bitcoindevkit / bitcoindevkit/bdk
KeychainTxOutIndex returns stale SPK cache entries in per-call ChangeSets
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 483
- Avg merge
- 20d 3h
- Merged PRs (30d)
- 3
Description
**Describe the bug**
KeychainTxOutIndex stages newly derived script pubkeys in an internal staging buffer and the flushes that buffer into the next returned ChangeSet. As a result, per-call ChangeSet results aren't operation-local: a call such as `reveal_next_spk` could return SPK cache entries derived by earlier operations (for example descriptor insertion / index store replenishment), which is surprising for downstream consumers that persist deltas per API call.
**To Reproduce**
1. Create KeychainTxOutIndex with persist_spks = true and a nonzero lookahead.
2. Insert a descriptor.
3. Call reveal_next_spk once.
4. Inspect the returned ChangeSet.spk_cache.
**Expected behavior**
Each mutating API call should return a ChangeSet containing only the cache delta created by that call. For example, reveal_next_spk should return only newly derived scripts from that reveal step, not previously staged scripts from unrelated prior calls.
**Build environment**
- BDK tag/commit: 47556ab7
- OS+version:
- Rust/Cargo version: rustc 1.94.1
- Rust/Cargo target:
**Which backend(s) are relevant (if any)?**
- [ ] Electrum
- [ ] Esplora
- [ ] Bitcoin Core RPC
- [x] None / not backend-related (e.g. bdk_chain, bdk_core)
- [ ] Other (please specify): `____`
**Is this blocking production use?**
- [ ] Yes
- [x] No
Contributor guide
Assessment
This issue has not been assessed yet.