Skip to content

Commit

Permalink
fix(chain): properly commit state
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 2, 2020
1 parent d40f2ac commit 7703aa7
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions packages/cosmic-swingset/lib/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,41 +108,30 @@ export async function launch(kernelStateDBDir, mailboxStorage, vatsDir, argv) {
saveState();

// then arrange for inbound messages to be processed, after which we save
async function turnCrank(committed) {
async function turnCrank() {
const start = Date.now();
await controller.run();
const runTime = Date.now() - start;
if (committed) {
saveState(runTime);
} else {
console.log(`proposed SwingSet transaction [run=${runTime}ms]`);
}
// Have to save state every time.
saveState(runTime);
}

async function deliverInbound(sender, messages, ack, committed) {
async function deliverInbound(sender, messages, ack, _committed) {
if (!(messages instanceof Array)) {
throw new Error(`inbound given non-Array: ${messages}`);
}
if (mb.deliverInbound(sender, messages, ack)) {
console.log(`mboxDeliver: ADDED messages`);
await turnCrank(committed);
} else if (committed) {
// We need to save our state on every commitment.
saveState();
}
await turnCrank();
}

async function deliverStartBlock(blockHeight, blockTime, committed) {
async function deliverStartBlock(blockHeight, blockTime, _committed) {
const addedToQueue = timer.poll(blockTime);
console.log(
`polled; blockTime:${blockTime}, h:${blockHeight} ADDED: ${addedToQueue}`,
);
if (addedToQueue) {
await turnCrank(committed);
} else if (committed) {
// We need to save our state on every commitment.
saveState();
}
await turnCrank();
}

return { deliverInbound, deliverStartBlock };
Expand Down

0 comments on commit 7703aa7

Please sign in to comment.