Skip to content

fix(chain)!: handle descriptor SPK collisions - #2327

Open
busayo-OD wants to merge 2 commits into
bitcoindevkit:masterfrom
busayo-OD:fix/descriptor-spk-collision
Open

busayo-OD wants to merge 2 commits into
bitcoindevkit:masterfrom
busayo-OD:fix/descriptor-spk-collision

Conversation

@busayo-OD

Copy link
Copy Markdown

Description

Fixes #2277.

KeychainTxOutIndex does not currently handle collisions when a descriptor derives an SPK that is already owned by another keychain.

This PR allows wildcard descriptors to skip already-owned SPKs when revealing new scripts and continue to the next available SPK. Non-wildcard descriptors are rejected when their only SPK is already claimed, returning the new NoDerivableSpk error variant.

Notes to the reviewers

  • The rejected non-wildcard descriptor is not registered and its state is rolled back.
  • Collided SPKs remain associated with their original keychains and are not recorded as revealed for the wildcard keychain.
  • Regression tests cover non-wildcard descriptor rejection, both insertion orders, and consecutive SPK collisions.
  • The new NoDerivableSpk error needs to be handled in bdk_wallet by mapping it to DescriptorOutputCollision.

Changelog notice

  • Add NoDerivableSpk to InsertDescriptorError.
  • Handle SPK collisions when revealing wildcard descriptor outputs.
  • Reject non-wildcard descriptors whose only SPK is already claimed.

Checklists

All Submissions:

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Allow wildcard descriptors to skip SPKs already owned by another keychain
when revealing new SPKs.

Reject non-wildcard descriptors whose only SPK is already claimed by
another keychain with a new `NoDerivableSpk` error variant.
Add regression tests for non-wildcard descriptor rejection, both descriptor
insertion orders, wildcard collision handling, and consecutive SPK collisions
during SPK revelation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

KeychainTxOutIndex panics on overlapping descriptors (non-index-0 spk)

2 participants