Skip to content

wallet: Cache the Address max indices in memory to reduce DB traffic#9340

Open
cdecker wants to merge 3 commits into
masterfrom
2026w28-blockscan-addr-index
Open

wallet: Cache the Address max indices in memory to reduce DB traffic#9340
cdecker wants to merge 3 commits into
masterfrom
2026w28-blockscan-addr-index

Conversation

@cdecker

@cdecker cdecker commented Jul 21, 2026

Copy link
Copy Markdown
Member

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.

@cdecker
cdecker force-pushed the 2026w28-blockscan-addr-index branch from 536de89 to 52ef4dc Compare July 21, 2026 14:17
@cdecker cdecker changed the title 2026w28 blockscan addr index wallet: Cache the Address max indices in memory to reduce DB traffic Jul 21, 2026
cdecker added 2 commits July 21, 2026 16:26
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
cdecker force-pushed the 2026w28-blockscan-addr-index branch from 52ef4dc to 8f65d8e Compare July 21, 2026 14:26
nepet
nepet previously approved these changes Jul 21, 2026

@nepet nepet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this patch!
ack 8f65d8e

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>
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