Skip to content

Extended ledger#4981

Open
Exxenoz wants to merge 14 commits into
nanocurrency:developfrom
Exxenoz:extended_ledger
Open

Extended ledger#4981
Exxenoz wants to merge 14 commits into
nanocurrency:developfrom
Exxenoz:extended_ledger

Conversation

@Exxenoz

@Exxenoz Exxenoz commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This branch adds optional extended ledger indices to speed up RPC paths that previously required expensive ledger scans. The indices are persisted in the store, maintained by ledger runtime hooks, and can be populated or dropped through dedicated CLI commands.

The extended ledger indices added are:

  • account_block_by_height

    • Indexes { account, height } -> block_hash.
    • Speeds up account_history, especially offset-based lookups.
  • account_delegator_by_weight

    • Indexes delegators by { representative, weight, delegator }.
    • Speeds up delegators and delegators_count.
  • account_receivable_by_amount

    • Indexes receivables by { account, amount, send_block_hash }.
    • Speeds up receivable and accounts_receivable when sorted results are requested.
  • receive_block_by_send_block

    • Maps a send/source block hash to the receive/open block that consumed it.
    • Speeds up blocks_info when receive_hash=true.

The branch also adds shared extended ledger lifecycle handling, including persisted initialized flags, startup population, drop behavior, runtime add/remove/update hooks, and logging for index population and maintenance.

Note: when the extended account_delegator_by_weight index is enabled, the delegators RPC now returns delegators in descending weight order instead of delegator account order.
Note: when the extended account_receivable_by_amount index is enabled, the accounts_receivable and receivable RPCs use that index only for sorted requests (sorting: true).

CLI

New maintenance commands:

  • --populate_extended_ledger_indices

    • Builds missing extended ledger indices for an existing ledger.
  • --drop_extended_ledger_indices

    • Drops all extended ledger index data and marks the indices disabled.

The extended ledger index feature is controlled through the node configuration option extended_ledger_index.

Tests

Adds focused core tests for extended ledger index population, runtime maintenance, rollback/delete behavior, drop behavior, disabled reopen behavior, and direct index-table verification.

The extended ledger index test cases were created with GPT-5.5 assistance (using Codex), and all changes were manually reviewed by me.

@gr0vity-dev-bot

gr0vity-dev-bot commented Jan 5, 2026

Copy link
Copy Markdown

Test Results for Commit e864619

Pull Request 4981: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 120s)
  • 5n4pr_conf_10k_change: PASS (Duration: 196s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 133s)
  • 5n4pr_conf_change_independant: PASS (Duration: 114s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 115s)
  • 5n4pr_conf_send_independant: PASS (Duration: 120s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 117s)
  • 5n4pr_rocks_10k_change: PASS (Duration: 170s)

Last updated: 2026-07-09 08:40:11 UTC

@Exxenoz
Exxenoz force-pushed the extended_ledger branch 5 times, most recently from 2dcdb2c to 6d4a2ed Compare January 8, 2026 13:30
@Exxenoz
Exxenoz force-pushed the extended_ledger branch 2 times, most recently from 40e2e6f to 28b8749 Compare January 24, 2026 16:42
@Exxenoz
Exxenoz force-pushed the extended_ledger branch 4 times, most recently from 22a66c3 to 6bcaea9 Compare January 29, 2026 02:08
@Exxenoz
Exxenoz force-pushed the extended_ledger branch 3 times, most recently from ba56a86 to f15ba60 Compare June 4, 2026 23:36
@Exxenoz
Exxenoz force-pushed the extended_ledger branch 3 times, most recently from b6fe35d to da01eb0 Compare July 5, 2026 02:34
@Exxenoz
Exxenoz marked this pull request as ready for review July 5, 2026 02:35
@Exxenoz
Exxenoz force-pushed the extended_ledger branch 2 times, most recently from 0406cd3 to f1c2921 Compare July 5, 2026 03:18
@Exxenoz
Exxenoz force-pushed the extended_ledger branch from f1c2921 to 3c3fe28 Compare July 5, 2026 03:26
@Exxenoz
Exxenoz force-pushed the extended_ledger branch from 2e83023 to 9722ad7 Compare July 5, 2026 04:07
Exxenoz added 3 commits July 7, 2026 00:01
When the extended `account_delegators_by_weight` index is enabled, the `delegators` RPC now returns delegators in descending weight order instead of delegator account order.

This differs from the fallback path because the fallback scans the account table, which is ordered by account, while the extended index is keyed by representative, weight, and delegator. Re-sorting the indexed results by delegator account would defeat part of the purpose of using the weight index, and `count` cannot exactly match both the account-table ordering and the weight-index ordering at the same time (without scanning/sorting ALL delegator entries). For the indexed path, the RPC therefore follows the natural index semantics and returns the highest-weight delegators first.
@Exxenoz
Exxenoz force-pushed the extended_ledger branch from 7c20b50 to 5f9f2ba Compare July 6, 2026 22:01
Exxenoz added 2 commits July 7, 2026 01:55
Populate the account-height block lookup index by scanning the block table directly instead of walking each account chain through successor lookups. This uses the sideband height already available from the block iterator and avoids extra random block/successor reads during ledger upgrade.
Use crawlers when populating extended ledger indices so long-running write transactions can be refreshed in batches, matching the topology index population flow. Progress logging is now time-based while refreshes remain tied to the population batch size.

Add crawler::next_entry(): The existing crawler increment advances by logical/group key for specialized tables such as pending. This would skip additional receivables for the same account when populating the account receivables index with crawler++.
@Exxenoz

Exxenoz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Extended ledger indices populate performance observations

I tested the initial populate of all four extended ledger index tables with both LMDB and RocksDB.

Test hardware

Component Specification
CPU AMD Ryzen 9 5950X, 16 cores, 4.9GHz
SSD Samsung SSD 970 EVO 1 TB
RAM 32 GB DDR5

Populate results

Backend txn.refresh() during populate Populate duration Ledger size before populate Ledger size after populate Size increase
LMDB No ~3h 40m 134 GB 177 GB +43 GB
LMDB Yes ~4h 50m 134 GB 218 GB +84 GB
RocksDB Yes ~1h 30m 88.3 GB 126 GB +37.7 GB

Open question

The main open question is how we should handle the LMDB behavior.

The additional LMDB file growth when using txn.refresh() could be caused by random insert patterns and LMDB page splits/page reuse behavior, but I am not sure whether this is expected or whether it indicates a bug or pathological behavior in the current populate strategy.

Should this be investigated further and potentially optimized for LMDB?

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.

2 participants