Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-batcher: extract state pruning, block fetching and progress checking into a single pure function #13060

Merged
merged 56 commits into from
Dec 6, 2024

Conversation

geoknee
Copy link
Contributor

@geoknee geoknee commented Nov 25, 2024

This approach enables the majority of the complexity in these jobs to be encapsulated, deduplicated, and easily unit tested.

Supercedes #12981.

@geoknee geoknee linked an issue Nov 25, 2024 that may be closed by this pull request
2 tasks
@geoknee geoknee added the A-op-batcher Area: op-batcher label Nov 27, 2024
@geoknee geoknee marked this pull request as ready for review December 2, 2024 11:25
@geoknee geoknee requested review from a team as code owners December 2, 2024 11:25
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (4ee839a) to head (b069105).
Report is 76 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #13060       +/-   ##
============================================
- Coverage    44.51%        0   -44.52%     
============================================
  Files          801        0      -801     
  Lines        72026        0    -72026     
============================================
- Hits         32059        0    -32059     
+ Misses       37359        0    -37359     
+ Partials      2608        0     -2608     
Flag Coverage Δ
cannon-go-tests-32 ?
cannon-go-tests-64 ?

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

see 801 files with indirect coverage changes

Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

looking good, just minor comments

op-batcher/batcher/driver.go Show resolved Hide resolved
op-batcher/batcher/driver.go Outdated Show resolved Hide resolved
op-batcher/batcher/sync_actions.go Outdated Show resolved Hide resolved
op-batcher/batcher/sync_actions.go Outdated Show resolved Hide resolved
op-batcher/batcher/sync_actions.go Outdated Show resolved Hide resolved
geoknee and others added 4 commits December 5, 2024 14:28
Co-authored-by: Sebastian Stammler <seb@oplabs.co>
also set HeadL1 to more realistic values (generally ahead of currentL1 due to nonzero confirmation depth)
@geoknee
Copy link
Contributor Author

geoknee commented Dec 5, 2024

Going by the codecov report: we should add a test case where there are no blocks in the state. That should give us 100% coverage of the new pure function.

@sebastianst sebastianst added this pull request to the merge queue Dec 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 6, 2024
@sebastianst sebastianst added this pull request to the merge queue Dec 6, 2024
Merged via the queue into develop with commit f9eaf1f Dec 6, 2024
42 checks passed
@sebastianst sebastianst deleted the gk/compute-sync-actions branch December 6, 2024 10:56
sigma pushed a commit that referenced this pull request Dec 19, 2024
…ng into a single pure function (#13060)

* remove lastStoredBlock and lastL1Tip from BatchSubmitter state

We can use the channelManager's state to infer lastStoredBlock. And lastL1Tip is actually unused.

* change log line wording

* fix typo

* remove unecessary method

* WIP first pass at computeSyncActions

* computeSyncAction takes a ChannelStatuser interface

also report fully inclusive range of blocks to load

* add happy path test case

* clearState is a pointer

we can use nil value to signal no state clearing should be performed

* add more test cases

* add another test case

* computeSyncActions only takes prevCurrentL1, not prevSyncStatus

* add batcher restart case

* safe chain reorg case

* failed to make progress case

* simplify log messages, print entire struct

* add godoc

* wire up computeSyncActions

* cache prevCurrentL1 on BatchSubmitter

* document stages

* fix loadBlocksIntoState range interpretation

* pass syncStatus, not pointer to syncStatus and add test case for no progress

* check unsafe status before trying to get more blocks

* do not panic on invalid block ranges

return an error instead. This error is ultimated swallowed, matching existing behaviour.

* test: add assetions and mock data about blockID passed to clearState

* add readme section on max channel duration

* add back unit tests for pruning methods

* fix pruneBlocks behaviour when blockCursor pointed at block which is now pruned

* rename waitForNodeSync to sequencerOutOfSync

* Introduce SeqOutOfSyncError

* move SyncActions code to a separate file

* ChannelStatuser -> channelStatuser

* SeqOutOfSyncError -> ErrSeqOutOfSync

* move ctx to first position in fn signature

* do not update cached prevCurrentL1 value if there is an ErrSeqOutOfSync

* Always warn log when computeSyncActions returns an error

* move sync actions test to separate file

* computeSyncActions returns a bool, not an error

There is only ever one kind of error returned

* SyncActions -> syncActions

* define local variables to aid readability

* organise computeSyncActions and introduce startAfresh syncAction

Add comments explaining logical flow: the checks get increasingly deep and we return early where possible.

* undo changes to submodule

* move test utils to sync_actions_test.go file

* ensure pruneChannels clears currentChannel when appropriate

* fix submodule"

* don't try to get number of block if none exists

* improve log

* Update op-batcher/batcher/driver.go

Co-authored-by: Sebastian Stammler <seb@oplabs.co>

* use struct for block range, not array

* use startAfresh in one more place

* add test case for multiple channels

also set HeadL1 to more realistic values (generally ahead of currentL1 due to nonzero confirmation depth)

* print value of *struct  in Stringer

* add test case when there are no blocks in state

* Update op-batcher/batcher/sync_actions.go

Co-authored-by: Sebastian Stammler <seb@oplabs.co>

* tighten up log messages and test descriptions

---------

Co-authored-by: Sebastian Stammler <seb@oplabs.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-op-batcher Area: op-batcher
Projects
None yet
Development

Successfully merging this pull request may close these issues.

batcher: live-lock caused by incomplete state clearing when sequencer restarts
2 participants