Skip to content

Commit

Permalink
move epoch transition to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei authored and turbocrime committed Aug 20, 2024
1 parent 377575e commit f78d415
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,21 @@ export class BlockProcessor implements BlockProcessorInterface {
throw new Error(`Unexpected block height: ${compactBlock.height} at ${currentHeight}`);
}

latestKnownBlockHeight = await this.processBlock(compactBlock, latestKnownBlockHeight);
await this.processBlock(compactBlock, latestKnownBlockHeight);

// We only query Tendermint for the latest known block height once, when
// the block processor starts running. Once we're caught up, though, the
// chain will of course continue adding blocks, and we'll keep processing
// them. So, we need to update `latestKnownBlockHeight` once we've passed
// it.
if (compactBlock.height > latestKnownBlockHeight) {
latestKnownBlockHeight = compactBlock.height;
}

const isLastBlockOfEpoch = !!compactBlock.epochRoot;
if (isLastBlockOfEpoch) {
await this.handleEpochTransition(compactBlock.height, latestKnownBlockHeight);
}
}
}

Expand Down Expand Up @@ -340,25 +354,9 @@ export class BlockProcessor implements BlockProcessorInterface {
);
}

// We only query Tendermint for the latest known block height once, when
// the block processor starts running. Once we're caught up, though, the
// chain will of course continue adding blocks, and we'll keep processing
// them. So, we need to update `latestKnownBlockHeight` once we've passed
// it.
if (compactBlock.height > latestKnownBlockHeight) {
latestKnownBlockHeight = compactBlock.height;
}

const isLastBlockOfEpoch = !!compactBlock.epochRoot;
if (isLastBlockOfEpoch) {
await this.handleEpochTransition(compactBlock.height, latestKnownBlockHeight);
}

if (globalThis.__ASSERT_ROOT__) {
await this.assertRootValid(compactBlock.height);
}

return latestKnownBlockHeight;
}

/*
Expand Down

0 comments on commit f78d415

Please sign in to comment.