optimism
optimism copied to clipboard
Add buffered caching of L1 block refs to the confDepth-aware fetcher
Description
Introduces reorg-sensitive caching to the confirmation-depth-aware L1 block fetcher, in order to avoid unnecessary synchronous fetches in the sequencer and derivation pipeline.
This adds two new data structures, a generic indexed ring buffer, and an l1HeadBuffer
which wraps the ring buffer and enforces that the underlying buffer only ever contains a series of sequential blocks with a valid chain of parent hashes.
The confirmation-depth-aware L1 block fetcher now includes an l1HeadBuffer
which holds up to 1000 block refs, and inserts the latest known l1Head
into the buffer on each call to L1BlockRefByNumber
, preferring values held in the buffer to invoking the underlying L1Fetcher
.
Under normal circumstances and assuming a sufficient confirmation depth, this is expected to always read from the cache and never fall back to the L1Fetcher
. Shallow reorgs may partially invalidate the cache, but the cache should be populated at a given block height by the time that the confirmation depth is passed.
Tests
Added new test cases for the caching behavior, in order to ensure that reorg conditions and cache eviction behave as expected.
Additional context
Add any other context about the problem you're solving.
Metadata
- Fixes #[Link to Issue]