Skip to content

Commit 42f7abd

Browse files
committed
fix: prevent simulated blocks from reentering the kernel
Closes #763
1 parent 8f94d50 commit 42f7abd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/cosmic-swingset/lib/ag-solo/fake-chain.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import anylogger from 'anylogger';
66

77
import { launch } from '../launch-chain';
88
import makeBlockManager from '../block-manager';
9+
import { makeWithQueue } from './queue';
910

1011
const log = anylogger('fake-chain');
1112

@@ -57,8 +58,8 @@ export async function connectToFakeChain(basedir, GCI, role, delay, inbound) {
5758

5859
const maximumDelay = (delay || PRETEND_BLOCK_DELAY) * 1000;
5960

60-
async function simulateBlock() {
61-
clearTimeout(nextBlockTimeout);
61+
const withBlockQueue = makeWithQueue();
62+
const simulateBlock = withBlockQueue(async () => {
6263
const actualStart = Date.now();
6364
// Gather up the new messages into the latest block.
6465
thisBlock.push(...intoChain);
@@ -101,11 +102,12 @@ export async function connectToFakeChain(basedir, GCI, role, delay, inbound) {
101102
ack: 0,
102103
};
103104
inbound(GCI, outbox, ack);
104-
}
105+
});
105106

106107
async function deliver(newMessages, acknum) {
107108
intoChain.push([newMessages, acknum]);
108109
if (!delay) {
110+
clearTimeout(nextBlockTimeout);
109111
await simulateBlock();
110112
}
111113
}

0 commit comments

Comments
 (0)