Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modulo block ahead of finalized #2132

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/node-core/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,15 @@ export abstract class BaseFetchService<
return moduloBlocks;
}

getEnqueuedModuloBlocks(startBlockHeight: number): number[] {
/**
*
* @param startBlockHeight
* @param endBlockHeight is either FinalizedHeight or BestHeight, ensure ModuloBlocks not greater than this number
*/
getEnqueuedModuloBlocks(startBlockHeight: number, endBlockHeight: number): number[] {
return this.getModuloBlocks(
startBlockHeight,
this.nodeConfig.batchSize * Math.max(...this.getModulos()) + startBlockHeight
Math.min(this.nodeConfig.batchSize * Math.max(...this.getModulos()) + startBlockHeight, endBlockHeight)
).slice(0, this.nodeConfig.batchSize);
}

Expand Down Expand Up @@ -313,14 +318,22 @@ export abstract class BaseFetchService<

const enqueuingBlocks =
handlers.length && this.getModulos().length === handlers.length
? this.getEnqueuedModuloBlocks(startBlockHeight)
? this.getEnqueuedModuloBlocks(startBlockHeight, latestHeight)
: range(startBlockHeight, endHeight + 1);

await this.enqueueBlocks(enqueuingBlocks);
}
}

private async enqueueBlocks(enqueuingBlocks: number[]): Promise<void> {
// We check enqueuingBlocks length rather than cleanedBatchBlocks
// Because when bypass blocks, cleanedBatchBlocks can be [], but latestBufferHeight could be valid to update metadata
// See comments in blockDispatcher.enqueueBlocks method
if (!enqueuingBlocks.length) {
logger.info(`No blocks to enqueue at the moment.`);
await delay(10);
jiqiang90 marked this conversation as resolved.
Show resolved Hide resolved
return;
}
const cleanedBatchBlocks = this.filteredBlockBatch(enqueuingBlocks);
await this.blockDispatcher.enqueueBlocks(
cleanedBatchBlocks,
Expand Down
Loading