[Blockchain Watcher] (EVM) Fix evm process blocks (#1519)
* Validate latestBlockHeight block * Improve comments * Improve validation * Improve latestBlockHeight validation * Resolve evm test --------- Co-authored-by: julian merlo <julianmerlo@julians-MacBook-Pro-2.local>
This commit is contained in:
parent
f9ff45d278
commit
51f6e8ebb0
|
@ -111,11 +111,12 @@ export class PollEvm extends RunPollingJob {
|
|||
}
|
||||
|
||||
let toBlock = BigInt(fromBlock) + BigInt(this.cfg.getBlockBatchSize());
|
||||
// limit toBlock to obtained block height
|
||||
if (toBlock > fromBlock && toBlock > latestBlockHeight) {
|
||||
// Limit toBlock to obtained block height and restrict toBlock update because the latestBlockHeight may be outdated
|
||||
if (toBlock > fromBlock && toBlock > latestBlockHeight && fromBlock < latestBlockHeight) {
|
||||
toBlock = latestBlockHeight;
|
||||
}
|
||||
// limit toBlock to configured toBlock
|
||||
|
||||
// Limit toBlock to configured toBlock
|
||||
if (this.cfg.toBlock && toBlock > this.cfg.toBlock) {
|
||||
toBlock = this.cfg.toBlock;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ describe("PollEvm", () => {
|
|||
it("should be able to read logs from latest block when no fromBlock is configured", async () => {
|
||||
const currentHeight = 10n;
|
||||
const blocksAhead = 1n;
|
||||
const blockBatchSize = 100n;
|
||||
givenEvmBlockRepository(currentHeight, blocksAhead);
|
||||
givenMetadataRepository();
|
||||
givenStatsRepository();
|
||||
|
@ -53,7 +54,7 @@ describe("PollEvm", () => {
|
|||
addresses: cfg.filters[0].addresses,
|
||||
topics: cfg.filters[0].topics,
|
||||
fromBlock: currentHeight + blocksAhead,
|
||||
toBlock: currentHeight + blocksAhead,
|
||||
toBlock: currentHeight + blocksAhead + blockBatchSize,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue