Skip to content

Remove redundant fields from WantsInputs event#1106

Merged
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:wants-inputs-primary-info
Sep 25, 2025
Merged

Remove redundant fields from WantsInputs event#1106
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:wants-inputs-primary-info

Conversation

@arminsabouri
Copy link
Collaborator

The primary information obtained from WantsOutputs is the outputs being commited. The session event should reflect new primary information only.

Related ticket: #1103

Pull Request Checklist

Please confirm the following before requesting review:

@arminsabouri arminsabouri added this to the payjoin-1.0 milestone Sep 22, 2025
@arminsabouri arminsabouri self-assigned this Sep 22, 2025
Comment on lines 147 to 148
#[cfg(feature = "v2")]
pub(crate) fn payjoin_proposal(&self) -> Psbt { self.payjoin_psbt.clone() }
Copy link
Contributor

@DanGould DanGould Sep 22, 2025

Choose a reason for hiding this comment

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

I see why you preferred the field to this in #1102 because the feature flag can be avoided. Though I'm not sure why you're using pub(crate) when pub(super) seems sufficient.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Pub(super) would work fine here.
Last push removes the feature flagged getter infavor if a pub(super) field.

The primary information obtained from `WantsOutputs` is the outputs
being commited. The session event should reflect new primary information
only.
@arminsabouri arminsabouri force-pushed the wants-inputs-primary-info branch from c54059c to 35ed7d7 Compare September 24, 2025 15:07
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 17981042076

Details

  • 15 of 15 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 84.54%

Totals Coverage Status
Change from base Build 17960911092: 0.02%
Covered Lines: 8591
Relevant Lines: 10162

💛 - Coveralls

Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

ACK 35ed7d7

Comment on lines +830 to +837
let mut payjoin_proposal = self.inner.payjoin_psbt.clone();
let outputs_len = outputs.len();
// Add the outputs that may have been replaced
payjoin_proposal.unsigned_tx.output = outputs;
payjoin_proposal.outputs = vec![Default::default(); outputs_len];

let mut inner = self.state.inner.commit_outputs();
inner.payjoin_psbt = payjoin_proposal;
Copy link
Contributor

@DanGould DanGould Sep 25, 2025

Choose a reason for hiding this comment

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

What happens with legacy pre-segwit outputs? I suppose there is never a case where you need bitcoin::psbt::Output because, well, they're outputs being spent to and all you need is the TxOut.script_pubkey to spend to them? perhaps a comment explaining why the Default payjoin_proposal.outputs are appropriate would clarify.

This is making me think the SessionEvent variants might need renames. This WantsInputs event does produce a WantsInputs type but it's really an event which does ~CommitOutputs, since it encapsulates those outputs. I think that tripped me up on first read.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is making me think the SessionEvent variants might need renames.

I agree, event variants should describe "what event happened" instead of "what this event produces". We already do this for the Created and Closed variants. Could be something like:

{
//...
    IdentifiedReceiverOutputs(Vec<usize>),
    CommittedOutputs(Vec<bitcoin::TxOut>),
    CommittedInputs(Vec<InputPair>),
//...
}

and so on for the other variants.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer these get named in imperative mood over past tense but otherwise agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose there is never a case where you need bitcoin::psbt::Output because, well, they're outputs being spent to and all you need is the TxOut.script_pubkey to spend to them?

Correct. I actually copied this code from the common abstraction

        // Update the payjoin PSBT outputs
        payjoin_psbt.outputs = vec![Default::default(); outputs.len()];
        payjoin_psbt.unsigned_tx.output = outputs;

// Update the payjoin PSBT outputs

The PSBT outputs are being set to default regardless if the receiver replaces their outputs.
That may be an issue for some implementations that expect BIP32 paths to be present in order to validate change address. But in those cases the implementation could mutate the PSBT pre-signing.

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.

utACK 35ed7d7

@arminsabouri arminsabouri merged commit eabea2f into payjoin:master Sep 25, 2025
10 checks passed
@arminsabouri arminsabouri deleted the wants-inputs-primary-info branch September 25, 2025 18:25
@spacebear21 spacebear21 mentioned this pull request Sep 26, 2025
2 tasks
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