Skip to content

Commit

Permalink
feat: use same (instrumented) kernel stepper for bootstrap
Browse files Browse the repository at this point in the history
This allows us to collect and report on bootstrap crank statistics
in the same way as transaction-initiated cranks after bootstrap.
  • Loading branch information
michaelfig committed Apr 6, 2021
1 parent 1de984e commit 33d42a8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/cosmic-swingset/lib/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,29 @@ export async function launch(

// ////////////////////////////
// TODO: This is where we would add the scheduler.
async function endBlock(_blockHeight, _blockTime) {
//
// Note that the "bootstrap until no more progress" state will call this
// function without any arguments.
async function crankScheduler(maximumCranks = Infinity) {
let now = Date.now();
const blockStart = now;
let stepsRemaining = FIXME_MAX_CRANKS_PER_BLOCK;
let stepped = true;
// TODO: how to rewrite without an await in loop?
// (without blowing out the stack or promise chain)
while (stepped && stepsRemaining > 0) {
let numCranks = 0;
while (stepped && numCranks < maximumCranks) {
const crankStart = now;
// eslint-disable-next-line no-await-in-loop
stepped = await controller.step();
now = Date.now();
schedulerCrankTimeHistogram.record(now - crankStart);
stepsRemaining -= 1;
numCranks += 1;
}
schedulerBlockTimeHistogram.record((now - blockStart) / 1000);
}

async function endBlock(_blockHeight, _blockTime) {
await crankScheduler(FIXME_MAX_CRANKS_PER_BLOCK);
}

async function saveChainState() {
// Save the mailbox state.
await mailboxStorage.commit();
Expand Down Expand Up @@ -202,9 +207,11 @@ export async function launch(
}
// Run the kernel until there is no more progress possible without inbound
// messages.
await controller.run();
await crankScheduler();

// Commit the results, marking it so that we don't do it again.
// Commit the results, with the savedHeight updated so that we don't do it
// again. All future cranks will be with the scheduler in a normal block
// context.
savedHeight = 0;
await saveOutsideState(savedHeight, savedActions, savedChainSends);
}
Expand Down

0 comments on commit 33d42a8

Please sign in to comment.