Skip to content

Remove unneeded PSBT fields when extracting request#907

Merged
arminsabouri merged 2 commits intopayjoin:masterfrom
arminsabouri:restore-utxo-bug
Jul 29, 2025
Merged

Remove unneeded PSBT fields when extracting request#907
arminsabouri merged 2 commits intopayjoin:masterfrom
arminsabouri:restore-utxo-bug

Conversation

@arminsabouri
Copy link
Collaborator

@arminsabouri arminsabouri commented Jul 29, 2025

PsbtContextBuilder stores a Psbt with unneeded fields removed. Our API later attempts to restore some of these fields after we process the response from the receiver.

fn restore_original_utxos(&self, proposal: &mut Psbt) -> InternalResult<()> {

However, since the original psbt was already stripped of "unneeded" fields there is nothing to restore. This commit removes the extranous PSBT fields when we are extracting the POST request but leaves the fields in the original_psbt untouched.

Related ticket: #906

`PsbtContextBuilder` stores a Psbt with [unneeded fields
removed](https://github.com/payjoin/rust-payjoin/blob/57ec41b1ebfd325ded9fc216096ec3930ed40b4b/payjoin/src/core/send/mod.rs#L524).
Our API later attempts to restore _some_ of these fields after we
process the response from the receiver.
https://github.com/payjoin/rust-payjoin/blob/57ec41b1ebfd325ded9fc216096ec3930ed40b4b/payjoin/src/core/send/mod.rs#L411

However, since the original psbt was already stripped of "unneeded"
fields there is nothing to restore. This commit removes the extranous
PSBT fields when we are extracting the POST request.
@arminsabouri arminsabouri requested a review from spacebear21 July 29, 2025 17:11
@coveralls
Copy link
Collaborator

coveralls commented Jul 29, 2025

Pull Request Test Coverage Report for Build 16604779713

Details

  • 35 of 36 (97.22%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 85.921%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/send/mod.rs 35 36 97.22%
Totals Coverage Status
Change from base Build 16601759995: 0.05%
Covered Lines: 7940
Relevant Lines: 9241

💛 - Coveralls

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

tACK, confirmed that the newly added test_restore_original_utxos fails on master.

It would be great to add another test validating the clearing behavior in sender requests (see comment below) in this PR if it's not a big lift.

);
let body = psbt_ctx.original_psbt.to_string().as_bytes().to_vec();
let mut sanitized_psbt = psbt_ctx.original_psbt.clone();
clear_unneeded_fields(&mut sanitized_psbt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to actually validate this behavior in a test, I can comment out this line and all tests are still green despite it violating the BIP78 spec. We could augment test_clear_unneeded_fields so it checks the request body instead of just validating the function internals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or we could augment the new test that I have introduced. Eitherway happy to make this change

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could add some assertions in our v1 integration test for the most minimal testing.

let (req, ctx) = SenderBuilder::new(psbt, uri)
.build_with_additional_fee(Amount::from_sat(10000), None, FeeRate::ZERO, false)?
.create_v1_post_request();
let headers = HeaderMock::new(&req.body, req.content_type);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually what you suggested may be easier

Copy link
Collaborator

@benalleng benalleng Jul 29, 2025

Choose a reason for hiding this comment

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

I just realized that might not be the right create_v1_post_request method? ... they're all public scratch that it looks good I got all my wires crossed

Add some coverage to the higher level function where we actually clear
the unneeded fields.
@arminsabouri arminsabouri requested a review from spacebear21 July 29, 2025 18:50
@benalleng
Copy link
Collaborator

Ack on a276767 makes sense to just call create_v1_post_request in that unit test

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

reACK pending passing checks

@arminsabouri arminsabouri merged commit 7040cca into payjoin:master Jul 29, 2025
9 checks passed
@arminsabouri arminsabouri deleted the restore-utxo-bug branch July 29, 2025 19:11
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.

4 participants