Skip to content

KeychainTxOutIndex returns stale SPK cache entries in per-call ChangeSets #2217

Description

@ValuedMammal

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: 47556ab
  • OS+version:
  • Rust/Cargo version: rustc 1.94.1
  • Rust/Cargo target:

Which backend(s) are relevant (if any)?

  • Electrum
  • Esplora
  • Bitcoin Core RPC
  • None / not backend-related (e.g. bdk_chain, bdk_core)
  • Other (please specify): ____

Is this blocking production use?

  • Yes
  • No

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions