rust-payjoin icon indicating copy to clipboard operation
rust-payjoin copied to clipboard

Use native rust-bitcoin methods for weight calculations

Open spacebear21 opened this issue 1 year ago • 2 comments

See https://github.com/payjoin/rust-payjoin/issues/353

This deletes the custom weight.rs traits and input_type.rs helpers in favor of out-of-the-box rust-bitcoin methods. It also removes the unused output_type.rs.

A question that may be relevant to this PR: do we want to commit to allowing mixed input types (despite it being a violation of the BIP78 spec) to better enable batching use cases? Maybe we could introduce a allow_mixed_input_types parameter that can be set by the sender and defaults to false if not set?

spacebear21 avatar Sep 26 '24 20:09 spacebear21

pretty massive delete! eager to follow

DanGould avatar Sep 26 '24 20:09 DanGould

I'm partial to allow mixed input types, and that opinion appears to be consensus. In addition, allow by default is more permissive and should have fewer failed attempts, I'm not sure I'd even want to expose the option unless it were strictly necessary for a downstream usecase if the logic weren't already in the codebase for v1.

DanGould avatar Sep 26 '24 20:09 DanGould

@DanGould Summary of changes since your last review:

  • Fixed the try_fold issue you brought up.
  • Removed the input_type and sequence fields from the ContextV1 and RequestContext structs, as they can be computed from the original psbt.
  • Added a unit test for input weight calculations. I used payjoin-cli with RUST_LOG=trace to generate and obtain the original and payjoin PSBT values, and a new bitcoin-cli wallet for each address type.

spacebear21 avatar Oct 08 '24 02:10 spacebear21

  • Try_fold fix looks good
  • input_type and sequence removal also looking good

I haven't checked the PSBT values in the known-weight tests, so I'm on that tomorrow. I think that's the last substantive check to make.

DanGould avatar Oct 08 '24 05:10 DanGould

Thanks - fixed the clippy warnings and test name.

spacebear21 avatar Oct 08 '24 22:10 spacebear21