Skip to content

Commit

Permalink
fix: prevent simulated blocks from reentering the kernel
Browse files Browse the repository at this point in the history
Closes #763
  • Loading branch information
michaelfig committed Mar 25, 2020
1 parent 8f94d50 commit 42f7abd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/cosmic-swingset/lib/ag-solo/fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import anylogger from 'anylogger';

import { launch } from '../launch-chain';
import makeBlockManager from '../block-manager';
import { makeWithQueue } from './queue';

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

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

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

async function simulateBlock() {
clearTimeout(nextBlockTimeout);
const withBlockQueue = makeWithQueue();
const simulateBlock = withBlockQueue(async () => {
const actualStart = Date.now();
// Gather up the new messages into the latest block.
thisBlock.push(...intoChain);
Expand Down Expand Up @@ -101,11 +102,12 @@ export async function connectToFakeChain(basedir, GCI, role, delay, inbound) {
ack: 0,
};
inbound(GCI, outbox, ack);
}
});

async function deliver(newMessages, acknum) {
intoChain.push([newMessages, acknum]);
if (!delay) {
clearTimeout(nextBlockTimeout);
await simulateBlock();
}
}
Expand Down

0 comments on commit 42f7abd

Please sign in to comment.