Skip to content

feat(sequencer): Origin Selector optimistically prefetches the next origin#12073

Closed
BrianBland wants to merge 3 commits intoethereum-optimism:developfrom
BrianBland:origin-selector-optimistic-prefetching
Closed

feat(sequencer): Origin Selector optimistically prefetches the next origin#12073
BrianBland wants to merge 3 commits intoethereum-optimism:developfrom
BrianBland:origin-selector-optimistic-prefetching

Conversation

@BrianBland
Copy link
Contributor

@BrianBland BrianBland commented Sep 24, 2024

Description
Updates the Sequencer's L1 origin selector to locally cache the currentOrigin and nextOrigin attributes and also optimistically prefetch the nextOrigin in the background whenever FindL1Origin is called. This also forces a synchronous prefetch on each ForkchoiceUpdateEvent in order to produce more deterministic behavior, but at the cost of sequencer performance when using a single-threaded event loop. (Addressed by #11100)

In many cases, the existing L1 origin is "good enough" for building a new block from the sequencer's perspective, and it's better to fetch the next L1 origin in the background instead of spending precious time that could otherwise be used for building the next block. In these conditions, the currentOrigin will be returned and fetching the nextOrigin will be scheduled in a new goroutine. Whenever the nextOrigin is already available and valid, this is returned instead.

Under specific circumstances, such as when a new L1 origin has not been found for a long period of time, the sequencer will actually need to review the nextOrigin and determine if this is valid (behind the next L2 block time). In these cases, the FindL1Origin call will wait for the background fetch to complete, and compare these potential origins immediately.

This implementation uses a channel for notifying the FindL1Origin context of the fetch job's completion (by closing the channel). The channel is created within the public FindL1Origin method, and passed to a private findL1Origin, which is typically used in tests to provide a reasonable degree of deterministic concurrency control.

Note: This changeset can also be simplified to only introduce event-based prefetching for the L1 Origin Selector (using ForkchoiceUpdateEvent) if desired

Tests

Added several new origin selector tests and added concurrency checks to the existing tests in order to ensure that this new prefetching behavior is safe under all conditions.

Metadata

Partially addresses #11960. In order to fully resolve this ticket, we may need to merge the origin selector and attributes builder, so that an origin is only selected if and only if it also has the relevant attributes already built or has all of the data needed to build attributes (L1 receipts).

@BrianBland BrianBland requested review from a team as code owners September 24, 2024 00:33
@BrianBland BrianBland requested a review from ajsutton September 24, 2024 00:33
@BrianBland BrianBland force-pushed the origin-selector-optimistic-prefetching branch from 417064e to 7102d7e Compare September 24, 2024 00:45
@BrianBland BrianBland requested a review from a team as a code owner September 24, 2024 00:45
@codecov
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.87%. Comparing base (43224ed) to head (83287a6).
Report is 22 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12073      +/-   ##
===========================================
- Coverage    79.10%   78.87%   -0.24%     
===========================================
  Files           41       41              
  Lines         3437     3437              
===========================================
- Hits          2719     2711       -8     
- Misses         548      557       +9     
+ Partials       170      169       -1     
Flag Coverage Δ
cannon-go-tests 78.87% <ø> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

@BrianBland BrianBland marked this pull request as draft September 24, 2024 18:44
@BrianBland BrianBland force-pushed the origin-selector-optimistic-prefetching branch from 7102d7e to 5f38c57 Compare September 24, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant