Separate out fee application into own typestate#881
Separate out fee application into own typestate#881spacebear21 merged 3 commits intopayjoin:masterfrom
Conversation
58255be to
9861a58
Compare
Pull Request Test Coverage Report for Build 16326869862Details
💛 - Coveralls |
|
FWIW I wanted to include an example of how we are using this in the Liana integration: payjoin/liana#8 |
spacebear21
left a comment
There was a problem hiding this comment.
concept ACK, but the FFI parameter names should keep the fee rate unit, and the new typestate/method need docstrings (these should also be applied to the FFI layer).
I second Dan's suggestion in #870 to rename ProvisionalProposal to WantsSigner as well, but this can be done in a follow-up after we evaluate whether it should allow for multiple individual signature operations + a commitment method. I don't think that should block this PR since separating fee application solves a separate known problem and makes for a cleaner state machine regardless.
payjoin/src/core/receive/v1/mod.rs
Outdated
| output_contribution_weight | ||
| } | ||
|
|
||
| pub fn commit_fee_range( |
There was a problem hiding this comment.
The "commit" naming pattern refers to something that was contributed/applied to the existing typestate (e.g. contributed inputs/outputs) and "committing" it moves to the next typestate. Maybe apply_fee_range, with an explanatory docstring that it only applies a fee if the receiver contributions exceed the sender's additional fee, to match min_fee_rate, and not exceeding max_effective_fee_rate.
There was a problem hiding this comment.
TBH the docstring from the inner apply_fee should probably just live on this method, since it's public whereas apply_fee is private.
payjoin/src/core/receive/v1/mod.rs
Outdated
| let mut finalized_psbt = | ||
| wallet_process_psbt(&self.payjoin_psbt).map_err(ReplyableError::Implementation)?; |
There was a problem hiding this comment.
Was there a reason to move this to happen before the sender signatures get cleared? IIRC it had to happen in this order before to fix a bug in bitcoin-cli, though this specific bug has been fixed since. See #241
There was a problem hiding this comment.
Not particularly. If it was moved that is my mistake.
payjoin-ffi/src/receive/uni.rs
Outdated
| min_fee_rate: Option<u64>, | ||
| max_effective_fee_rate: Option<u64>, |
There was a problem hiding this comment.
Since the strong FeeRate type is lost in uniffi translation, we should specify the unit in the parameter names (e.g. min_fee_rate_sat_per_vb).
There was a problem hiding this comment.
yes I had the same thought.
There was a problem hiding this comment.
Fixed in the first commit
payjoin-ffi/src/receive/uni.rs
Outdated
| } | ||
|
|
||
| /// Psbt With fee contributions applied | ||
| pub fn psbt_with_fee_contributions(&self) -> Option<Arc<crate::Psbt>> { |
There was a problem hiding this comment.
What value does it provide to make this specific PSBT state accessible downstream? And is psbt_with_contributed_inputs still useful at all?
There was a problem hiding this comment.
And is psbt_with_contributed_inputs still useful at all?
No I would recommend we either deprecate it or just remove it.
What value does it provide to make this specific PSBT state accessible downstream?
This is useful when the singer is not the entity that is progressing the state machine. In these wallet architectures the psbt that is "ready to be signed" will be made accessible when its requested. For a more concrete example please reference payjoin/liana#8. In this example, Lianad (backend service) will save the psbt with fee's applies in their psbt table. When the signer navigates to the their psbt page the backend will pull from this table and the user can sign.
There was a problem hiding this comment.
psbt_with_contributed_inputs is now removed
There was a problem hiding this comment.
It might carry more meaning to name this psbt_ready_for_signing?
9861a58 to
7776fa1
Compare
I don't understand the rationale for this naming change or the new methods. rust-payjoin should less involved in signing operations and by extension application business logic. All rust-payjoin cares about from |
spacebear21
left a comment
There was a problem hiding this comment.
utACK with a couple of naming comments that imo would be best addressed in this PR.
payjoin-ffi/src/receive/uni.rs
Outdated
| } | ||
|
|
||
| /// Psbt With fee contributions applied | ||
| pub fn psbt_with_fee_contributions(&self) -> Option<Arc<crate::Psbt>> { |
There was a problem hiding this comment.
It might carry more meaning to name this psbt_ready_for_signing?
| @@ -819,21 +843,19 @@ impl ProvisionalProposal { | |||
| /// | |||
| /// Errors if the final effective fee rate exceeds `max_effective_fee_rate`. | |||
| pub fn finalize_proposal( | |||
There was a problem hiding this comment.
I just noticed this docstring needs to be updated too since all the fee stuff is now handled in WantsFeeRange.
7776fa1 to
5eef949
Compare
This commit refactors fee application on the receiver side by moving it out of the `ProvisionalProposal` typestate into a dedicated `WantsFeeRange` typestate, as outlined in payjoin#870 It also removes the `receiver_inputs` field from `ProvisionalProposal`, since it was solely used during fee computation and is no longer needed in this state.
This method was originally exposed to provide signers access to the PSBT they are expected to sign. However, that PSBT excludes the receiver's fee contributions. It has therefore been replaced by `psbt_with_fee_contributions`.
5eef949 to
3dcea20
Compare
This commit refactors fee application on the receiver side by moving
it out of the
ProvisionalProposaltypestate into a dedicatedWantsFeeRangetypestate, as outlined in #870It also removes the
receiver_inputsfield fromProvisionalProposal, since it was solely used during fee computationand is no longer needed in this state.