Skip to content

fix!: exact weight pricing for grouped legacy inputs in mixed txs - #63

Open
evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:fix/legacy-pricing-mix
Open

fix!: exact weight pricing for grouped legacy inputs in mixed txs#63
evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:fix/legacy-pricing-mix

Conversation

@evanlinjin

@evanlinjin evanlinjin commented Aug 12, 2026

Copy link
Copy Markdown
Member

Fixes CoinSelector::input_weight undercounting candidates that group multiple legacy inputs in a segwit transaction (where each legacy input serializes a 1 WU empty witness).

Previously, CoinSelector added 1 WU per non-segwit candidate if the transaction was segwit. This meant a candidate representing a group of N legacy inputs came out N-1 WU short.

This PR:

  1. Replaces Candidate fields input_count and is_segwit with segwit_count and legacy_count.
  2. Allows a single Candidate to mix legacy and segwit inputs and still be priced exactly.
  3. Replaces Candidate::new with explicit Candidate::new_segwit and Candidate::new_legacy constructors to clarify that satisfaction_weight is the additional weight required beyond TXIN_BASE_WEIGHT (which already accounts for a 1-byte scriptSigLen).

Note: This replaces #62 and #61. #61 introduced empty_witness_refund which was problematic. #62 introduced an invariant (no mixing legacy and segwit inputs in a candidate) that is problematic for downstream crates.

…y_count

Fixes CoinSelector::input_weight undercounting candidates that group multiple legacy inputs in a segwit transaction (where each legacy input serializes a 1 WU empty witness). Tracking segwit and legacy input counts separately also allows a single Candidate to mix legacy and segwit inputs.
…legacy

Replaces the boolean is_segwit parameter in Candidate::new with explicit new_segwit and new_legacy constructors. Clarifies in doc comments that satisfaction_weight is the additional weight required beyond TXIN_BASE_WEIGHT (which already accounts for a 1-byte scriptSigLen).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant