Skip to content

Commit

Permalink
feat: support coreProposal.needs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Sep 21, 2023
1 parent 7b0d456 commit 82c55d7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 41 deletions.
47 changes: 26 additions & 21 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions packages/swingset-runner/src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/boot-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/boot-sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/boot-solo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const modules = harden({
* }} vatPowers
* @param {{
* bootstrapManifest?: Record<string, Record<string, unknown>>;
* coreProposalCode?: string;
* coreProposalCodeSteps?: string;
* }} vatParameters
*/
export const buildRootObject = (vatPowers, vatParameters) => {
Expand Down
35 changes: 20 additions & 15 deletions packages/vats/src/core/lib-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -138,29 +139,33 @@ 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<import('../types.js').BridgeHandler>;
* }}
*/
// @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
Expand Down

0 comments on commit 82c55d7

Please sign in to comment.