wallet: Cache the Address max indices in memory to reduce DB traffic#9340
Open
cdecker wants to merge 3 commits into
Open
wallet: Cache the Address max indices in memory to reduce DB traffic#9340cdecker wants to merge 3 commits into
cdecker wants to merge 3 commits into
Conversation
cdecker
force-pushed
the
2026w28-blockscan-addr-index
branch
from
July 21, 2026 14:17
536de89 to
52ef4dc
Compare
We were looking up the index for the addresses to scan, twice, for every single output, for every single TX for every block. No wonder that was being slow. Changelog-Fixed: wallet: Addressed a performance regression during blockchain scans
cdecker
force-pushed
the
2026w28-blockscan-addr-index
branch
from
July 21, 2026 14:26
52ef4dc to
8f65d8e
Compare
The write-through cache added for the address max_index was only kept in sync in wallet_can_spend(). wallet_get_newindex() still read and wrote the bip32_max_index/bip86_max_index db vars directly, leaving the in-memory cache stale after every newaddr. Since listaddresses and the rescan window now read from that cache, freshly issued addresses were invisible until the next restart (and wallet_can_spend could even write a stale, lower value back to the db). Route all reads and writes through wallet_max_addr_index() and wallet_set_max_addr_index() so the cache and the db never diverge. Changelog-None Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
While looking into a performance regression, first noticed in v25.12, @nepet and I found that we were fetching the BIP address max indices twice for each output x transaction x block, causing massive delays when working with a postgresql DB.