Skip to content

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

Merged
romac merged 48 commits intomainfrom
romac/wal-proposed-value
Apr 8, 2025
Merged

feat(code/engine): Store proposed values in WAL#896
romac merged 48 commits intomainfrom
romac/wal-proposed-value

Conversation

@romac
Copy link
Copy Markdown
Contributor

@romac romac commented Mar 7, 2025

Closes: #897


PR author checklist

For all contributors

For external contributors

@codecov
Copy link
Copy Markdown

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 ∅ <ø> (∅)

Comment thread code/crates/engine/src/util/events.rs Outdated
Comment thread code/crates/test/tests/it/wal.rs
Comment thread code/crates/core-consensus/src/handle/proposed_value.rs Outdated
@ancazamfir
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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.

Comment thread code/crates/core-consensus/src/full_proposal.rs Outdated
Comment thread code/crates/engine/src/wal/entry.rs
Comment thread code/crates/engine/src/wal/entry.rs Outdated
Comment thread code/crates/engine/src/wal/entry.rs
Comment thread code/crates/core-consensus/src/effect.rs
Comment thread code/crates/core-consensus/src/handle/proposal.rs
Comment thread code/crates/core-consensus/src/handle/proposed_value.rs
Comment thread code/crates/test/tests/it/wal.rs
Comment thread code/crates/engine/src/consensus.rs
Comment thread code/crates/engine/src/consensus.rs
Comment thread code/crates/core-consensus/src/full_proposal.rs Outdated
Comment thread code/crates/engine/src/wal/entry.rs
Comment thread code/crates/engine/src/wal/entry.rs Outdated
Comment thread code/crates/engine/src/wal/entry.rs
Comment thread code/crates/engine/src/consensus.rs
Comment thread code/crates/test/tests/it/wal.rs
Comment thread code/crates/engine/src/consensus.rs
Comment thread code/crates/core-consensus/src/handle/proposal.rs
Comment thread code/crates/core-consensus/src/full_proposal.rs Outdated
Comment thread code/crates/engine/src/wal/entry.rs
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
Copy Markdown
Contributor

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
Copy Markdown
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!

Comment thread code/crates/core-consensus/src/handle/proposal.rs Outdated
Comment thread code/crates/core-consensus/src/handle/propose.rs
Comment thread code/crates/engine/src/wal/entry.rs
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