Skip to content

Input weight prediction helpers for nested P2WPKH - #3443

Merged
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
spacebear21:np2wpkh-input-weight-predictions
Oct 9, 2024
Merged

apoelstra merged 2 commits into
rust-bitcoin:masterfrom
spacebear21:np2wpkh-input-weight-predictions

Conversation

@spacebear21

Copy link
Copy Markdown
Contributor

Following up on #630 (comment).

I amended the docstring on InputWeightPrediction::weight() to clarify that it only returns the signature weight. I'm not sure what the rationale was for only returning partial input weight, and if there are any arguments against something like InputWeightPrediction::total_weight() which returns self.weight() + Weight::from_non_witness_data_size(32 + 4 + 4) (and maybe deprecate weight() eventually to prevent misuse).

Add helpers for input weight predictions corresponding to P2WPKH nested
in a P2SH output (nested segwit).
Clarify that the returned weight doesn't include txid, index, or
sequence weights.
@github-actions github-actions Bot added the C-bitcoin PRs modifying the bitcoin crate label Oct 3, 2024
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 11171505097

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 82.585%

Totals Coverage Status
Change from base Build 11162793049: 0.006%
Covered Lines: 19031
Relevant Lines: 23044

💛 - Coveralls

/// Tallies the total weight added to a transaction by an input with this weight prediction,
/// not counting potential witness flag bytes or the witness count varint.
/// Computes the **signature weight** added to a transaction by an input with this weight prediction,
/// not counting the prevout (txid, index), sequence, potential witness flag bytes or the witness count varint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like signature_weight() would be a better name for this method eventually.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I suggested deprecating in the top comment but if it'll stay exposed it would be good to change the name to avoid confusion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer witness_weight or something. Unsure. signature_weight may suggest to some users that it's specifically about EC signatures.

In any case, this PR looks good as-is.

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK aa1fd5f successfully ran local tests

@tcharding tcharding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK aa1fd5f

@apoelstra
apoelstra merged commit 78bcca7 into rust-bitcoin:master Oct 9, 2024
@spacebear21
spacebear21 deleted the np2wpkh-input-weight-predictions branch October 9, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants