From 82c55d7dd40cbb27152840bbb4f53056a732422e Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 20 Sep 2023 15:05:58 -0600 Subject: [PATCH] feat: support `coreProposal.needs` --- packages/cosmic-swingset/src/launch-chain.js | 47 +++++++++++--------- packages/swingset-runner/src/chain.js | 7 ++- packages/vats/src/core/boot-chain.js | 2 +- packages/vats/src/core/boot-sim.js | 2 +- packages/vats/src/core/boot-solo.js | 2 +- packages/vats/src/core/lib-boot.js | 35 ++++++++------- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/packages/cosmic-swingset/src/launch-chain.js b/packages/cosmic-swingset/src/launch-chain.js index 2e17d073166d..31600761c4e2 100644 --- a/packages/cosmic-swingset/src/launch-chain.js +++ b/packages/cosmic-swingset/src/launch-chain.js @@ -147,14 +147,17 @@ export async function buildSwingset( // Find the entrypoints for all the core proposals. if (coreProposals) { - const { bundles, code } = await extractCoreProposalBundles( + const { bundles, codeSteps } = await extractCoreProposalBundles( coreProposals, configLocation, // for path resolution ); swingsetConfig.bundles = { ...swingsetConfig.bundles, ...bundles }; // Tell the bootstrap code how to run the core proposals. - bootVat.parameters = { ...bootVat.parameters, coreProposalCode: code }; + bootVat.parameters = { + ...bootVat.parameters, + coreProposalCodeSteps: codeSteps, + }; } if (bridgeOutbound) { @@ -802,7 +805,7 @@ export async function launch({ // Find scripts relative to our location. const myFilename = fileURLToPath(import.meta.url); - const { bundles, code: coreEvalCode } = + const { bundles, codeSteps: coreEvalCodeSteps } = await extractCoreProposalBundles(coreProposals, myFilename, { handleToBundleSpec: async (handle, source, _sequence, _piece) => { const bundle = await bundleSource(source); @@ -821,25 +824,27 @@ export async function launch({ } // Now queue the code for evaluation. - const coreEvalAction = { - type: ActionType.CORE_EVAL, - blockHeight, - blockTime, - evals: [ - { - json_permits: 'true', - js_code: coreEvalCode, - }, - ], - }; - runThisBlock.push({ - context: { + for (const coreEvalCode of coreEvalCodeSteps) { + const coreEvalAction = { + type: ActionType.CORE_EVAL, blockHeight, - txHash: 'x/upgrade', - msgIdx: 0, - }, - action: coreEvalAction, - }); + blockTime, + evals: [ + { + json_permits: 'true', + js_code: coreEvalCode, + }, + ], + }; + runThisBlock.push({ + context: { + blockHeight, + txHash: 'x/upgrade', + msgIdx: 0, + }, + action: coreEvalAction, + }); + } controller.writeSlogObject({ type: 'cosmic-swingset-upgrade-finish', diff --git a/packages/swingset-runner/src/chain.js b/packages/swingset-runner/src/chain.js index d957f5bee639..7564c768fb00 100644 --- a/packages/swingset-runner/src/chain.js +++ b/packages/swingset-runner/src/chain.js @@ -167,12 +167,15 @@ export async function initEmulatedChain(config, configPath) { const bootVat = config.vats[config.bootstrap]; await null; if (coreProposals) { - const { bundles, code } = await extractCoreProposalBundles( + const { bundles, codeSteps } = await extractCoreProposalBundles( coreProposals, configPath, ); config.bundles = { ...config.bundles, ...bundles }; - bootVat.parameters = { ...bootVat.parameters, coreProposalCode: code }; + bootVat.parameters = { + ...bootVat.parameters, + coreProposalCodeSteps: codeSteps, + }; } const batchChainStorage = (method, args) => diff --git a/packages/vats/src/core/boot-chain.js b/packages/vats/src/core/boot-chain.js index 15f4198e33bd..a0d4c96b0a6b 100644 --- a/packages/vats/src/core/boot-chain.js +++ b/packages/vats/src/core/boot-chain.js @@ -29,7 +29,7 @@ export const MANIFEST = CHAIN_BOOTSTRAP_MANIFEST; * logger: (msg) => void; * }} vatPowers * @param {{ - * coreProposalCode?: string; + * coreProposalCodeSteps?: string[]; * }} vatParameters * @param {import('@agoric/vat-data').Baggage} baggage */ diff --git a/packages/vats/src/core/boot-sim.js b/packages/vats/src/core/boot-sim.js index 0e0471d981fe..2572296e6558 100644 --- a/packages/vats/src/core/boot-sim.js +++ b/packages/vats/src/core/boot-sim.js @@ -31,7 +31,7 @@ const modules = harden({ behaviors: { ...behaviors }, utils: { ...utils } }); * logger: (msg) => void; * }} vatPowers * @param {{ - * coreProposalCode?: string; + * coreProposalCodeSteps?: string[]; * }} vatParameters */ export const buildRootObject = (vatPowers, vatParameters) => { diff --git a/packages/vats/src/core/boot-solo.js b/packages/vats/src/core/boot-solo.js index c9118cd8ae7d..9341a318495a 100644 --- a/packages/vats/src/core/boot-solo.js +++ b/packages/vats/src/core/boot-solo.js @@ -36,7 +36,7 @@ const modules = harden({ * }} vatPowers * @param {{ * bootstrapManifest?: Record>; - * coreProposalCode?: string; + * coreProposalCodeSteps?: string; * }} vatParameters */ export const buildRootObject = (vatPowers, vatParameters) => { diff --git a/packages/vats/src/core/lib-boot.js b/packages/vats/src/core/lib-boot.js index 278e393b6836..805c0f46881a 100644 --- a/packages/vats/src/core/lib-boot.js +++ b/packages/vats/src/core/lib-boot.js @@ -100,8 +100,9 @@ export const makeBootstrap = ( ); const namesVat = namedVat.consume.agoricNames; - const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = - await E(namesVat).getNameHubKit(); + const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = await E( + namesVat, + ).getNameHubKit(); const spaces = await makeWellKnownSpaces(agoricNamesAdmin, log); produce.agoricNames.resolve(agoricNames); produce.agoricNamesAdmin.resolve(agoricNamesAdmin); @@ -138,21 +139,12 @@ export const makeBootstrap = ( await runBehaviors(bootManifest); - const { coreProposalCode } = vatParameters; - if (!coreProposalCode) { + /** @type {{ coreProposalCodeSteps?: string[] }} */ + const { coreProposalCodeSteps } = vatParameters; + if (!coreProposalCodeSteps) { return; } - // Start the governance from the core proposals. - const coreEvalMessage = { - type: 'CORE_EVAL', - evals: [ - { - json_permits: 'true', - js_code: coreProposalCode, - }, - ], - }; /** * @type {{ * coreEvalBridgeHandler: Promise; @@ -160,7 +152,20 @@ export const makeBootstrap = ( */ // @ts-expect-error cast const { coreEvalBridgeHandler } = consume; - await E(coreEvalBridgeHandler).fromBridge(coreEvalMessage); + + // Start the governance from the core proposals. + for await (const coreProposalCode of coreProposalCodeSteps) { + const coreEvalMessage = { + type: 'CORE_EVAL', + evals: [ + { + json_permits: 'true', + js_code: coreProposalCode, + }, + ], + }; + await E(coreEvalBridgeHandler).fromBridge(coreEvalMessage); + } }; // For testing supports