Optimize ledger::confirm (...) database operations#5030
Merged
pwojcikdev merged 3 commits intonanocurrency:developfrom Feb 13, 2026
Merged
Optimize ledger::confirm (...) database operations#5030pwojcikdev merged 3 commits intonanocurrency:developfrom
ledger::confirm (...) database operations#5030pwojcikdev merged 3 commits intonanocurrency:developfrom
Conversation
Test Results for Commit 3b88c51Pull Request 5030: Results Test Case Results
Last updated: 2026-02-13 06:39:48 UTC |
b53b72d to
3b88c51
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the ledger::confirm function by reducing redundant database operations during block confirmation. The optimization refactors the confirmation algorithm to work with block instances rather than hashes, extracting a reusable bounded_dfs helper that handles depth-first traversal with stack size limits and overflow detection.
Changes:
- Extracted bounded iterative DFS algorithm to
nano/lib/bounded_dfs.hppwith comprehensive test coverage - Added optimized
block_exists(transaction, block)overload to skip block fetch when checking confirmation status - Added
block_pruned()helper toledger_set_anyfor explicit pruned block detection - Refactored
ledger::confirmto operate on block instances, reducing database lookups from 3-4 per block to 1
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| nano/lib/bounded_dfs.hpp | New generic bounded DFS algorithm with overflow handling and multi-pass support |
| nano/core_test/bounded_dfs.cpp | Comprehensive test suite (520 lines) covering overflow, multi-pass, early return, and edge cases |
| nano/secure/ledger_set_confirmed.hpp | Added block_exists overload taking block instance |
| nano/secure/ledger_set_confirmed.cpp | Implemented optimized confirmation check using height comparison |
| nano/secure/ledger_set_any.hpp | Added block_pruned method declaration |
| nano/secure/ledger_set_any.cpp | Implemented block_pruned to check pruned store |
| nano/secure/ledger.cpp | Refactored confirm to use bounded_dfs with block instances, added cementing_overflow stat |
| nano/lib/stats_enums.hpp | Added cementing_overflow detail for tracking overflow conditions |
| nano/lib/CMakeLists.txt | Added bounded_dfs.hpp to build (alphabetically sorted) |
| nano/core_test/CMakeLists.txt | Added bounded_dfs.cpp test file (alphabetically sorted) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Previously,
ledger::confirmperformed redundantblock_getcalls — each block was fetched from the store twice (once to compute dependencies, once to confirm). Additionally, checking whether a dependency was already confirmed required 3 DB lookups (pruned check, block fetch, confirmation height check).By changing the DFS to operate on block instances rather than hashes:
store.block.get()calls per confirmed blockconfirmed.block_exists(block)overload skips the store fetch and only checks confirmation height — saves 2 DB lookups per already-confirmed dependencyThe
bounded_dfshelper is extracted as a generic, tested algorithm that handles stack bounding, overflow detection, and partial progress for the caller's outer loop.