Commit 67a0414d authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2218 from ethereum-optimism/fix/handle-null-response

fix: handle null response in `eth_getBlockRange`
parents 59732e5f e9602d86
---
'@eth-optimism/data-transport-layer': patch
---
Handle null response for `eth_getBlockRange` query
...@@ -219,6 +219,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> { ...@@ -219,6 +219,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
id: '1', id: '1',
} }
// Retry the `eth_getBlockRange` query in case the endBlockNumber
// is greater than the tip and `null` is returned. This gives time
// for the sync to catch up
let result = null
let retry = 0
while (result === null) {
if (retry === 6) {
throw new Error(
`unable to fetch block range [${startBlockNumber},${endBlockNumber})`
)
}
const resp = await axios.post( const resp = await axios.post(
this.state.l2RpcProvider.connection.url, this.state.l2RpcProvider.connection.url,
req, req,
...@@ -227,7 +239,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> { ...@@ -227,7 +239,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
const respJson = await bfj.parse(resp.data, { const respJson = await bfj.parse(resp.data, {
yieldRate: 4096, // this yields abit more often than the default of 16384 yieldRate: 4096, // this yields abit more often than the default of 16384
}) })
blocks = respJson.result
result = respJson.result
if (result === null) {
retry++
this.logger.info(
`request for block range [${startBlockNumber},${endBlockNumber}) returned null, retry ${retry}`
)
await sleep(1000 * retry)
}
}
blocks = result
} }
for (const block of blocks) { for (const block of blocks) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment