Skip to content

Commit 96d4912

Browse files
committed
fix: commit kernel state in END_BLOCK, for reset robustness
1 parent e175782 commit 96d4912

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

packages/cosmic-swingset/lib/block-manager.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export default function makeBlockManager({
7070

7171
let currentActions = [];
7272
let decohered;
73-
let saveTime = 0;
7473

7574
async function blockManager(action) {
7675
if (decohered) {
@@ -85,17 +84,6 @@ export default function makeBlockManager({
8584
`Committed height ${action.blockHeight} does not match computed height ${computedHeight}`,
8685
);
8786
}
88-
89-
const start = Date.now();
90-
91-
// Save the kernel's computed state because we've committed
92-
// the block (i.e. have obtained consensus on the prior
93-
// state).
94-
saveOutsideState(computedHeight, savedActions);
95-
savedHeight = computedHeight;
96-
97-
saveTime = Date.now() - start;
98-
currentActions = [];
9987
break;
10088
}
10189

@@ -138,8 +126,8 @@ export default function makeBlockManager({
138126
if (computedHeight === action.blockHeight) {
139127
// We are reevaluating, so send exactly the same downcalls to the chain.
140128
//
141-
// This is necessary since the block proposer will be asked to validate
142-
// the actions it just proposed (in Tendermint v0.33.0).
129+
// This is necessary only after a restart when Tendermint is reevaluating the
130+
// block that was interrupted and not committed.
143131
//
144132
// We assert that the return values are identical, which allows us not
145133
// to resave our state.
@@ -165,17 +153,24 @@ export default function makeBlockManager({
165153
const start = Date.now();
166154
const { mailboxSize } = saveChainState();
167155
const mbTime = Date.now() - start;
168-
log.debug(
169-
`wrote SwingSet checkpoint (mailbox=${mailboxSize}), [run=${runTime}ms, mb=${mbTime}ms, save=${saveTime}ms]`,
170-
);
171156

172157
// Advance our saved state variables.
173158
savedActions = currentActions;
174159
computedHeight = action.blockHeight;
175-
if (action.blockHeight === 0) {
176-
// No replay, no errors on genesis init.
177-
currentActions = [];
178-
}
160+
161+
// Save the kernel's computed state so that we can recover if we ever
162+
// reset before Cosmos SDK commit.
163+
const start2 = Date.now();
164+
saveOutsideState(computedHeight, savedActions);
165+
savedHeight = computedHeight;
166+
167+
const saveTime = Date.now() - start2;
168+
169+
log.debug(
170+
`wrote SwingSet checkpoint (mailbox=${mailboxSize}), [run=${runTime}ms, mb=${mbTime}ms, save=${saveTime}ms]`,
171+
);
172+
currentActions = [];
173+
179174
break;
180175
}
181176

0 commit comments

Comments
 (0)