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