Skip to content

Commit

Permalink
Fix null blocks from RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalencar committed Oct 3, 2024
1 parent b6dc740 commit dad3bfc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
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
29 changes: 19 additions & 10 deletions src/data_sources/events/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,26 @@ export class Web3Source {
}

public async getBlockInfoAsync(blockNumber: number): Promise<BlockWithoutTransactionData> {
try {
logger.debug(`Fetching block ${blockNumber}`);

const block = (await this._web3Wrapper.getBlockIfExistsAsync(blockNumber)) as BlockWithoutTransactionData;

if (block == null) {
throw new Error(`Block ${blockNumber} returned null`);
while (true) {
try {
logger.debug(`Fetching block ${blockNumber}`);

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...`);
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...`);
} else {
logger.error(`Unknown error while fetching block ${blockNumber}. Retrying...`);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
return block;
} catch (err) {
throw new Error(`Encountered error while fetching block ${blockNumber}: ${err}`);
}
}

Expand Down

0 comments on commit dad3bfc

Please sign in to comment.