Skip to content

Commit

Permalink
fix(bootstrap): get scenario#1 to work
Browse files Browse the repository at this point in the history
Need to make singleton objects for the chain rather than creating them
fresh for every user bundle.

Fix some hopeful but incorrect function arguments for scenario#1.
  • Loading branch information
michaelfig committed Nov 7, 2019
1 parent e40160d commit 033c654
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function parseArgs(argv) {
return [ROLES, bootAddress, additionalAddresses];
}

const SCENARIO_1_INDEX = 1;
const SCENARIO_2_INDEX = 1;

export default function setup(syscall, state, helpers) {
Expand Down Expand Up @@ -92,20 +93,21 @@ export default function setup(syscall, state, helpers) {
}

// Make services that are provided on the real or virtual chain side
function makeChainBundler(vats, timerDevice) {
async function makeChainBundler(vats, timerDevice) {
// Create singleton instances.
const sharingService = await E(vats.sharing).getSharingService();
const registrar = await E(vats.registrar).getSharedRegistrar();
const chainTimerService = await addTimerService(
timerDevice,
vats.timer,
);
const contractHost = await E(vats.host).makeHost();
await E(vats.pixel).startup(contractHost);
const zoe = await E(vats.zoe).getZoe();

return harden({
async createUserBundle(nickname, jackpot) {
const sharingService = await E(vats.sharing).getSharingService();
const registrar = await E(vats.registrar).getSharedRegistrar();
const chainTimerService = await addTimerService(
timerDevice,
vats.timer,
);
const contractHost = await E(vats.host).makeHost();
await E(vats.pixel).startup(contractHost);
async createUserBundle(nickname) {
const pixelBundle = await E(vats.pixel).createPixelBundle(nickname);
const zoe = await E(vats.zoe).getZoe();

const bundle = harden({
...pixelBundle,
chainTimerService,
Expand Down Expand Up @@ -153,16 +155,12 @@ export default function setup(syscall, state, helpers) {
// client (python) on localhost, which creates client solo node on
// localhost, with HTML frontend. Multi-player mode.
if (ROLES.chain || ROLES.one_chain) {
// todo(hibbert) make this consistent with the bundle distinction
console.log(`scenario#1: chain bootstrap starting`);
const host = await E(vats.host).makeHost();
await E(vats.pixel).startup(host);
await E(vats.timer).registerTimerDevice(devices.timer);

// provisioning vat can ask the demo server for bundles, and can
// register client pubkeys with comms
await E(vats.provisioning).register(
makeChainBundler(host, vats),
await makeChainBundler(vats, devices.timer),
vats.comms,
vats.vattp,
);
Expand All @@ -175,7 +173,7 @@ export default function setup(syscall, state, helpers) {
},
});
// bootAddress holds the pubkey of controller
await E(vats.comms).addEgress(bootAddress, 1, provisioner);
await E(vats.comms).addEgress(bootAddress, SCENARIO_1_INDEX, provisioner);
console.log(`localchain vats initialized`);
} else if (ROLES.controller || ROLES.one_controller) {
// todo(hibbert) make this consistent with the bundle distinction
Expand All @@ -191,7 +189,7 @@ export default function setup(syscall, state, helpers) {

// Create a presence for the on-chain provisioner.
await addRemote(GCI);
const chainProvisioner = await E(vats.comms).addIngress(GCI, 1);
const chainProvisioner = await E(vats.comms).addIngress(GCI, SCENARIO_1_INDEX);
// Allow web requests from the provisioning server to call our
// provisioner object.
const provisioner = harden({
Expand All @@ -217,14 +215,13 @@ export default function setup(syscall, state, helpers) {
// todo: this should be the ingressIndex from the provisioner
const INDEX = 1;
const demoProvider = await E(vats.comms).addIngress(GCI, INDEX);
const bundle = await E(demoProvider).getDemoBundle();
const { purses, bundle } = await E(demoProvider).getDemoBundle();
await E(vats.http).setPresences(
{ ...bundle, localTimerService },
await createLocalBundle(
vats,
bundle.contractHost,
bundle.zoe,
bundle.registrar,
bundle,
purses,
),
);
console.log(` vats initialized`);
Expand All @@ -235,7 +232,7 @@ export default function setup(syscall, state, helpers) {

console.log(`scenario#2: local chain bootstrap starting`);
// bootAddress holds the pubkey of localclient
const chainBundler = makeChainBundler(vats, devices.timer);
const chainBundler = await makeChainBundler(vats, devices.timer);
const demoProvider = harden({
// build a chain-side bundle for a client.
async getDemoBundle(nickname) {
Expand Down Expand Up @@ -277,11 +274,10 @@ export default function setup(syscall, state, helpers) {
`scenario#3: local demo-server+client bootstrap starting`);
await setupCommandDevice(vats.http, devices.command, {
client: true});
const { purses, bundle } = await makeChainBundler(
const { purses, bundle } = await E(makeChainBundler(
vats,
devices.timer,
)
.createUserBundle('localuser');
)).createUserBundle('localuser');

// Setup of the Local part /////////////////////////////////////
const localBundle = await createLocalBundle(vats, bundle, purses);
Expand Down

0 comments on commit 033c654

Please sign in to comment.