Skip to content

feat(electrum): add ElectrumClient.populate_tx_cache - #1150

Merged
thunderbiscuit merged 1 commit into
bitcoindevkit:masterfrom
Birch-Wallet:electrum-populate-tx-cache
Oct 29, 2026
Merged

thunderbiscuit merged 1 commit into
bitcoindevkit:masterfrom
Birch-Wallet:electrum-populate-tx-cache

Conversation

@newtonick

@newtonick newtonick commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

bdk_electrum has populate_tx_cache and I wanted to expose it for my iOS multisig wallet (Birch) that uses Electrum. This PR exposes it on ElectrumClient, so the wallet's transactions can be loaded into the cache before the scan and the scan only downloads new ones. This improves the speed of syncing dramatically. In Swift it looks like this:

let client = try ElectrumClient(url: url)
client.populateTxCache(txs: wallet.transactions().map(\.transaction))
let update = try client.fullScan(request: wallet.startFullScan().build(), stopGap: 20, batchSize: 50, fetchPrevTxouts: false)

I benchmarked a full scan on a new client against a Fulcrum server on testnet4 (stop gap 20, batch size 50, median of 5 runs, in Rust with bdk_wallet 3.2.0 and bdk_electrum 0.24.1):

Wallet No cache populate_tx_cache
622 transactions 43.0 s 2.1 s
10 transactions 1.35 s 0.66 s

I made the same change on top of 3.1.1, built bdk-swift with it (release) and tested it with my iOS wallet without any issues.

Notes to the reviewers

I kept the same name as bdk_electrum and had it take a list of transactions instead of a Wallet, since the ADRs in docs/adr say to keep the Rust names and only wrap when needed. The transactions can come from Wallet.transactions.

Documentation

Changelog

I don't have permission to add labels. I think this should be changelog: added.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added exactly one changelog:* label
  • I've linked the relevant upstream docs or specs above

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Expose BdkElectrumClient::populate_tx_cache, which inserts transactions
into the client's transaction cache so that it will not re-fetch them.

A new ElectrumClient starts with an empty cache, so the first full_scan
or sync on it downloads every transaction the wallet already has, one
request each. Passing the wallet's transactions to populate_tx_cache
first means the scan only downloads new ones. On a testnet4 wallet with
622 transactions, a full scan on a new client against a Fulcrum server
went from 43.0 s to 2.1 s.
@newtonick
newtonick force-pushed the electrum-populate-tx-cache branch from b129210 to 9677671 Compare October 26, 2026 23:30
@newtonick
newtonick marked this pull request as ready for review October 26, 2026 23:35
@newtonick
newtonick requested a review from a team as a code owner October 26, 2026 23:35
@thunderbiscuit

thunderbiscuit commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Thanks for opening this! We've been hearing from multiple users now that sync speed and efficiency is paramount, and so I'm happy this API can help you out this way. Will review.

Note the other possible improvements coming in #1012 if you'd like to review/comment on this.

@thunderbiscuit thunderbiscuit added this to the 3.2.0 milestone Oct 27, 2026

@thunderbiscuit thunderbiscuit 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.

ACK 9677671.

This is great; thanks for sending me down that rabbit hole, I was not aware of this method on the client! I would have loved an Android test but I think you'd need to create a wallet, populate it, save to persistence, re-build it, etc. Maybe too involved here.

@thunderbiscuit
thunderbiscuit merged commit 9677671 into bitcoindevkit:master Oct 29, 2026
8 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in BDK-Bindings Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants