Skip to content

Conversation

@evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Mar 28, 2025

Fixes #1898

Description

When we initially created the canonicalization algorithm, we didn't expect callers to insert invalid transactions into the graph. However, user error happens and we should handle it correctly.

Before this PR, when inserting transactions that double-spend themselves (where two or more different inputs of the transactions conflict), the canonicalization result will have inconsistencies.

Notes to the reviewers

Logic changes are all contained in CanonicalIter::mark_canonical. mark_canonical will detect whether the tx being passed in double spends itself. If so, we abort and undo all changes made so far.

There is a slight <2% degradation in performance with this change (except in two cases where there is a performance improvement of ~10%).

bench.txt

Changelog notice

  • Fix canonicalization mess-up when transactions that conflict with itself are inserted.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

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

@notmandatory notmandatory moved this to In Progress in BDK Chain Mar 31, 2025
@evanlinjin evanlinjin force-pushed the canonicalization_improvements branch from ac28f70 to 9f73527 Compare April 2, 2025 11:46
@evanlinjin evanlinjin force-pushed the canonicalization_improvements branch 3 times, most recently from 3e7c702 to 133f09c Compare April 17, 2025 04:58
Detect self-double-spends in `CanonicalIter::mark_canonical`. Disregard
the tx that self-double-spends and all it's attached meta data (such as
timestamps and anchors).

Add new test cases on `test_tx_conflict_handling` for transactions that
self-double-spend.
@evanlinjin evanlinjin force-pushed the canonicalization_improvements branch from 133f09c to 370497c Compare April 17, 2025 05:04
@evanlinjin evanlinjin marked this pull request as ready for review April 17, 2025 05:16
@evanlinjin evanlinjin moved this from In Progress to Needs Review in BDK Chain Apr 17, 2025
Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 370497c

Copy link
Contributor

@LagginTimes LagginTimes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 370497c

@notmandatory notmandatory added this to the 1.3.0 milestone Apr 22, 2025
@evanlinjin evanlinjin merged commit 4fe121e into bitcoindevkit:master Apr 23, 2025
17 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Chain Apr 23, 2025
@ValuedMammal ValuedMammal mentioned this pull request Apr 30, 2025
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

panic (assertion) in try_filter_chain_txouts

4 participants