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,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