Skip to content

Commit

Permalink
misc cleanup (#9661)
Browse files Browse the repository at this point in the history
_incidental_

## Description
Some cleanups noticed in the course of [#9659](#9659)

### Security Considerations
none
### Scaling Considerations
none

### Documentation Considerations
none
### Testing Considerations
"Dependency Graph" test has been failing on the recent change to `replay-membrane.js`. Maybe that should be a Required test in the repo.

### Upgrade Considerations
This changes Zoe but in a fully backwards and forward compatible way. I think it can get into master and reach chain whenever Zoe is next upgraded.
  • Loading branch information
mergify[bot] authored Jul 8, 2024
2 parents 62ea793 + 3c531f5 commit 6581fd3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
12 changes: 9 additions & 3 deletions packages/SwingSet/tools/bundleTool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeNodeBundleCache as wrappedMaker } from '@endo/bundle-source/cache.js';
import styles from 'ansi-styles'; // less authority than 'chalk'

/** @type {typeof wrappedMaker} */
export const makeNodeBundleCache = async (dest, options, loadModule, pid) => {
const log = (...args) => {
const flattened = args.map(arg =>
Expand All @@ -16,9 +17,9 @@ export const makeNodeBundleCache = async (dest, options, loadModule, pid) => {
};
return wrappedMaker(dest, { log, ...options }, loadModule, pid);
};
/** @typedef {ReturnType<typeof makeNodeBundleCache>} BundleCache */
/** @typedef {Awaited<ReturnType<typeof makeNodeBundleCache>>} BundleCache */

/** @type {Map<string, BundleCache>} */
/** @type {Map<string, Promise<BundleCache>>} */
const providedCaches = new Map();

/**
Expand All @@ -29,10 +30,11 @@ const providedCaches = new Map();
* @param {{ format?: string, dev?: boolean }} options
* @param {(id: string) => Promise<any>} loadModule
* @param {number} [pid]
* @returns {BundleCache}
* @returns {Promise<BundleCache>}
*/
export const provideBundleCache = (dest, options, loadModule, pid) => {
const uniqueDest = [dest, options.format, options.dev].join('-');
// store the promise instead of awaiting to prevent a race
let bundleCache = providedCaches.get(uniqueDest);
if (!bundleCache) {
bundleCache = makeNodeBundleCache(dest, options, loadModule, pid);
Expand All @@ -42,5 +44,9 @@ export const provideBundleCache = (dest, options, loadModule, pid) => {
};
harden(provideBundleCache);

/**
* @param {string} dest
* @returns {Promise<BundleCache>}
*/
export const unsafeMakeBundleCache = dest =>
makeNodeBundleCache(dest, {}, s => import(s));
18 changes: 16 additions & 2 deletions packages/async-flow/src/replay-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@ export const makeReplayMembrane = ({
try {
optVerb
? heapVowE.sendOnly(hostTarget)[optVerb](...hostArgs)
: // @ts-expect-error XXX heapVowE
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore once we changed this from E to heapVowE,
// typescript started complaining that heapVowE(hostTarget)
// is not callable. I'm not sure if this is a just a typing bug
// in heapVowE or also reflects a runtime deficiency. But this
// case it not used yet anyway. We disable it
// with at-ts-ignore rather than at-ts-expect-error because
// the dependency-graph tests complains that the latter is unused.
heapVowE.sendOnly(hostTarget)(...hostArgs);
} catch (hostProblem) {
throw Panic`internal: eventual sendOnly synchrously failed ${hostProblem}`;
Expand Down Expand Up @@ -313,7 +320,14 @@ export const makeReplayMembrane = ({
try {
const hostPromise = optVerb
? heapVowE(hostTarget)[optVerb](...hostArgs)
: // @ts-expect-error XXX heapVowE
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore once we changed this from E to heapVowE,
// typescript started complaining that heapVowE(hostTarget)
// is not callable. I'm not sure if this is a just a typing bug
// in heapVowE or also reflects a runtime deficiency. But this
// case it not used yet anyway. We disable it
// with at-ts-ignore rather than at-ts-expect-error because
// the dependency-graph tests complains that the latter is unused.
heapVowE(hostTarget)(...hostArgs);
resolver.resolve(hostPromise); // TODO does this always work?
} catch (hostProblem) {
Expand Down
4 changes: 1 addition & 3 deletions packages/zoe/src/instanceRecordStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { q, Fail } from '@endo/errors';
import { provide, prepareExoClass, M } from '@agoric/vat-data';
import { prepareExoClass, M } from '@agoric/vat-data';
import { assertKeywordName } from './cleanProposal.js';
import {
BrandKeywordRecordShape,
Expand Down Expand Up @@ -28,8 +28,6 @@ const { ownKeys } = Reflect;
* @returns {(ir: InstanceRecord) => InstanceState}
*/
export const makeInstanceRecordStorage = baggage => {
provide(baggage, 'instanceRecord', () => undefined);

const assertInstantiated = instanceRecord => {
instanceRecord !== 'undefined' ||
Fail`instanceRecord has not been instantiated`;
Expand Down
1 change: 0 additions & 1 deletion packages/zoe/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ export const ZoeStorageManagerIKit = harden({
}),
startInstanceAccess: M.interface('ZoeStorage startInstance access', {
makeZoeInstanceStorageManager: M.call(
M.any(),
InstallationShape,
M.any(),
IssuerPKeywordRecordShape,
Expand Down
1 change: 0 additions & 1 deletion packages/zoe/src/zoeService/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
* instance-specific terms
*
* @callback MakeZoeInstanceStorageManager
* @param {import('@agoric/vat-data').Baggage} instanceBaggage
* @param {Installation} installation
* @param {object} customTerms
* @param {IssuerKeywordRecord} uncleanIssuerKeywordRecord
Expand Down
6 changes: 0 additions & 6 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/marshal';
import {
M,
makeScalarBigMapStore,
provideDurableWeakMapStore,
prepareExoClass,
prepareExo,
Expand Down Expand Up @@ -301,14 +300,9 @@ export const makeStartInstance = (

const instanceHandle = makeInstanceHandle();

const instanceBaggage = makeScalarBigMapStore('instanceBaggage', {
durable: true,
});

const zoeInstanceStorageManager = await E(
startInstanceAccess,
).makeZoeInstanceStorageManager(
instanceBaggage,
installation,
customTerms,
uncleanIssuerKeywordRecord,
Expand Down
1 change: 0 additions & 1 deletion packages/zoe/src/zoeService/zoeStorageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ export const makeZoeStorageManager = (

/** @type {MakeZoeInstanceStorageManager} */
const makeZoeInstanceStorageManager = async (
instanceBaggage,
installation,
customTerms,
uncleanIssuerKeywordRecord,
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/tools/setup-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const makeZoeForTest = vatAdminSvc =>

/**
* Returns promises for `zoe` and the `feeMintAccess`.
* Provide testing versions of capabilities for Zoe contracts.
*
* @template {object} [T=unknown]
* @param {object} options
Expand Down

0 comments on commit 6581fd3

Please sign in to comment.