Skip to content

Commit

Permalink
fix: move COMMIT_BLOCK immediately before the Cosmos SDK commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 21, 2021
1 parent 11ce03a commit f0d2e68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 2 additions & 3 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,9 @@ func (app *GaiaApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci

// Commit tells the controller that the block is commited
func (app *GaiaApp) Commit() abci.ResponseCommit {
// Wrap the BaseApp's Commit method
res := app.BaseApp.Commit()
// Frontrun the BaseApp's Commit method
swingset.CommitBlock(app.SwingSetKeeper)
return res
return app.BaseApp.Commit()
}

// LoadHeight loads a particular height
Expand Down
25 changes: 13 additions & 12 deletions packages/cosmic-swingset/src/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function makeBlockManager({
}) {
let computedHeight = bootstrapBlock ? undefined : savedHeight;
let runTime = 0;
let chainTime;

async function kernelPerformAction(action) {
// TODO warner we could change this to run the kernel only during END_BLOCK
Expand Down Expand Up @@ -108,6 +109,17 @@ export default function makeBlockManager({
`Committed height ${action.blockHeight} does not match computed height ${computedHeight}`,
);
}

// Save the kernel's computed state just before the chain commits.
const start2 = Date.now();
await saveOutsideState(computedHeight, savedActions, savedChainSends);

const saveTime = Date.now() - start2;

console.debug(
`wrote SwingSet checkpoint [run=${runTime}ms, chainSave=${chainTime}ms, kernelSave=${saveTime}ms]`,
);

flushChainSends(false);
break;
}
Expand Down Expand Up @@ -184,7 +196,7 @@ export default function makeBlockManager({
// We write out our on-chain state as a number of chainSends.
const start = Date.now();
await saveChainState();
const chainTime = Date.now() - start;
chainTime = Date.now() - start;

// Advance our saved state variables.
savedActions = currentActions;
Expand All @@ -195,17 +207,6 @@ export default function makeBlockManager({
} else {
computedHeight = action.blockHeight;
}

// Save the kernel's computed state so that we can recover if we ever
// reset before Cosmos SDK commit.
const start2 = Date.now();
await saveOutsideState(computedHeight, savedActions, savedChainSends);

const saveTime = Date.now() - start2;

console.debug(
`wrote SwingSet checkpoint [run=${runTime}ms, chainSave=${chainTime}ms, kernelSave=${saveTime}ms]`,
);
}

currentActions = [];
Expand Down

0 comments on commit f0d2e68

Please sign in to comment.