fix!: exact weight pricing for grouped legacy inputs in mixed txs - #63
Open
evanlinjin wants to merge 2 commits into
Open
fix!: exact weight pricing for grouped legacy inputs in mixed txs#63evanlinjin wants to merge 2 commits into
evanlinjin wants to merge 2 commits into
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
CoinSelector::input_weightundercounting candidates that group multiple legacy inputs in a segwit transaction (where each legacy input serializes a 1 WU empty witness).Previously,
CoinSelectoradded 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:
Candidatefieldsinput_countandis_segwitwithsegwit_countandlegacy_count.Candidateto mix legacy and segwit inputs and still be priced exactly.Candidate::newwith explicitCandidate::new_segwitandCandidate::new_legacyconstructors to clarify thatsatisfaction_weightis the additional weight required beyondTXIN_BASE_WEIGHT(which already accounts for a 1-bytescriptSigLen).Note: This replaces #62 and #61. #61 introduced
empty_witness_refundwhich was problematic. #62 introduced an invariant (no mixing legacy and segwit inputs in a candidate) that is problematic for downstream crates.