Skip to content

fix(chain): use maximum anchor confirmation height - #2345

Closed
kleonyuan wants to merge 1 commit into
bitcoindevkit:masterfrom
kleonyuan:master
Closed

kleonyuan wants to merge 1 commit into
bitcoindevkit:masterfrom
kleonyuan:master

Conversation

@kleonyuan

@kleonyuan kleonyuan commented Oct 5, 2026 •

Copy link
Copy Markdown

Description

Fixes #2344

TxGraph::insert_anchor() used the last anchor in the BTreeSet to determine the previous maximum confirmation height. Since Anchor::Ord prioritizes the anchor BlockId and does not order anchors by confirmation_height_upper_bound(), this could leave stale or duplicate entries in the highest confirmation height index.

CanonicalTask made the same ordering assumption when assigning a height to transactions whose anchors are not confirmed.

Compute the maximum confirmation height across all anchors in both places. Add regression coverage using a custom Anchor whose confirmation height upper bounds are not monotonic with its block heights.

Notes to the reviewers

The regression cases use anchors at block heights 100, 90, and 110 with confirmation upper bounds 10, 80, and 20, respectively.

Changelog notice

Fix highest confirmation height indexing and leftover transaction heights for custom anchors.

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

@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.87%. Comparing base (0790f04) to head (debb9dd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2345      +/-   ##
==========================================
+ Coverage   78.84%   78.87%   +0.03%     
==========================================
  Files          31       31              
  Lines        6060     6060              
  Branches      288      288              
==========================================
+ Hits         4778     4780       +2     
+ Misses       1203     1202       -1     
+ Partials       79       78       -1     
Flag Coverage Δ
rust 78.87% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

With Anchor::confirmation_height_upper_bound removed in bitcoindevkit#2299, the
original fix for bitcoindevkit#2344 is no longer needed. Use ConfirmationBlockTime
to cover the supported exact-block semantics instead.

Check height-index uniqueness and changeset reconstruction after
out-of-order, same-height fork, and duplicate anchor insertions. Also
check that leftover canonicalization uses the highest anchor block
height rather than confirmation timestamps or insertion order.

Signed-off-by: kleonyuan <kleonyuan@outlook.com>
@evanlinjin

Copy link
Copy Markdown
Member

Closing in favor of #2390. The ordering bug this fixed was already resolved by #2299, so the code change is no longer in this PR's diff after the rebase, though the title and changelog still describe it. #2390 keeps a smaller regression test for it. Thanks for the work on this, @kleonyuan.

@evanlinjin evanlinjin closed this Oct 18, 2026
@github-project-automation github-project-automation Bot moved this from Triage to Done in BDK Chain Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Anchor ordering can produce incorrect confirmation heights

2 participants