-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vats): choose bootstrap behaviors by name
Goal: allow genesis to specify exactly which functions get what powers during bootstrap. - filter bootstrap powers based on templates - layer simBootstrapManifest on bootstrapManifest - log bootstrap behavior invocations with endowments - separate sim bootstrap behaviors - fold bootstrap-zoe-config.js into bootstrap-behaviors.js - move manifests with behaviors - fix .js in module specifier
- Loading branch information
Showing
6 changed files
with
208 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// @ts-check | ||
import { E, Far } from '@agoric/far'; | ||
import { makeNotifierKit } from '@agoric/notifier'; | ||
import { bootstrapManifest } from './bootstrap-behaviors.js'; | ||
|
||
export const simBootstrapManifest = harden({ | ||
behaviors: { installSimEgress: true, ...bootstrapManifest.behaviors }, | ||
endowments: { | ||
installSimEgress: { | ||
vatParameters: { argv: { hardcodedClientAddresses: true } }, | ||
vats: { | ||
vattp: true, | ||
comms: true, | ||
}, | ||
workspace: true, | ||
}, | ||
...bootstrapManifest.endowments, | ||
}, | ||
}); | ||
|
||
/** | ||
* @param {{ | ||
* vatParameters: { argv: Record<string, unknown> }, | ||
* vats: { | ||
* vattp: VattpVat, | ||
* comms: CommsVatRoot, | ||
* }, | ||
* workspace: Record<string, ERef<unknown>>, | ||
* }} powers | ||
* | ||
* @typedef {{ getChainBundle: () => unknown }} ChainBundler | ||
*/ | ||
const installSimEgress = async ({ vatParameters, vats, workspace }) => { | ||
const PROVISIONER_INDEX = 1; | ||
|
||
const { argv } = vatParameters; | ||
const addRemote = async addr => { | ||
const { transmitter, setReceiver } = await E(vats.vattp).addRemote(addr); | ||
await E(vats.comms).addRemote(addr, transmitter, setReceiver); | ||
}; | ||
|
||
// TODO: chainProvider per address | ||
let bundle = harden({ | ||
echoer: Far('echoObj', { echo: message => message }), | ||
// TODO: echo: Far('echoFn', message => message), | ||
}); | ||
const { notifier, updater } = makeNotifierKit(bundle); | ||
|
||
const chainProvider = Far('chainProvider', { | ||
getChainBundle: () => notifier.getUpdateSince().then(({ value }) => value), | ||
getChainBundleNotifier: () => notifier, | ||
}); | ||
|
||
await Promise.all( | ||
/** @type { string[] } */ (argv.hardcodedClientAddresses).map( | ||
async addr => { | ||
await addRemote(addr); | ||
await E(vats.comms).addEgress(addr, PROVISIONER_INDEX, chainProvider); | ||
}, | ||
), | ||
); | ||
|
||
workspace.allClients = harden({ | ||
assign: newProperties => { | ||
bundle = { ...bundle, ...newProperties }; | ||
updater.updateState(bundle); | ||
}, | ||
}); | ||
}; | ||
|
||
harden({ installSimEgress }); | ||
export { installSimEgress }; | ||
export * from './bootstrap-behaviors.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// @ts-check | ||
import { E } from '@agoric/far'; | ||
import { AssetKind } from '@agoric/ertp'; | ||
|
||
// TODO: phase out ./issuers.js | ||
export const CENTRAL_ISSUER_NAME = 'RUN'; | ||
|
||
/** @type { FeeIssuerConfig } */ | ||
export const feeIssuerConfig = { | ||
name: CENTRAL_ISSUER_NAME, | ||
assetKind: AssetKind.NAT, | ||
displayInfo: { decimalPlaces: 6, assetKind: AssetKind.NAT }, | ||
}; | ||
|
||
export const bootstrapManifest = harden({ | ||
behaviors: { | ||
connectVattpWithMailbox: true, | ||
buildZoe: true, | ||
}, | ||
endowments: { | ||
connectVattpWithMailbox: { | ||
vatPowers: { D: true }, | ||
vats: { vattp: true }, | ||
devices: { mailbox: true }, | ||
}, | ||
buildZoe: { | ||
vats: { vatAdmin: true }, | ||
devices: { vatAdmin: true }, | ||
workspace: true, | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* @param {{ | ||
* vatPowers: { D: EProxy }, // D type is approximate | ||
* vats: { vattp: VattpVat }, | ||
* devices: { mailbox: MailboxDevice }, | ||
* }} powers | ||
*/ | ||
const connectVattpWithMailbox = ({ | ||
vatPowers: { D }, | ||
vats: { vattp }, | ||
devices: { mailbox }, | ||
}) => { | ||
D(mailbox).registerInboundHandler(vattp); | ||
return E(vattp).registerMailboxDevice(mailbox); | ||
}; | ||
|
||
/** | ||
* @param {{ | ||
* vats: { vatAdmin: VatAdminVat }, | ||
* devices: { vatAdmin: unknown }, | ||
* workspace: Record<string, ERef<any>>, | ||
* }} powers | ||
* | ||
* @typedef {ERef<ReturnType<import('./vat-zoe').buildRootObject>>} ZoeVat | ||
*/ | ||
const buildZoe = async ({ vats, devices, workspace }) => { | ||
// TODO: what else do we need vatAdminSvc for? can we let it go out of scope? | ||
const vatAdminSvc = E(vats.vatAdmin).createVatAdminService(devices.vatAdmin); | ||
|
||
/** @type {{ root: ZoeVat }} */ | ||
const { root } = await E(vatAdminSvc).createVatByName('zoe'); | ||
const { zoeService: zoe, feeMintAccess: _2 } = await E(root).buildZoe( | ||
vatAdminSvc, | ||
feeIssuerConfig, | ||
); | ||
|
||
workspace.zoe = zoe; | ||
E(workspace.allClients).assign({ zoe }); | ||
}; | ||
|
||
harden({ connectVattpWithMailbox, buildZoe }); | ||
export { connectVattpWithMailbox, buildZoe }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import '@agoric/install-ses'; | ||
import test from 'ava'; | ||
|
||
import { extract } from '../src/bootstrap-core.js'; | ||
|
||
test('extract picks from specimen based on template', t => { | ||
const specimen = { a: 1, b: { c: 2 } }; | ||
const template = { b: { c: true } }; | ||
const actual = extract(template, specimen); | ||
t.deepEqual(actual, { b: { c: 2 } }); | ||
}); |