Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions crates/provider/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,35 @@ impl<N: Network> NewBlocks<N> {

// Then try to fill as many blocks as possible.
// TODO: Maybe use `join_all`
let mut retries = MAX_RETRIES;
for number in self.next_yield..=block_number {
'fill: for number in self.next_yield..=block_number {
debug!(number, "fetching block");
let block = match client.request("eth_getBlockByNumber", (U64::from(number), false)).await {
Ok(Some(block)) => block,
Err(RpcError::Transport(err)) if retries > 0 && err.recoverable() => {
debug!(number, %err, "failed to fetch block, retrying");
retries -= 1;
continue;
}
Ok(None) if retries > 0 => {
debug!(number, "failed to fetch block (doesn't exist), retrying");
retries -= 1;
continue;
}
Err(err) => {
error!(number, %err, "failed to fetch block");
break;
}
Ok(None) => {
error!(number, "failed to fetch block (doesn't exist)");
break;
let mut retries = MAX_RETRIES;
let block = loop {
match client.request("eth_getBlockByNumber", (U64::from(number), false)).await {
Ok(Some(block)) => break Some(block),
Err(RpcError::Transport(err)) if retries > 0 && err.recoverable() => {
debug!(number, %err, "failed to fetch block, retrying");
retries -= 1;
continue;
}
Ok(None) if retries > 0 => {
debug!(number, "failed to fetch block (doesn't exist), retrying");
retries -= 1;
continue;
}
Err(err) => {
error!(number, %err, "failed to fetch block");
break None;
}
Ok(None) => {
error!(number, "failed to fetch block (doesn't exist)");
break None;
}
}
};
let Some(block) = block else {
break 'fill;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just continue here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just continue here?

@mattsse We need to break out of the loop once the per-number retries are exhausted. Continuing here would skip over the missing block, leaving a hole at self.next_yield; newer blocks would pile up in the cache but couldn’t be yielded until that hole is filled, so we’d waste RPC calls and still block the stream. The previous implementation also break’d on an unrecoverable failure, so this keeps the same behaviour while making the retry budget actually per block.

};
self.known_blocks.put(number, block);
if self.known_blocks.len() == BLOCK_CACHE_SIZE.get() {
// Cache is full, should be consumed before filling more blocks.
Expand Down