Skip to content

Commit c3bd9f5

Browse files
committed
fix(reku): add timeout retry for crosscheck
1 parent 33e9303 commit c3bd9f5

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

packages/reku/src/event/crosschecker/autochecker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ethers } from 'ethers'
2-
import { polling, retryOnNull, sleep } from '@ora-io/utils'
2+
import { polling, sleep, timeoutWithRetry } from '@ora-io/utils'
33
import { ETH_BLOCK_INTERVAL } from '../../constants'
44
import type { Providers } from '../../types/w3'
55
import { CrossCheckerCacheManager } from './cache/manager'
@@ -56,7 +56,7 @@ export class AutoCrossChecker extends BaseCrossChecker {
5656

5757
this.cache = new CrossCheckerCacheManager(options?.store, { keyPrefix: options?.storeKeyPrefix, ttl: options?.storeTtl })
5858

59-
const latestblocknum = await retryOnNull(async () => await this.provider.provider?.getBlockNumber())
59+
const latestblocknum = await timeoutWithRetry(() => this.provider.provider?.getBlockNumber(), 15 * 1000, 3)
6060

6161
// resume checkpoint priority: options.fromBlock > cache > latestblocknum + 1
6262
const defaultInitCheckpoint = await this.cache.getCheckpoint() ?? (latestblocknum + 1)
@@ -85,7 +85,7 @@ export class AutoCrossChecker extends BaseCrossChecker {
8585
}
8686

8787
const waitNextCrosscheck = async (): Promise<boolean> => {
88-
const latestblocknum = await retryOnNull(async () => await this.provider.provider?.getBlockNumber())
88+
const latestblocknum = await timeoutWithRetry(() => this.provider.provider?.getBlockNumber(), 15 * 1000, 3)
8989
if (ccrOptions.toBlock + delayBlockFromLatest > latestblocknum) {
9090
// sleep until the toBlock
9191
await sleep((ccrOptions.toBlock + delayBlockFromLatest - latestblocknum) * blockInterval)

packages/reku/src/event/crosschecker/basechecker.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ethers } from 'ethers'
2-
import { retryOnNull } from '@ora-io/utils'
2+
import { timeoutWithRetry } from '@ora-io/utils'
33
import { ETH_BLOCK_COUNT_ONE_HOUR } from '../../constants'
44
import type { Providers } from '../../types/w3'
55
import type { CrossCheckFromParam, CrossCheckRangeParam, CrossCheckRetroParam, SimpleLog } from './interface'
@@ -34,7 +34,11 @@ export class BaseCrossChecker {
3434

3535
// define from, to
3636
// TODO: use blockNumber for performance
37-
const block = await retryOnNull(async () => await this.provider.provider?.getBlock('latest'))
37+
const block = await timeoutWithRetry(() => this.provider.provider.getBlock('latest'), 15 * 1000, 3)
38+
if (!block) {
39+
console.warn('crosscheck failed to get latest block')
40+
return
41+
}
3842
const options: CrossCheckRangeParam = {
3943
...ccrOptions,
4044
fromBlock: block.number - retroBlockCount,
@@ -53,8 +57,11 @@ export class BaseCrossChecker {
5357
ccfOptions: CrossCheckFromParam,
5458
) {
5559
// TODO: use blockNumber for performance
56-
const block = await retryOnNull(async () => await this.provider.provider?.getBlock('latest'))
57-
60+
const block = await timeoutWithRetry(() => this.provider.provider.getBlock('latest'), 15 * 1000, 3)
61+
if (!block) {
62+
console.warn('crosscheck failed to get latest block')
63+
return
64+
}
5865
// suggest use large retroBlockCount
5966
if (block.number - ccfOptions.fromBlock < ETH_BLOCK_COUNT_ONE_HOUR)
6067
console.warn('crosscheck retroBlockCount too low, recommend crosscheck interval >= 1 hour')
@@ -105,7 +112,7 @@ export class BaseCrossChecker {
105112
...(topics && { topics }),
106113
}
107114
if (this.provider.provider) {
108-
const logs = await this.provider.provider?.getLogs(params)
115+
const logs = await timeoutWithRetry(() => this.provider.provider.getLogs(params), 15 * 1000, 3)
109116
// get ignoreLogs keys
110117
const ignoreLogs = options.ignoreLogs
111118

0 commit comments

Comments
 (0)