Skip to content

Commit

Permalink
feat(solo): make client objects appear earlier, parallelise chain
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Sep 21, 2021
1 parent 20abcbe commit 656514e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/agoric-cli/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const main = async (progname, rawArgs, powers) => {
.option(
'--need <subsystems>',
'comma-separated names of subsystems to wait for',
'agoric,wallet',
'local,agoric,wallet',
)
.option(
'--provide <subsystems>',
Expand Down
29 changes: 18 additions & 11 deletions packages/cosmic-swingset/src/sim-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,33 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
console.log(`delivering to ${GCI} (trips=${totalDeliveries})`);

intoChain.push([newMessages, acknum]);
if (!delay) {
// Only actually simulate a block if we're not in bootstrap.
if (blockHeight && !delay) {
clearTimeout(nextBlockTimeout);
await simulateBlock();
}
}

let genesisBlockP;
if (!blockHeight) {
const bootSimChain = async () => {
if (blockHeight) {
return;
}
// The before-first-block is special... do it now.
// This emulates what x/swingset does to run a BOOTSTRAP_BLOCK
// before continuing with the real initialHeight.
genesisBlockP = blockManager(
{ type: 'BOOTSTRAP_BLOCK', blockTime },
savedChainSends,
).then(() => (blockHeight = initialHeight));
}
await genesisBlockP;
await blockManager({ type: 'BOOTSTRAP_BLOCK', blockTime }, savedChainSends);
blockHeight = initialHeight;
};

const enableDeliveries = () => {
// Start the first pretend block.
nextBlockTimeout = setTimeout(simulateBlock, maximumDelay);
};

// Start the first pretend block.
nextBlockTimeout = setTimeout(simulateBlock, maximumDelay);
bootSimChain().then(enableDeliveries, e => {
console.error(`Cannot boot sim chain:`, e);
process.exit(1);
});

const batchDelayMs = delay ? delay * 1000 : undefined;
return makeBatchedDeliver(deliver, batchDelayMs);
Expand Down
8 changes: 4 additions & 4 deletions packages/solo/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ export default async function start(basedir, argv) {
resetOutdatedState,
} = d;

// Start timer here!
startTimer(800);
resetOutdatedState();

// Remove wallet traces.
await unlink('html/wallet').catch(_ => {});

Expand Down Expand Up @@ -391,10 +395,6 @@ export default async function start(basedir, argv) {
}),
);

// Start timer here!
startTimer(1200);
resetOutdatedState();

log.info(`swingset running`);
swingSetRunning = true;
deliverOutbound();
Expand Down
22 changes: 10 additions & 12 deletions packages/solo/src/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ export function buildRootObject(vatPowers) {
},

setPresences(
privateObjects,
privateObjects = undefined,
decentralObjects = undefined,
handyObjects = undefined,
deprecatedObjects = undefined,
) {
exportedToCapTP = {
...exportedToCapTP,
...decentralObjects, // TODO: Remove; replaced by .agoric
...privateObjects, // TODO: Remove; replaced by .local
...handyObjects,
...deprecatedObjects,
agoric: { ...decentralObjects },
local: { ...privateObjects },
};
Expand All @@ -129,15 +129,13 @@ export function buildRootObject(vatPowers) {
doneLoading(['agoric']);
}

// TODO: Remove; home object is deprecated.
if (decentralObjects) {
Object.assign(
replObjects.home,
decentralObjects,
privateObjects,
handyObjects,
);
}
// TODO: Maybe remove sometime; home object is deprecated.
Object.assign(
replObjects.home,
decentralObjects,
privateObjects,
deprecatedObjects,
);
},

// devices.command invokes our inbound() because we passed to
Expand Down
71 changes: 38 additions & 33 deletions packages/vats/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,10 @@ export function buildRootObject(vatPowers, vatParameters) {
// environments.
const spawner = E(vats.spawner).buildSpawner(vatAdminSvc);

const localTimerService = E(vats.timer).createTimerService(devices.timer);

// Needed for DApps, maybe for user clients.
const uploads = E(vats.uploads).getUploads();
const scratch = E(vats.uploads).getUploads();

// Only create the plugin manager if the device exists.
let plugin;
Expand Down Expand Up @@ -874,11 +876,9 @@ export function buildRootObject(vatPowers, vatParameters) {
return allComparable(
harden({
...(plugin ? { plugin } : {}),
// TODO: Our preferred name is "scratch", but there are many Dapps
// that use "uploads".
scratch: uploads,
uploads,
scratch,
spawner,
localTimerService,
network: vats.network,
http: httpRegCallback,
vattp: makeVattpFrom(vats),
Expand Down Expand Up @@ -945,32 +945,40 @@ export function buildRootObject(vatPowers, vatParameters) {

// ag-setup-solo runs this.
case 'client': {
assert(FIXME_GCI, X`client must be given GCI`);
let localBundle;
let chainBundle;
const deprecated = {};

const localTimerService = await E(vats.timer).createTimerService(
devices.timer,
);
await registerNetworkProtocols(vats, bridgeManager, null);
// Tell the http server about our presences.
const updatePresences = () =>
E(vats.http).setPresences(localBundle, chainBundle, deprecated);

await setupCommandDevice(vats.http, devices.command, {
client: true,
});
await addRemote(FIXME_GCI);
// addEgress(..., index, ...) is called in vat-provisioning.
const demoProvider = await E(vats.comms).addIngress(
FIXME_GCI,
PROVISIONER_INDEX,
);
const localBundle = await createLocalBundle(
vats,
devices,
vatAdminSvc,
);
await E(vats.http).setPresences(localBundle);
const bundle = await E(demoProvider).getDemoBundle();
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService,
});
const addLocalPresences = async () => {
await registerNetworkProtocols(vats, bridgeManager, null);

await setupCommandDevice(vats.http, devices.command, {
client: true,
});
localBundle = await createLocalBundle(vats, devices, vatAdminSvc);

// TODO: Remove this when we can.
deprecated.uploads = localBundle.scratch;
await updatePresences();
};

const addChainPresences = async () => {
assert(FIXME_GCI, X`client must be given GCI`);
await addRemote(FIXME_GCI);
// addEgress(..., index, ...) is called in vat-provisioning.
const demoProvider = E(vats.comms).addIngress(
FIXME_GCI,
PROVISIONER_INDEX,
);
chainBundle = await E(demoProvider).getDemoBundle();
await updatePresences();
};

await Promise.all([addLocalPresences(), addChainPresences()]);
break;
}

Expand Down Expand Up @@ -1017,10 +1025,7 @@ export function buildRootObject(vatPowers, vatParameters) {
});
await Promise.all(
hardcodedClientAddresses.map(async addr => {
const { transmitter, setReceiver } = await E(
vats.vattp,
).addRemote(addr);
await E(vats.comms).addRemote(addr, transmitter, setReceiver);
await addRemote(addr);
await E(vats.comms).addEgress(
addr,
PROVISIONER_INDEX,
Expand Down

0 comments on commit 656514e

Please sign in to comment.