[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:
Julian 2024-06-27 16:32:32 -03:00 committed by GitHub
parent f9ff45d278
commit 51f6e8ebb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -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;
}

View File

@ -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,
})
);
});