Skip to content

Conversation

evanlinjin
Copy link
Member

Description

This PR adds two new methods to CanonicalView to support RBF (Replace-By-Fee) transaction workflows:

  • extract_subgraph(): Extracts a transaction and all its descendants from the canonical view
  • roots(): Returns transactions that have no parent transactions in the view

These methods are essential for RBF support as they allow extracting specific transaction chains that can be replaced.

Note: This PR depends on #2029 which introduces the CanonicalView struct.

Notes to the reviewers

The extract_subgraph() method removes the extracted transactions from the original view and returns them in a new CanonicalView. This is useful for isolating transaction chains that need to be replaced in RBF scenarios.

Changelog notice

Added

  • CanonicalView::extract_subgraph() method to extract transactions with all their descendants
  • CanonicalView::roots() method to find root transactions without parents in the view

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

🤖 Generated with Claude Code

evanlinjin and others added 12 commits September 17, 2025 23:46
- Add `CanonicalView` structure with canonical transaction methods
- Move methods from `TxGraph` to `CanonicalView` (txs, filter_outpoints, balance, etc.)
- Add canonical view methods to `IndexedTxGraph`
- Update all tests and examples to use new API
- Optimize examples to reuse canonical view instances

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Add min_confirmations parameter to control confirmation depth requirements:
- min_confirmations = 0: Include all confirmed transactions (same as 1)
- min_confirmations = 1: Standard behavior - require at least 1 confirmation
- min_confirmations = 6: High security - require at least 6 confirmations

Transactions with fewer than min_confirmations are treated as trusted/untrusted
pending based on the trust_predicate. This restores the minimum confirmation
functionality that was available in the old TxGraph::balance doctest but with
a more intuitive API since CanonicalView has the tip internally.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Add test file `tests/test_canonical_view.rs` with three comprehensive test cases:

1. `test_min_confirmations_parameter`: Tests basic min_confirmations functionality
   - Verifies min_confirmations = 0 and 1 behave identically
   - Tests edge case where transaction has exactly required confirmations
   - Tests case where transaction has insufficient confirmations

2. `test_min_confirmations_with_untrusted_tx`: Tests trust predicate interaction
   - Verifies insufficient confirmations + untrusted predicate = untrusted_pending
   - Ensures trust predicate is respected when confirmations are insufficient

3. `test_min_confirmations_multiple_transactions`: Tests complex scenarios
   - Multiple transactions with different confirmation counts
   - Verifies correct categorization based on min_confirmations threshold
   - Tests both min_confirmations = 5 and min_confirmations = 10 scenarios

These tests validate that the min_confirmations parameter correctly controls
when transactions are treated as confirmed vs trusted/untrusted pending.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
BREAKING: Remove `CanonicalTx` as it's no longer needed.
Add comprehensive docs for CanonicalView module, structs, and methods.
Fix all doctests to compile and pass with proper imports.
Also update submodule-level docs for `tx_graph`'s Canonicalization
section.
BREAKING CHANGE: `CanonicalView::balance()` now takes `additional_confirmations`
instead of `min_confirmations`. The new parameter represents confirmations
beyond the first (e.g., 5 means 6 total confirmations required).

- Rename `why` to `reason` in CanonicalView for clarity
- Update docs to clarify topological-spending order
- Simplify docs by removing redundant conflict mentions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
BREAKING CHANGE: The trust_predicate parameter in CanonicalView::balance()
now takes &FullTxOut<A> instead of ScriptBuf as its second argument.

This provides more context to the predicate function.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
These methods are intended to help implement RBF logic.
Test extraction of transaction subgraphs with descendants, verifying
that spends and txs fields maintain consistency.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@evanlinjin evanlinjin self-assigned this Sep 19, 2025
@oleonardolima oleonardolima added the api A breaking API change label Sep 21, 2025
@oleonardolima oleonardolima moved this to Needs Review in BDK Chain Sep 21, 2025
@oleonardolima oleonardolima added this to the Wallet 3.0.0 milestone Sep 21, 2025
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

cACK f081300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

2 participants