Skip to content

Commit

Permalink
refactor(vats): separate out sim-behaviors from production ones
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jan 26, 2022
1 parent de72509 commit efc5d9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/vats/src/core/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
export * from './basic-behaviors.js';
export * from './chain-behaviors.js';
export * from './econ-behaviors.js';
export * from './sim-behaviors.js';
// We exclude sim-behaviors.js from this list because it should not be used in production.
24 changes: 15 additions & 9 deletions packages/vats/src/core/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import {
} from './manifest.js';

import * as behaviors from './behaviors.js';
import * as simBehaviors from './sim-behaviors.js';

const { entries, fromEntries, keys } = Object;
const { details: X, quote: q } = assert;

// TODO: include behaviors in this table; separate sim-behaviors a bit more.
// Choose a manifest based on runtime configured argv.ROLE.
const roleToManifest = new Map([
['chain', CHAIN_BOOTSTRAP_MANIFEST],
['sim-chain', SIM_CHAIN_BOOTSTRAP_MANIFEST],
]);
const roleToManifest = harden({
chain: CHAIN_BOOTSTRAP_MANIFEST,
'sim-chain': SIM_CHAIN_BOOTSTRAP_MANIFEST,
});
const roleToBehaviors = harden({
chain: behaviors,
'sim-chain': { ...behaviors, ...simBehaviors },
});

/**
* Make { produce, consume } where for each name, `consume[name]` is a promise
Expand Down Expand Up @@ -135,8 +139,10 @@ const buildRootObject = (vatPowers, vatParameters) => {
} = vatParameters;
console.debug(`${ROLE} bootstrap starting`);

const actualManifest = bootstrapManifest || roleToManifest.get(ROLE);
assert(actualManifest, X`no configured manifest maker for role ${ROLE}`);
const bootManifest = bootstrapManifest || roleToManifest[ROLE];
const bootBehaviors = roleToBehaviors[ROLE];
assert(bootManifest, X`no configured bootstrapManifest for role ${ROLE}`);
assert(bootBehaviors, X`no configured bootstrapBehaviors for role ${ROLE}`);

return Far('bootstrap', {
/**
Expand Down Expand Up @@ -167,13 +173,13 @@ const buildRootObject = (vatPowers, vatParameters) => {
Promise.resolve().then(() => {
const endowments = extract(permit, powers);
console.info(`bootstrap: ${name}(${q(permit)})`);
return behaviors[name](endowments);
return bootBehaviors[name](endowments);
}),
),
);
};

await runBehaviors(actualManifest);
await runBehaviors(bootManifest);
if (vatParameters.governanceActions) {
await runBehaviors(GOVERNANCE_ACTIONS_MANIFEST);
}
Expand Down

0 comments on commit efc5d9a

Please sign in to comment.