Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null blocks from RPC #158

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`);
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 38 additions & 9 deletions src/data_sources/events/web3.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -253,18 +253,47 @@ export class Web3Source {
}

public async getBlockInfoAsync(blockNumber: number): Promise<BlockWithoutTransactionData> {
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<BlockWithoutTransactionData> {
Expand Down
Loading