From a7bb9030881276c574a42af0f04683c97eade325 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 11 May 2023 14:15:33 -0700 Subject: [PATCH] refactor: POLA for instancePrivateArgs --- .../src/proposals/econ-behaviors.js | 13 ++++++------ .../src/proposals/startEconCommittee.js | 4 ++-- packages/vats/src/core/basic-behaviors.js | 19 +++++++++++------- packages/vats/src/core/types.js | 3 ++- .../src/proposals/restart-vats-proposal.js | 4 ++-- .../test/snapshots/test-boot-config.js.md | 2 ++ .../test/snapshots/test-boot-config.js.snap | Bin 2102 -> 2131 bytes 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/inter-protocol/src/proposals/econ-behaviors.js b/packages/inter-protocol/src/proposals/econ-behaviors.js index 0bdbd6926b5..72f00690233 100644 --- a/packages/inter-protocol/src/proposals/econ-behaviors.js +++ b/packages/inter-protocol/src/proposals/econ-behaviors.js @@ -157,9 +157,8 @@ export const setupReserve = async ({ governorAdminFacet: g.adminFacet, }), ); - const { instancePrivateArgs } = await diagnostics; - instancePrivateArgs.set(instance, privateArgs.governed); - instancePrivateArgs.set(g.instance, privateArgs); + await E(diagnostics).savePrivateArgs(instance, privateArgs.governed); + await E(diagnostics).savePrivateArgs(g.instance, privateArgs); reserveInstanceProducer.resolve(instance); reserveGovernor.resolve(g.instance); @@ -319,9 +318,11 @@ export const startVaultFactory = async ( E(g.creatorFacet).getAdminFacet(), ]); - const { instancePrivateArgs } = await consume.diagnostics; // XXX omitting the governor - instancePrivateArgs.set(vaultFactoryInstance, vaultFactoryPrivateArgs); + await E(consume.diagnostics).savePrivateArgs( + vaultFactoryInstance, + vaultFactoryPrivateArgs, + ); vaultFactoryKit.resolve( harden({ @@ -335,7 +336,7 @@ export const startVaultFactory = async ( governorAdminFacet: g.adminFacet, governorCreatorFacet: g.creatorFacet, - // XXX try refactoring to use instancePrivateArgs + // XXX try refactoring to use savePrivateArgs privateArgs: vaultFactoryPrivateArgs, }), ); diff --git a/packages/inter-protocol/src/proposals/startEconCommittee.js b/packages/inter-protocol/src/proposals/startEconCommittee.js index ef658cebd09..c14d634d5f0 100644 --- a/packages/inter-protocol/src/proposals/startEconCommittee.js +++ b/packages/inter-protocol/src/proposals/startEconCommittee.js @@ -76,8 +76,8 @@ export const startEconomicCommittee = async ( // XXX should startInstance return its label? harden({ ...startResult, label: 'economicCommittee' }), ); - const { instancePrivateArgs } = await diagnostics; - instancePrivateArgs.set(startResult.instance, privateArgs); + + await E(diagnostics).savePrivateArgs(startResult.instance, privateArgs); economicCommitteeCreatorFacet.resolve(creatorFacet); economicCommittee.resolve(instance); diff --git a/packages/vats/src/core/basic-behaviors.js b/packages/vats/src/core/basic-behaviors.js index 33b8a250d83..f3d2f6173ae 100644 --- a/packages/vats/src/core/basic-behaviors.js +++ b/packages/vats/src/core/basic-behaviors.js @@ -119,7 +119,14 @@ harden(makeVatsFromBundles); /** @param {Pick} powers */ export const produceDiagnostics = async ({ produce }) => { const instancePrivateArgs = new Map(); - produce.diagnostics.resolve({ instancePrivateArgs }); + const savePrivateArgs = (instance, privateArgs) => { + if (instancePrivateArgs.has(instance)) { + Fail`privateArgs already set`; + } + instancePrivateArgs.set(instance, privateArgs); + }; + produce.diagnostics.resolve({ savePrivateArgs }); + produce.instancePrivateArgs.resolve(instancePrivateArgs); }; /** @param {BootstrapSpace & { zone: import('@agoric/zone').Zone }} powers */ @@ -149,8 +156,7 @@ export const produceStartUpgradable = async ({ label ||= NonNullish(getInterfaceOf(started.instance)); const kit = harden({ ...started, label }); contractKits.init(kit.instance, kit); - const instancePA = await E.get(diagnostics).instancePrivateArgs; - instancePA.set(kit.instance, privateArgs); + await E(diagnostics).savePrivateArgs(kit.instance, privateArgs); return kit; }; @@ -302,9 +308,8 @@ export const produceStartGovernedUpgradable = async ({ const kit = harden({ ...facets, label }); contractKits.init(facets.instance, kit); - const instancePA = await E.get(diagnostics).instancePrivateArgs; - instancePA.set(kit.instance, privateArgs); - instancePA.set(kit.governor, { + await E(diagnostics).savePrivateArgs(kit.instance, privateArgs); + await E(diagnostics).savePrivateArgs(kit.governor, { economicCommitteeCreatorFacet: await economicCommitteeCreatorFacet, }); @@ -805,7 +810,7 @@ export const BASIC_BOOTSTRAP_PERMITS = { brand: { produce: { BLD: 'BLD', IST: 'zoe' } }, }, [produceDiagnostics.name]: { - produce: { diagnostics: true }, + produce: { diagnostics: true, instancePrivateArgs: true }, }, [produceStartUpgradable.name]: { zone: true, diff --git a/packages/vats/src/core/types.js b/packages/vats/src/core/types.js index c7c2c7f0fe6..11ba4151f82 100644 --- a/packages/vats/src/core/types.js +++ b/packages/vats/src/core/types.js @@ -252,10 +252,11 @@ * client: ClientManager, * clientCreator: ClientCreator, * coreEvalBridgeHandler: import('../types.js').BridgeHandler, - * diagnostics: { instancePrivateArgs: Map }, + * diagnostics: { savePrivateArgs: (instance: Instance, privateArgs: unknown) => void }, * feeMintAccess: FeeMintAccess, * highPrioritySendersManager: import('@agoric/internal/src/priority-senders.js').PrioritySendersManager?, * initialSupply: Payment<'nat'>, + * instancePrivateArgs: Map, * namesByAddress: NameHub, * namesByAddressAdmin: import('../types').NamesByAddressAdmin, * pegasusConnections: import('@agoric/vats').NameHubKit, diff --git a/packages/vats/src/proposals/restart-vats-proposal.js b/packages/vats/src/proposals/restart-vats-proposal.js index 5ea51b36f94..09ed159ef32 100644 --- a/packages/vats/src/proposals/restart-vats-proposal.js +++ b/packages/vats/src/proposals/restart-vats-proposal.js @@ -40,7 +40,7 @@ export const restartVats = async ({ consume }, { options }) => { }), ); - const { instancePrivateArgs } = await consume.diagnostics; + const instancePrivateArgs = await consume.instancePrivateArgs; const failures = []; /** @@ -118,8 +118,8 @@ export const getManifestForRestart = (_powers, options) => ({ [restartVats.name]: { consume: { contractKits: true, - diagnostics: true, governedContractKits: true, + instancePrivateArgs: true, loadCriticalVat: true, zoe: 'zoe', provisioning: 'provisioning', diff --git a/packages/vats/test/snapshots/test-boot-config.js.md b/packages/vats/test/snapshots/test-boot-config.js.md index 3038b7d7b47..3578ff1b583 100644 --- a/packages/vats/test/snapshots/test-boot-config.js.md +++ b/packages/vats/test/snapshots/test-boot-config.js.md @@ -177,6 +177,7 @@ Generated by [AVA](https://avajs.dev). "installation_mintHolder" [label="mintHolder", shape=cylinder];␊ "produceDiagnostics" [label="produceDiagnostics"];␊ "space_diagnostics" [label="diagnostics", shape=house, style=filled, fillcolor=khaki];␊ + "space_instancePrivateArgs" [label="instancePrivateArgs", shape=house, style=filled, fillcolor=khaki];␊ "produceStartUpgradable" [label="produceStartUpgradable"];␊ "space_startUpgradable" [label="startUpgradable", shape=house, style=filled, fillcolor=khaki];␊ "space_contractKits" [label="contractKits", shape=house, style=filled, fillcolor=khaki];␊ @@ -278,6 +279,7 @@ Generated by [AVA](https://avajs.dev). "addBankAssets" -> "installation_centralSupply" [dir=back]␊ "addBankAssets" -> "installation_mintHolder" [dir=back]␊ "produceDiagnostics" -> "space_diagnostics" []␊ + "produceDiagnostics" -> "space_instancePrivateArgs" []␊ "produceStartUpgradable" -> "space_startUpgradable" []␊ "produceStartUpgradable" -> "space_contractKits" []␊ "produceStartUpgradable" -> "space_diagnostics" [dir=back]␊ diff --git a/packages/vats/test/snapshots/test-boot-config.js.snap b/packages/vats/test/snapshots/test-boot-config.js.snap index a73dc18fe9ad6d34b6404f1781c077bbcbfa3f48..06ee7ce87db4ab26a5e4c0cdc7bd1e9337c05c25 100644 GIT binary patch literal 2131 zcmV-Z2(0%(RzVNYo~qB8U8vBK-mVjU7ssG<@n|$=Rg4mo+&La)zTJ`3*l@E+Zan()a&R!9+yg ze7EFWq#_}^$&MylCMH)b%}B)F62W*pNn^50*IcmjNBaIl7!pB#fBf%PcfPqJ|GxP8 z&bMFw{WxSRP_v#qnEZ8;ka!caWO6!r^8Ck>G+P#=Aj(oflUHQL6BaxpTbcrMM3yuH z)+y?qo=kZ{f{4yQRru=V{N8l(XU=#!m5s%ZC)0FC0*ZB=gj5l>DxYqDW5z&mr|J5Wf^GO-5D;u_CgrA*7&solR4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