Commit e9602d86 authored by Mark Tyneway's avatar Mark Tyneway

dtl: add retry loop to `eth_getBlockRange`

The RPC endpoint `eth_getBlockRange` is a custom endpoint
that was added to `l2geth` to speed up pulling in data
from the sequencer to run a replica of the sequencer.
A `null` response is not handled properly, this commit
adds the retries and errors after too many retries.
It linearly backs off its timing with each retry
parent e0f7e5f4
---
'@eth-optimism/data-transport-layer': patch
---
Handle null response for `eth_getBlockRange` query
......@@ -219,6 +219,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
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(
this.state.l2RpcProvider.connection.url,
req,
......@@ -227,7 +239,18 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
const respJson = await bfj.parse(resp.data, {
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) {
......
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