Skip to content

feat(code/engine): Store proposed values in WAL #896

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

Merged
merged 48 commits into from
Apr 8, 2025
Merged

Conversation

romac
Copy link
Member

@romac romac commented Mar 7, 2025

Closes: #897


PR author checklist

For all contributors

For external contributors

Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (f77bdb3) to head (f631c01).
Report is 3 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #896   +/-   ##
===========================
===========================
Components Coverage Δ
core ∅ <ø> (∅)
engine ∅ <ø> (∅)
app ∅ <ø> (∅)
starknet ∅ <ø> (∅)

@ancazamfir
Copy link
Collaborator

Sorry for the stale review, forgot to publish couple of days ago. Will close the ones resolved.

Copy link
Contributor

@nenadmilosevic95 nenadmilosevic95 left a comment

Choose a reason for hiding this comment

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

I made a full pass! It looks good to me! Great job @romac ! I left some comments!

As a side not, I am more convinced that different modes parts-only and others should not be part of consensus-core, and that we need to rethink these designs, if for nothing but just for code clarity. IMHO, these modes are complicating the code.

romac and others added 7 commits April 7, 2025 12:23
Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Anca Zamfir <ancazamfir@users.noreply.github.com>
Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Anca Zamfir <ancazamfir@users.noreply.github.com>
@ancazamfir
Copy link
Collaborator

ancazamfir commented Apr 7, 2025

As a side not, I am more convinced that different modes parts-only and others should not be part of consensus-core, and that we need to rethink these designs, if for nothing but just for code clarity. IMHO, these modes are complicating the code.

We can look into it but here is a brief overview and history:

  • we have started with proposal-and-parts mode, it was not configurable as it was the only one. To handle it we added the full_proposal.rs where we mux the ProposedValue from the app and the Proposal wire message. When we have both we call the driver and then the state machine
  • then starknet model came with parts-only and, from conversations with farcaster, it transpired that a proposal-only mode would have been useful (had it been ready). So we added these two modes
  • it is the application that configures consensus with the mode that best fits, we can make recommendations
  • the full_proposer in core-consensus, core-driver, core_votekeeper and core-state-machine are and will stay mode agnostic
  • the mode is handled in the core-consensus/src/handle/.. event or message handlers and there are a couple of early checks for misconfiguration in the engine

We have draft PRs: #942 and (not directly related) #943 along your comments (and some raised during the review of ADR003). Mainly trying to move the checks in the engine and get rid of proposal parts. But we do have some concerns and we can discuss in the future.

@romac romac requested a review from ancazamfir April 8, 2025 07:12
Copy link
Contributor

@nenadmilosevic95 nenadmilosevic95 left a comment

Choose a reason for hiding this comment

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

Made another pass! LGTM! Great job!

Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Romain Ruetschi <github@romac.me>
@romac romac added this pull request to the merge queue Apr 8, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 8, 2025
* feat(code/engine): Store locally proposed value in WAL and re-use it if available

* Cleanup

* Merge all three WalAppend effects into one

* Cleanup

* Add multi-round test with timeouts

* Cleanup

* Add a middleware to the test context to override vote building

* Less noisy logs in test app

* Add concept of middleware to change from the tests how votes and proposals are built (#945)

* Make `new_prevote`, `new_precommit` and `new_proposal` methods of `Context` instead of static functions

* Stuff middleware in the `TestContext` instead of static variable

* Remove unused dep

* Add way to access middleware from TestContext

* Deduplicate timeout elapsed code

* Replay proposed values before other entries

* Split `StartHeight` into `PrepareHeight` and `StartHeight`

* Add check that we are in the right state before starting a height

* Actually replay the proposed values

* Cleanup

* Store proposed values for other rounds

* Better naming

* Replay locally proposed value as an `ProposedValue` input instead of `Propose` input

* Fix unused variable warning

* Replay proposals

* On GetValue output from the driver, re-use any full proposal proposed by us instead of performing `GetValue` effect

* Remove outdated check in Starknet tests

* Cleanup

* Simplify WAL replay

* Store all proposed values (local or not) in the WAL
* Replay the whole WAL in one go after `StartHeight`
* The application will get a `GetValue` effect during WAL replay, but
  its response will be ignored if we already had a proposed value in the WAL.

* Re-enable checks in byzantine WAL tests

* Cleanup

* Cleanup protos

* Replay ProposedValue exactly as stored in the WAL

* Log proposed values to WAL only if not already seen and therefore
logged.

* Fix issue with last commit, store proposed values before getting the
full proposal.

* Fix comments

* Ensure all timeouts can be decoded

* Re-add check that was previously removed when we were replaying WAL before starting round 0

* Merge `WalReplay` events into one

* Review comments

* Apply suggestions from code review

Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Anca Zamfir <ancazamfir@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Anca Zamfir <ancazamfir@users.noreply.github.com>

* Add comments to handler functions

* Add comments to on_propose handler

* Add encode and decode functions for all wal entries

* Apply suggestion from code review

Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Signed-off-by: Romain Ruetschi <github@romac.me>

---------

Signed-off-by: Anca Zamfir <ancazamfir@users.noreply.github.com>
Signed-off-by: Romain Ruetschi <github@romac.me>
Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com>
Co-authored-by: nenadmilosevic95 <50905385+nenadmilosevic95@users.noreply.github.com>
Merged via the queue into main with commit f02d3f6 Apr 8, 2025
22 checks passed
@romac romac deleted the romac/wal-proposed-value branch April 8, 2025 08:01
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.

code: WAL scenarios for Proposal
4 participants