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,15 +219,38 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> { ...@@ -219,15 +219,38 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
id: '1', id: '1',
} }
const resp = await axios.post( // Retry the `eth_getBlockRange` query in case the endBlockNumber
this.state.l2RpcProvider.connection.url, // is greater than the tip and `null` is returned. This gives time
req, // for the sync to catch up
{ responseType: 'stream' } let result = null
) let retry = 0
const respJson = await bfj.parse(resp.data, { while (result === null) {
yieldRate: 4096, // this yields abit more often than the default of 16384 if (retry === 6) {
}) throw new Error(
blocks = respJson.result `unable to fetch block range [${startBlockNumber},${endBlockNumber})`
)
}
const resp = await axios.post(
this.state.l2RpcProvider.connection.url,
req,
{ responseType: 'stream' }
)
const respJson = await bfj.parse(resp.data, {
yieldRate: 4096, // this yields abit more often than the default of 16384
})
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