Skip to content

Commit 7946278

Browse files
committed
add retries for hl specific error
1 parent 82fc25b commit 7946278

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

evm/evm-rpc/src/data-source/get-blocks.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ export async function getBlocks(
3232
let blocks = await rpc.getBlockBatch(numbers, req)
3333

3434
let retries = 0
35-
let invalid = blocks.find(b => b._isInvalid)
36-
while (invalid != null) {
37-
await wait(100)
38-
39-
if (retries == 5) {
40-
throw new Error(invalid._errorMessage)
35+
while (true) {
36+
let invalid = blocks.find(b => b == null || b._isInvalid)
37+
38+
if (invalid) {
39+
if (retries == 5) {
40+
throw new Error(invalid._errorMessage)
41+
} else {
42+
await wait(100)
43+
44+
await requestInvalidBlocks(rpc, req, blocks)
45+
retries += 1
46+
}
47+
} else {
48+
return blocks
4149
}
42-
43-
await requestInvalidBlocks(rpc, req, blocks)
44-
retries += 1
4550
}
46-
47-
return blocks
4851
}

evm/evm-rpc/src/rpc.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Logger, createLogger} from '@subsquid/logger'
2-
import {CallOptions, RpcClient, RpcError, RpcProtocolError} from '@subsquid/rpc-client'
2+
import {CallOptions, RetryError, RpcClient, RpcError, RpcProtocolError} from '@subsquid/rpc-client'
33
import {
44
array,
55
BYTES,
@@ -132,7 +132,7 @@ export class Rpc {
132132
validateResult: getResultValidator(nullable(GetBlock)),
133133
validateError: info => {
134134
if (info.message.includes('cannot query unfinalized data')) return null // Avalanche
135-
if (info.message.includes('invalid block height')) return null // Hyperliquid
135+
if (info.message.includes('invalid block height')) throw new RetryError() // Hyperliquid
136136
throw new RpcError(info)
137137
}
138138
})
@@ -278,7 +278,11 @@ export class Rpc {
278278
}))
279279

280280
let results = await this.reduceBatchOnRetry(call, {
281-
validateResult: getResultValidator(nullable(array(Receipt)))
281+
validateResult: getResultValidator(nullable(array(Receipt))),
282+
validateError: info => {
283+
if (info.message.includes('invalid block height')) throw new RetryError() // Hyperliquid
284+
throw new RpcError(info)
285+
}
282286
})
283287

284288
let utils = await this.getChainUtils()

0 commit comments

Comments
 (0)