Skip to content

Commit 7703aa7

Browse files
committed
fix(chain): properly commit state
1 parent d40f2ac commit 7703aa7

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

packages/cosmic-swingset/lib/launch-chain.js

+7-18
Original file line numberDiff line numberDiff line change
@@ -108,41 +108,30 @@ export async function launch(kernelStateDBDir, mailboxStorage, vatsDir, argv) {
108108
saveState();
109109

110110
// then arrange for inbound messages to be processed, after which we save
111-
async function turnCrank(committed) {
111+
async function turnCrank() {
112112
const start = Date.now();
113113
await controller.run();
114114
const runTime = Date.now() - start;
115-
if (committed) {
116-
saveState(runTime);
117-
} else {
118-
console.log(`proposed SwingSet transaction [run=${runTime}ms]`);
119-
}
115+
// Have to save state every time.
116+
saveState(runTime);
120117
}
121118

122-
async function deliverInbound(sender, messages, ack, committed) {
119+
async function deliverInbound(sender, messages, ack, _committed) {
123120
if (!(messages instanceof Array)) {
124121
throw new Error(`inbound given non-Array: ${messages}`);
125122
}
126123
if (mb.deliverInbound(sender, messages, ack)) {
127124
console.log(`mboxDeliver: ADDED messages`);
128-
await turnCrank(committed);
129-
} else if (committed) {
130-
// We need to save our state on every commitment.
131-
saveState();
132125
}
126+
await turnCrank();
133127
}
134128

135-
async function deliverStartBlock(blockHeight, blockTime, committed) {
129+
async function deliverStartBlock(blockHeight, blockTime, _committed) {
136130
const addedToQueue = timer.poll(blockTime);
137131
console.log(
138132
`polled; blockTime:${blockTime}, h:${blockHeight} ADDED: ${addedToQueue}`,
139133
);
140-
if (addedToQueue) {
141-
await turnCrank(committed);
142-
} else if (committed) {
143-
// We need to save our state on every commitment.
144-
saveState();
145-
}
134+
await turnCrank();
146135
}
147136

148137
return { deliverInbound, deliverStartBlock };

0 commit comments

Comments
 (0)