feat(esplora): add persistent tx cache to avoid re-fetching known txs - #2254
feat(esplora): add persistent tx cache to avoid re-fetching known txs#2254GuTS805 wants to merge 1 commit into
Conversation
Adds BdkEsploraClient wrapper (mirroring BdkElectrumClient) with an internal tx_cache and populate_tx_cache(). Cached txids now only trigger a lightweight get_tx_status() call instead of re-downloading the full transaction body via get_tx_info(). Fixes bitcoindevkit#2250
|
Thanks for taking this on, and for the detailed writeup in both #2250 and here. Unfortunately I don't think this approach works, and I'd like to explain why in enough detail to be useful — the premise in #2250 is the part that needs revisiting, so this isn't really a matter of fixing up the patch. The cache can't save what Esplora already sent
Esplora has no equivalent second call. That shows up directly in the diff: the cache is written in
No round trips are saved anywhere. And the remaining bandwidth win mostly doesn't materialize either. Worth noting the new test uses a
|
|
Follow-up on the TODO: opened #2260 to remove it. |
Adds
BdkEsploraClientwrapper (mirroringBdkElectrumClient) with an internaltx_cacheandpopulate_tx_cache(). Cached txids now only trigger a lightweightget_tx_status()call instead of re-downloading the full transaction body viaget_tx_info().Fixes #2250
Description
bdk_esplorare-downloaded the full transaction body (get_tx_info) for every tracked txid on every sync, even when the tx was already fetched in a previous sync and only its confirmation status could have changed.bdk_electrumavoids this viaBdkElectrumClient's persistenttx_cache;bdk_esplorahad no equivalent (see theTODOinasync_ext.rs:495/blocking_ext.rs:454).This PR adds
BdkEsploraClient<C>, a wrapper aroundesplora_client::BlockingClient/AsyncClientthat maintains a persistent in-memorytx_cache, mirroringBdkElectrumClient's pattern:BdkEsploraClient::new(client)andpopulate_tx_cache()to pre-seed the cache from an existingTxGraph.BdkEsploraClient::full_scan/syncinherent methods that use the cache.get_tx_status()call is made instead of re-downloading the full transaction viaget_tx_info(). Only genuinely new/unseen txids trigger a full fetch.The existing
EsploraExt/EsploraAsyncExttraits on the rawesplora_client::BlockingClient/AsyncClientare unchanged, so this is fully backward compatible — the cache is opt-in via the new wrapper.Notes to the reviewers
Couldn't run the
bdk_testenv-based integration tests locally (Windows) —electrsd's build script requiresstd::os::unix, which doesn't exist on this platform. Confirmed this is a pre-existing limitation unrelated to this change (reproduces identically onmaster). Verified withcargo check --all-featuresandcargo clippyinstead; CI should run the integration tests.Changelog notice
Added:
bdk_esplora: introduceBdkEsploraClientwrapper with a persistent transaction cache to avoid re-fetching already-downloaded transactions on sync.Checklists
All Submissions:
New Features:
Bugfixes: