Always fetched finalized blocks by hash #2741
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had an incident in mainnet caused by some nodes having different cached finalized L1 blocks for the same block number, which should not be possible. We theorize that this can happen due to fetching finalized blocks by number. We assume that if we no block
n
is finalized and we fetch blockn - k
, it must also be finalized. However, if we have an L1 client failover (or the L1 provider itself fails over to a different node, as we suspect happened with Infura) it is possible that we observedn
was finalized from one RPC node, but then we try to fetchn - k
from a different RPC node which hasn't finalizedn
yet, and returns an unfinalized block forn - k
which is later uncled.This PR:
get_finalized_block
in the L1 client to start from a known finalized block (either one which is already cached or one which is explicitly fetched using thefinalized
block tag) and then work backwards by parent hashes, fetching blocks by hash so we know we get only blocks which are in the finalized chain, until reaching the desired blockparent_hash
to the information we cache about each L1 blockNote that in the worst case, this could increase the number of blocks we fetch from the RPC. However, in the very common case, the latest finalized block (the one returned from fetching the
finalized
tag) is exactly the block we are trying to fetch, and we don't have to do anything else.