From f9dd12ddd2ba77903c7f9fa9aa5b62f06bfd797a Mon Sep 17 00:00:00 2001 From: tcar121293 Date: Thu, 8 Feb 2024 14:49:01 +0100 Subject: [PATCH] fix: add reorg count (#166) --- src/indexer/services/evmIndexer/evmIndexer.ts | 6 +++--- src/indexer/services/substrateIndexer/substrateIndexer.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/indexer/services/evmIndexer/evmIndexer.ts b/src/indexer/services/evmIndexer/evmIndexer.ts index 863a9fea..5c13ab1c 100644 --- a/src/indexer/services/evmIndexer/evmIndexer.ts +++ b/src/indexer/services/evmIndexer/evmIndexer.ts @@ -20,8 +20,8 @@ import { OfacComplianceService } from "../ofac" import { getLogs } from "./evmfilter" import { decodeLogs } from "./evmEventParser" -const BLOCK_TIME = 15000 - +const BLOCK_TIME = Number(process.env.BLOCK_TIME) || 15000 +const BLOCK_DELAY = Number(process.env.BLOCK_DELAY) || 10 export class EvmIndexer { private pastEventsQueryInterval = 1000 private eventsQueryInterval = 1 @@ -92,7 +92,7 @@ export class EvmIndexer { while (!this.stopped) { try { const latestBlock = await this.provider.getBlockNumber() - if (currentBlock >= latestBlock) { + if (currentBlock + BLOCK_DELAY >= latestBlock) { await sleep(BLOCK_TIME) continue } diff --git a/src/indexer/services/substrateIndexer/substrateIndexer.ts b/src/indexer/services/substrateIndexer/substrateIndexer.ts index bf0ecce7..55f6abb5 100644 --- a/src/indexer/services/substrateIndexer/substrateIndexer.ts +++ b/src/indexer/services/substrateIndexer/substrateIndexer.ts @@ -15,8 +15,8 @@ import { saveEvents, sleep } from "../../../indexer/utils/substrate" import AccountRepository from "../../../indexer/repository/account" import CoinMarketCapService from "../coinmarketcap/coinmarketcap.service" -const BLOCK_TIME = 12000 - +const BLOCK_TIME = Number(process.env.BLOCK_TIME) || 12000 +const BLOCK_DELAY = Number(process.env.BLOCK_DELAY) || 10 export class SubstrateIndexer { private domainRepository: DomainRepository private executionRepository: ExecutionRepository @@ -85,7 +85,7 @@ export class SubstrateIndexer { try { const latestBlock = await this.provider.rpc.chain.getBlock() const currentBlockHash = await this.provider.rpc.chain.getBlockHash(currentBlock) - if (currentBlock >= Number(latestBlock.block.header.number)) { + if (currentBlock + BLOCK_DELAY >= Number(latestBlock.block.header.number)) { await sleep(BLOCK_TIME) continue }