Verify ledger balance consistency on startup#4916
Merged
pwojcikdev merged 2 commits intonanocurrency:developfrom Jun 23, 2025
Merged
Verify ledger balance consistency on startup#4916pwojcikdev merged 2 commits intonanocurrency:developfrom
pwojcikdev merged 2 commits intonanocurrency:developfrom
Conversation
Test Results for Commit a7818e5Pull Request 4916: Results Test Case Results
Last updated: 2025-06-22 23:30:52 UTC |
a34640c to
936c816
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a fail-fast consistency check for ledger balances on startup and integrates a new consistency_check flag into cache generation.
- Add
burn_balanceparameter torep_weights::verify_consistencyand update call sites - Introduce ledger-level
verify_consistencyand compute active, pending, and burned balances - Replace individual cache flags manipulation with
generate_cache_flags::all_enabled/all_disabled
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| nano/secure/rep_weights.hpp | Updated verify_consistency signature to take burn_balance |
| nano/secure/rep_weights.cpp | Adjusted consistency assertions to account for burned balance |
| nano/secure/ledger.hpp | Added verify_consistency declaration; made existing methods const |
| nano/secure/ledger.cpp | Implemented new balance-sum consistency logic and logging |
| nano/secure/generate_cache_flags.hpp | Added consistency_check flag and static constructors |
| nano/secure/generate_cache_flags.cpp | Removed enable_all definition (header now self-contained) |
| nano/node/inactive_node.cpp | Switched to all_disabled for cache flags |
| nano/node/bounded_backlog.cpp | Updated rollback check to call ledger‐level consistency |
| nano/node/block_processor.cpp | Updated batch processor to call ledger‐level consistency |
| nano/nano_node/entry.cpp | Switched to all_enabled for cache flags |
| nano/core_test/ledger.cpp | Renamed test for zero‐weight representative |
Comments suppressed due to low confidence (3)
nano/secure/ledger.hpp:98
- Add a doc comment for
verify_consistencyexplaining its purpose, inputs, and failure conditions.
void verify_consistency (secure::transaction const &) const;
nano/secure/ledger.cpp:868
- The new
consistency_checkpath contains complex balance-summing logic; add unit tests to cover both passing and failing scenarios.
if (generate_cache_flags.consistency_check)
nano/secure/ledger.cpp:947
- Typo in log message: "commited" should be spelled "committed".
logger.info (nano::log::type::ledger, "Weight commited: {} | unused: {}",
936c816 to
4d4e50c
Compare
4d4e50c to
a7818e5
Compare
pwojcikdev
added a commit
that referenced
this pull request
Jun 23, 2025
Verify ledger balance consistency on startup # Conflicts: # nano/secure/generate_cache_flags.hpp
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.
This adds a fail-fast consistency check for ledger balances. Any discrepancies will cause immediate node crash.
This is part of an effort to protect against silent ledger-database corruption.
Why it matters
Silent corruption can lead to incorrect quorum decisions. A stale or incorrect rep-weight map undermines consensus.
Detecting discrepancies the moment they appear keeps the blast radius small.
We have historically observed database corruption on nodes running on the RocksDB backend. It is important to remember that RocksDB is still considered experimental, so no production services should rely on it.