Skip to content

Optimize ledger::confirm (...) database operations#5030

Merged
pwojcikdev merged 3 commits intonanocurrency:developfrom
pwojcikdev:bounded-dfs-helper
Feb 13, 2026
Merged

Optimize ledger::confirm (...) database operations#5030
pwojcikdev merged 3 commits intonanocurrency:developfrom
pwojcikdev:bounded-dfs-helper

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

@pwojcikdev pwojcikdev commented Feb 12, 2026

Previously, ledger::confirm performed redundant block_get calls — 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:

  • Blocks are fetched once when discovered as dependencies and reused when resolved — saves 2 store.block.get() calls per confirmed block
  • A new confirmed.block_exists(block) overload skips the store fetch and only checks confirmation height — saves 2 DB lookups per already-confirmed dependency

The bounded_dfs helper is extracted as a generic, tested algorithm that handles stack bounding, overflow detection, and partial progress for the caller's outer loop.

@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Feb 12, 2026

Test Results for Commit 3b88c51

Pull Request 5030: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 131s)
  • 5n4pr_conf_10k_change: PASS (Duration: 216s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 141s)
  • 5n4pr_conf_change_independant: PASS (Duration: 143s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 138s)
  • 5n4pr_conf_send_independant: PASS (Duration: 136s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 127s)
  • 5n4pr_rocks_10k_change: PASS (Duration: 164s)

Last updated: 2026-02-13 06:39:48 UTC

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 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.hpp with comprehensive test coverage
  • Added optimized block_exists(transaction, block) overload to skip block fetch when checking confirmation status
  • Added block_pruned() helper to ledger_set_any for explicit pruned block detection
  • Refactored ledger::confirm to 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.

@pwojcikdev pwojcikdev merged commit 6656b45 into nanocurrency:develop Feb 13, 2026
32 of 34 checks passed
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.

3 participants