refactor(consensus/proposal): encapsulate ordering rules in store#3675
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3675 +/- ##
==========================================
- Coverage 76.38% 76.34% -0.05%
==========================================
Files 396 396
Lines 36579 36596 +17
==========================================
- Hits 27941 27938 -3
- Misses 6664 6682 +18
- Partials 1974 1976 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rodrodros
reviewed
May 25, 2026
rodrodros
reviewed
May 25, 2026
Contributor
|
@RafaelGranza the benchmark only shows performance data, but there is no memory usage benchmark, could you please add them as well |
rodrodros
reviewed
May 25, 2026
81ee300 to
3652e55
Compare
Contributor
|
Nice refactor, the abstraction looks cleaner with these rules inside |
ongyimeng
approved these changes
May 26, 2026
6112d00 to
33a4a22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (ISSUE)
ProposalStorewas leaking coordination rules (ordering, what's safe to write/delete and when) across call sites. This refactor pushes those rules into the type itself so new callers can't violate them.What changed
sync.Map[Hash]*BRto nestedsync.Map[Height]*sync.Map[Hash]*BR.atomic.Uint64advanced monotonically via CAS inDeleteUpToHeight.height <= finalized; recheck-then-self-clean after publish to handle races with a concurrent sweep.height <= finalizedcheck before returning, so readers never observe entries past the cursor even during a race.The public API (
Get(hash),Store(hash, br),DeleteUpToHeight(h)) is unchanged for callers; no signature changes leak into thetendermint.Applicationinterface.Design note
There was a real trade-off in how to balance cost between Get and Delete:
sync.Map[Hash]*BRsync.Map[Height]*sync.Map[Hash]*BR(this PR)Picked the nested layout because num_heights is small in practice (1 to 3 in steady state, up to ~5 with stragglers), so the O(num_heights)
Getis sub-100ns and invisible end-to-end (network and VM latency dominate). The benchmarks below confirm theGethit stays in the tens of nanoseconds.The flip side is meaningful:
Deletecost is decoupled from total entry count. That's where the big speedup comes from.Benchmark comparison
Apple M-series,
go test -bench -benchmem. Spread across 5 live heights to reflect realistic steady-state consensus.The benchmark file (
proposal_store_bench_test.go) is included as requested for future comparisons.