Skip to content

Verify ledger balance consistency on startup#4916

Merged
pwojcikdev merged 2 commits intonanocurrency:developfrom
pwojcikdev:ledger-verify-consistency
Jun 23, 2025
Merged

Verify ledger balance consistency on startup#4916
pwojcikdev merged 2 commits intonanocurrency:developfrom
pwojcikdev:ledger-verify-consistency

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

@pwojcikdev pwojcikdev commented Jun 22, 2025

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.

@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Jun 22, 2025

Test Results for Commit a7818e5

Pull Request 4916: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 111s)
  • 5n4pr_conf_10k_change: PASS (Duration: 156s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 138s)
  • 5n4pr_conf_change_independant: PASS (Duration: 127s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 125s)
  • 5n4pr_conf_send_independant: PASS (Duration: 123s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 111s)
  • 5n4pr_rocks_10k_change: PASS (Duration: 137s)

Last updated: 2025-06-22 23:30:52 UTC

@pwojcikdev pwojcikdev force-pushed the ledger-verify-consistency branch from a34640c to 936c816 Compare June 22, 2025 17:24
@pwojcikdev pwojcikdev requested a review from Copilot June 22, 2025 20:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_balance parameter to rep_weights::verify_consistency and update call sites
  • Introduce ledger-level verify_consistency and 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_consistency explaining its purpose, inputs, and failure conditions.
	void verify_consistency (secure::transaction const &) const;

nano/secure/ledger.cpp:868

  • The new consistency_check path 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: {}",

@pwojcikdev pwojcikdev force-pushed the ledger-verify-consistency branch from 936c816 to 4d4e50c Compare June 22, 2025 22:26
@pwojcikdev pwojcikdev force-pushed the ledger-verify-consistency branch from 4d4e50c to a7818e5 Compare June 22, 2025 22:28
@pwojcikdev pwojcikdev merged commit 71d8bae into nanocurrency:develop Jun 23, 2025
26 checks passed
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
pwojcikdev added a commit to pwojcikdev/nano-node that referenced this pull request Jun 24, 2025
…erify-consistency"

This reverts commit 71d8bae, reversing
changes made to 1c5e8cc.
@qwahzi qwahzi added this to the V29 milestone Jun 25, 2025
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.

4 participants