Skip to content

Commit

Permalink
feat: support coreProposals.steps
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Dec 6, 2023
1 parent c7a8556 commit 2accfde
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 98 deletions.
98 changes: 47 additions & 51 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,6 @@ export async function buildSwingset(
const bootVat =
swingsetConfig.vats[swingsetConfig.bootstrap || 'bootstrap'];

// Find the entrypoints for all the core proposals.
if (coreProposals) {
const { bundles, code } = 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 };
}

if (bridgeOutbound) {
const batchChainStorage = (method, args) =>
bridgeOutbound(BRIDGE_ID.STORAGE, { method, args });
Expand All @@ -175,9 +163,10 @@ export async function buildSwingset(
// @ts-expect-error debugPrefix? what's that?
debugPrefix,
});
return coreProposals;
}

await ensureSwingsetInitialized();
const coreProposals = await ensureSwingsetInitialized();
const controller = await makeSwingsetController(
kernelStorage,
deviceEndowments,
Expand All @@ -193,6 +182,7 @@ export async function buildSwingset(
// (either on bootstrap block (0) or in endBlock).

return {
coreProposals,
controller,
mb: mailboxDevice,
bridgeInbound: bridgeDevice && bridgeDevice.deliverInbound,
Expand Down Expand Up @@ -333,19 +323,20 @@ export async function launch({
});

console.debug(`buildSwingset`);
const { controller, mb, bridgeInbound, timer } = await buildSwingset(
mailboxStorage,
bridgeOutbound,
kernelStorage,
vatconfig,
argv,
env,
{
debugName,
slogCallbacks,
slogSender,
},
);
const { coreProposals, controller, mb, bridgeInbound, timer } =
await buildSwingset(
mailboxStorage,
bridgeOutbound,
kernelStorage,
vatconfig,
argv,
env,
{
debugName,
slogCallbacks,
slogSender,
},
);

/** @type {{publish: (value: unknown) => Promise<void>} | undefined} */
let installationPublisher;
Expand Down Expand Up @@ -574,8 +565,7 @@ export async function launch({
*/
async function processActions(inboundQueue, runSwingset) {
let keepGoing = true;
await null;
for (const { action, context } of inboundQueue.consumeAll()) {
for await (const { action, context } of inboundQueue.consumeAll()) {
const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`;
inboundQueueMetrics.decStat();
await performAction(action, inboundNum);
Expand Down Expand Up @@ -745,7 +735,8 @@ export async function launch({
// );
switch (action.type) {
case ActionType.AG_COSMOS_INIT: {
const { isBootstrap, upgradePlan, blockTime, params } = action;
const { isBootstrap, blockTime, params } = action;
let upgradePlan = action.upgradePlan;
// This only runs for the very first block on the chain.
if (isBootstrap) {
verboseBlocks && blockManagerConsole.info('block bootstrap');
Expand All @@ -763,6 +754,9 @@ export async function launch({
await processAction(action.type, async () =>
bootstrapBlock(blockHeight, blockTime, bootstrapBlockParams),
);
if (!upgradePlan && coreProposals) {
upgradePlan = harden({ info: JSON.stringify({ coreProposals }) });
}
controller.writeSlogObject({
type: 'cosmic-swingset-bootstrap-block-finish',
blockTime,
Expand Down Expand Up @@ -809,17 +803,17 @@ export async function launch({
parseLocatedJson(upgradeInfoJson, 'ENACTED_UPGRADE upgradePlan.info');

// Handle the planned core proposals as just another action.
const { coreProposals = [] } = upgradePlanInfo || {};
const { coreProposals: upgradeCoreProposals } = upgradePlanInfo || {};

if (!coreProposals.length) {
if (!upgradeCoreProposals) {
// Nothing to do.
return undefined;
}

// Find scripts relative to our location.
const myFilename = fileURLToPath(import.meta.url);
const { bundles, code: coreEvalCode } =
await extractCoreProposalBundles(coreProposals, myFilename, {
const { bundles, codeSteps: coreEvalCodeSteps } =
await extractCoreProposalBundles(upgradeCoreProposals, myFilename, {
handleToBundleSpec: async (handle, source, _sequence, _piece) => {
const bundle = await bundleSource(source);
const { endoZipBase64Sha512: hash } = bundle;
Expand All @@ -837,25 +831,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 [key, coreEvalCode] of Object.entries(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: Number(key),
},
action: coreEvalAction,
});
}

controller.writeSlogObject({
type: 'cosmic-swingset-upgrade-finish',
Expand Down
15 changes: 1 addition & 14 deletions packages/swingset-runner/src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,9 @@ export async function initEmulatedChain(config, configPath) {
}
}

const {
coreProposals,
clearStorageSubtrees,
exportStorageSubtrees = [],
} = config;
const { clearStorageSubtrees, exportStorageSubtrees = [] } = config;

const bootVat = config.vats[config.bootstrap];
await null;
if (coreProposals) {
const { bundles, code } = await extractCoreProposalBundles(
coreProposals,
configPath,
);
config.bundles = { ...config.bundles, ...bundles };
bootVat.parameters = { ...bootVat.parameters, coreProposalCode: code };
}

const batchChainStorage = (method, args) =>
bridgeOutbound(BridgeId.STORAGE, { method, args });
Expand Down
4 changes: 1 addition & 3 deletions packages/vats/src/core/boot-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export const MANIFEST = CHAIN_BOOTSTRAP_MANIFEST;
* D: DProxy;
* logger: (msg) => void;
* }} vatPowers
* @param {{
* coreProposalCode?: string;
* }} vatParameters
* @param {object} vatParameters
* @param {import('@agoric/vat-data').Baggage} baggage
*/
export const buildRootObject = (vatPowers, vatParameters, baggage) => {
Expand Down
4 changes: 1 addition & 3 deletions packages/vats/src/core/boot-sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const modules = harden({ behaviors: { ...behaviors }, utils: { ...utils } });
* D: DProxy;
* logger: (msg) => void;
* }} vatPowers
* @param {{
* coreProposalCode?: string;
* }} vatParameters
* @param {object} vatParameters
*/
export const buildRootObject = (vatPowers, vatParameters) => {
console.debug(`sim bootstrap starting`);
Expand Down
1 change: 0 additions & 1 deletion packages/vats/src/core/boot-solo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const modules = harden({
* }} vatPowers
* @param {{
* bootstrapManifest?: Record<string, Record<string, unknown>>;
* coreProposalCode?: string;
* }} vatParameters
*/
export const buildRootObject = (vatPowers, vatParameters) => {
Expand Down
28 changes: 2 additions & 26 deletions packages/vats/src/core/lib-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export const makeBootstrap = (
);

const namesVat = namedVat.consume.agoricNames;
const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } =
await E(namesVat).getNameHubKit();
const nameHubKit = await E(namesVat).getNameHubKit();
const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = nameHubKit;
const spaces = await makeWellKnownSpaces(agoricNamesAdmin, log);
produce.agoricNames.resolve(agoricNames);
produce.agoricNamesAdmin.resolve(agoricNamesAdmin);
Expand Down Expand Up @@ -135,30 +135,6 @@ export const makeBootstrap = (
});

await runBehaviors(bootManifest);

const { coreProposalCode } = vatParameters;
if (!coreProposalCode) {
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);
};

// For testing supports
Expand Down

0 comments on commit 2accfde

Please sign in to comment.