Repository navigation
wallet: index addresses(keyidx) and bulk-load our_addresses ranges - #9778
Open
daywalker90 wants to merge 1 commit into
Open
daywalker90 wants to merge 1 commit into
daywalker90 wants to merge 1 commit into
Conversation
When expanding `our_addresses` after restart (e.g. on the first block scan via `wallet_can_spend()` or in `init_wallet_scriptpubkey_watches()`), `our_addresses_add_for_index()` called `wallet_get_addrtype()` once per key index. Because the `addresses` table had no index on `keyidx`, each lookup performed a full table scan, resulting in O(N^2) startup cost for nodes with many issued addresses (such as nodes with `invoices-onchain-fallback`). Add a reversible index migration (`CREATE INDEX addresses_keyidx_idx ON addresses (keyidx)`) and introduce `our_addresses_add_range()` to load all `(keyidx, addrtype)` rows for `[start, end]` in a single ordered query before deriving keys, reducing database work from O(N^2) to O(N) while preserving existing missing-row (`ADDR_ALL`) and duplicate-row semantics. Update the manual DB-version-rewind tests in `tests/test_splicing.py` and `tests/test_splicing_disconnect.py` to drop `addresses_keyidx_idx` before re-running migrations. Changelog-Changed: wallet: indexed `addresses(keyidx)` and bulk-loaded address types when populating `our_addresses`, avoiding O(N^2) startup scans on nodes with many issued addresses.
daywalker90
force-pushed
the
wallet-addresses-index-range
branch
from
November 27, 2026 16:33
48c7f3f to
3aa8fdd
Compare
This branch has not been deployed
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.
When expanding our_addresses after restart (e.g. on the first block scan via wallet_can_spend() or in init_wallet_scriptpubkey_watches()), our_addresses_add_for_index() called wallet_get_addrtype() once per key index. Because the addresses table had no index on keyidx, each lookup performed a full table scan, resulting in O(N^2) startup cost for nodes with many issued addresses (such as nodes with invoices-onchain-fallback).
Add a reversible index migration on addresses(keyidx) and introduce our_addresses_add_range() to load all (keyidx, addrtype) rows for [start, end] in a single ordered query before deriving keys, reducing database work from O(N^2) to O(N) while preserving existing missing-row (ADDR_ALL) and duplicate-row semantics.
Changelog-Changed: wallet: indexed addresses(keyidx) and bulk-loaded address types when populating our_addresses, avoiding O(N^2) startup scans on nodes with many issued addresses.