diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 296f46e5..db574b77 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -352,9 +352,9 @@ services: SCHEMA: 'events_linea' FEAT_ZEROEX_EXCHANGE_PROXY: "false" SETTLER_DEPLOYMENT_BLOCK: 6917652 - MAX_BLOCKS_TO_SEARCH: 800 - MAX_BLOCKS_TO_PULL: 100 - MAX_BLOCKS_REORG: 500 + MAX_BLOCKS_TO_SEARCH: 125 + MAX_BLOCKS_TO_PULL: 25 + MAX_BLOCKS_REORG: 125 SECONDS_BETWEEN_RUNS: 1 RESCRAPE_BLOCKS: 10 FEAT_WRAP_UNWRAP_NATIVE_EVENT: "true" @@ -363,6 +363,7 @@ services: FEAT_ERC20_TRANSFER_ALL: "true" FEAT_SETTLER_ERC721_TRANSFER_EVENT: "true" TOKENS_FROM_TRANSFERS_START_BLOCK: "1" + FEAT_SOCKET_BRIDGE_EVENT: "true" SOCKET_BRIDGE_CONTRACT_ADDRESS: "0x3a23f943181408eac424116af7b7790c94cb97a5" SOCKET_BRIDGE_EVENT_START_BLOCK: "6917652" networks: diff --git a/src/config.ts b/src/config.ts index f198c5b3..2c521ba0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -36,6 +36,7 @@ import { DEFAULT_MAX_BLOCKS_REORG, DEFAULT_MAX_BLOCKS_TO_PULL, DEFAULT_MAX_BLOCKS_TO_SEARCH, + DEFAULT_MAX_RPC_RETRY_CALLS, DEFAULT_MAX_TIME_TO_SEARCH, DEFAULT_MAX_TX_TO_PULL, DEFAULT_METRICS_PATH, @@ -157,6 +158,8 @@ export const MAX_BLOCKS_TO_SEARCH = getIntConfig('MAX_BLOCKS_TO_SEARCH', DEFAULT export const MAX_TX_TO_PULL = getIntConfig('MAX_TX_TO_PULL', DEFAULT_MAX_TX_TO_PULL); +export const MAX_RPC_RETRY_CALLS = getIntConfig('MAX_RPC_RETRY_CALLS', DEFAULT_MAX_RPC_RETRY_CALLS); + export const CHAIN_ID = process.env.CHAIN_ID ? parseInt(process.env.CHAIN_ID, 10) : throwError(`Must specify valid CHAIN_ID. Got: ${process.env.CHAIN_ID}`); diff --git a/src/constants.ts b/src/constants.ts index 81de98de..33853113 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,6 +10,7 @@ export const DEFAULT_BLOCKS_REORG_CHECK_INCREMENT = 35; export const DEFAULT_MAX_BLOCKS_TO_PULL = 120; export const DEFAULT_MAX_BLOCKS_TO_SEARCH = 120; export const DEFAULT_MAX_TX_TO_PULL = 1000; +export const DEFAULT_MAX_RPC_RETRY_CALLS = 5; export const DEFAULT_BLOCK_FINALITY_THRESHOLD = 10; export const DEFAULT_RESCRAPE_BLOCKS = 0; export const DEFAULT_MINUTES_BETWEEN_RUNS = 3; diff --git a/src/data_sources/events/web3.ts b/src/data_sources/events/web3.ts index c51d7418..ee04deb5 100644 --- a/src/data_sources/events/web3.ts +++ b/src/data_sources/events/web3.ts @@ -1,4 +1,4 @@ -import { MAX_TX_TO_PULL, BLOCK_RECEIPTS_MODE } from '../../config'; +import { MAX_TX_TO_PULL, BLOCK_RECEIPTS_MODE, MAX_RPC_RETRY_CALLS } from '../../config'; import { chunk, logger } from '../../utils'; import { BlockWithTransactionData, @@ -253,18 +253,47 @@ export class Web3Source { } public async getBlockInfoAsync(blockNumber: number): Promise { - try { - logger.debug(`Fetching block ${blockNumber}`); + let retryCount = 0; - const block = (await this._web3Wrapper.getBlockIfExistsAsync(blockNumber)) as BlockWithoutTransactionData; + while (retryCount < MAX_RPC_RETRY_CALLS) { + try { + logger.debug(`Fetching block ${blockNumber}`); - if (block == null) { - throw new Error(`Block ${blockNumber} returned null`); + const block = (await this._web3Wrapper.getBlockIfExistsAsync( + blockNumber, + )) as BlockWithoutTransactionData; + + if (block == null) { + logger.warn( + `Block ${blockNumber} returned null, likely because the RPC node is not fully synced. Retrying... (${ + retryCount + 1 + }/${MAX_RPC_RETRY_CALLS})`, + ); + retryCount++; + await new Promise((resolve) => setTimeout(resolve, 1000)); + continue; + } + return block; + } catch (err) { + if (err instanceof Error) { + logger.error( + `Error while fetching block ${blockNumber}: ${err.message}. Retrying... (${ + retryCount + 1 + }/${MAX_RPC_RETRY_CALLS})`, + ); + } else { + logger.error( + `Unknown error while fetching block ${blockNumber}. Retrying... (${ + retryCount + 1 + }/${MAX_RPC_RETRY_CALLS})`, + ); + } + retryCount++; + await new Promise((resolve) => setTimeout(resolve, 1000)); } - return block; - } catch (err) { - throw new Error(`Encountered error while fetching block ${blockNumber}: ${err}`); } + + throw new Error(`Failed to fetch block ${blockNumber} after ${MAX_RPC_RETRY_CALLS} retries.`); } public async getCurrentBlockAsync(): Promise {