Skip to content

Dedup utxos locked method#1568

Open
arminsabouri wants to merge 2 commits into
payjoin:masterfrom
arminsabouri:dedup-utxos-locked
Open

Dedup utxos locked method#1568
arminsabouri wants to merge 2 commits into
payjoin:masterfrom
arminsabouri:dedup-utxos-locked

Conversation

@arminsabouri
Copy link
Copy Markdown
Collaborator

Resolving this todo comment: TODO: de-duplicate this with the v1 implementation by moving utxos_to_be_locked to PsbtContext.
The bigger change is to filter out the sender inputs. If the prupose of this method is to inform the reciever what inputs they have to mark as "locked".

Not a fan of cloning the original PSBT. The only thing we need is sender input indecies.
In general, PsbtContext only needs a vec<usize> for the sender inputs (for other methods: psbt_to_sign). The only place where we use the original tx is the in the v2 monitor typestate. This is where something like #1197 would be useful.

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented May 19, 2026

Coverage Report for CI Build 26119539926

Coverage increased (+0.05%) to 85.349%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (27 of 28 lines covered, 96.43%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
payjoin/src/core/receive/v2/mod.rs 1 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
payjoin/src/core/receive/v2/mod.rs 1 91.46%

Coverage Stats

Coverage Status
Relevant Lines: 13699
Covered Lines: 11692
Line Coverage: 85.35%
Coverage Strength: 394.97 hits per line

💛 - Coveralls

Comment thread payjoin/src/core/receive/mod.rs Outdated
The verbage of this function suggests that this function 
returns the reciever's utxos to be locked. This comits moves 
this function to `PsbtContext` where we know the sender's inputs
and can filter them out.
This is not a general comment describing the code 
but something to be potentially done in the future.
self,
wallet_process_psbt: impl Fn(&Psbt) -> Result<Psbt, ImplementationError>,
) -> Result<PayjoinProposal, Error> {
let original_psbt = self.psbt_context.original_psbt.clone();
Copy link
Copy Markdown
Collaborator

@xstoicunicornx xstoicunicornx May 19, 2026

Choose a reason for hiding this comment

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

So I think you can avoid this clone() by:

  • updating PsbtContext::finalize_proposal() to not consume self
  • updating PsbtContext::prepare_psbt() to not consume self
  • move this assignment below let finalized_psbt = ... assignment

@DanGould
Copy link
Copy Markdown
Contributor

canmt the function be completely removed because the functions that create / modify PSBTs already know what their utxos to lock are? is this fn used in any integration whatsoever?

@xstoicunicornx
Copy link
Copy Markdown
Collaborator

xstoicunicornx commented May 20, 2026

cant the function be completely removed because the functions that create / modify PSBTs already know what their utxos to lock are? is this fn used in any integration whatsoever?

Yeah I guess so but might force callers to keep separate state of what inputs were contributed until the time of signing no? Or I guess looking up what utxos are signed on the proposal should be easy enough.

@DanGould
Copy link
Copy Markdown
Contributor

might force callers to keep separate state of what inputs were contributed until the time of signing

Is this being done anywhere? Not that I know of. I could see it being a possibility for exchanges/services w/ async signing tho

Copy link
Copy Markdown
Collaborator

@xstoicunicornx xstoicunicornx left a comment

Choose a reason for hiding this comment

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

utACK 301d280

Reviewed and tested the changes. I think it makes sense to make a resuable utxos_to_be_locked() method on PsbtContext that both v1 and v2 can leverage. Also think its a good method to provide to callers in the PayjoinProposal typestate. I don't actually feel strongly about the clone related comment earlier (but still think maybe worth doing?).

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