Skip check_payment in Receiver<Monitor> if the sender is using non-segwit address#1218
Conversation
7117416 to
4c1789e
Compare
Pull Request Test Coverage Report for Build 20173359100Details
💛 - Coveralls |
arminsabouri
left a comment
There was a problem hiding this comment.
ConceptAck. This fixes the immediate bug in our monitoring type state.
I am assuming #1211 shold probably preceed this PR?
Yeah. Going to add new test scenarios for non-SegWit to this PR once the integration test changes are merged. |
4fa6fb1 to
fb26ec9
Compare
fb26ec9 to
d3b5192
Compare
arminsabouri
left a comment
There was a problem hiding this comment.
cACK.
Just one comment about copy displayed in the history subcommand
…gwit address The previous implementation of the check_payment function assumed that if the outpoints of the Payjoin transaction have been removed from the UTXO set, it is an indication of the Payjoin being broadcasted by the sender. Moreover, it relied on the same closure to detect whether there is a double-spend attempt from the sender, if only a subset of the outpoints have been spent. Both of the usages of the outpoint closure is incorrect. If the sender does RBF on the fallback transaction, this would change the transaction ID and cause the previous implementation to incorrectly detect double-spend. Moreover, the sender can use some of the UTXOs in the Payjoin session if they wish without necessarily "attacking" the receiver. This change removes the outpoint closure, and instead skips the check if the fallback transaction has any inputs which does not have witness data. This assumes that the fallback transaction has been signed which is a certainty at this point in the Payjoin session.
d3b5192 to
fb368c0
Compare
|
Has there been any discussion about not allowing this state ReceiverSessionOutcome::PayjoinProposalSent => And instead requiring that clients that support non-SegWit inputs instead rely on an address index like esplora, allowing the state machine and clients to be simplified. I understand that this would limit our reference implementation, but the index is a sort of prerequisite for any full on wallet that we've integrated with in the past. |
|
We did briefly talk about how since not all clients have an address index, we could not reliably change this into something which would provide consistent experience. If I got it right, your suggestion is to only remove the new state, and change the documentation, etc. around the state to reference an address index usage to solve the non-SegWit problem. That makes sense to me. Trying to wrap my head around how it looks like in two different cases:
For the second point, let me know if you have any information! Otherwise I understand that real world usages will have address index capabilities to make this possible. Let me create an issue for it to move the discussion there. |
I think we can simplify by disallowing non-SegWit inputs in the reference implmentation.
I think the closure would change to be |
The persisted SessionEvent format freezes at the payjoin-cli 1.0 database-backwards-compatibility commitment, so reshape the receiver's terminal SessionOutcome while a format break is still free. Change Success(Vec<(ScriptBuf, Witness)>) to Success(Txid). The witness payload was recorded so the receiver could reconstruct the final Payjoin on the non-segwit path, but payjoin#1218 removed that path entirely, leaving the enum payload as dead code. The Receiver settlement classifier (payjoin#1692) will restore non-segwit detection, which would make the payload live again, but sufficient record of a settlement is the txid of the transaction that settled it rather than the witness list. The wallet that observed the spend already holds the full transaction. Recording Success(Txid) also keeps the terminal variants consistent where the outcome for the transaction we recognize carries the same evidence as the one we do not. Add Other(Txid), mapped to SessionStatus::Failed, for contested outpoints settled by an unrecognized transaction. Nothing produces it yet. The reason to reserve it now is API semver, not data compatibility. 8c92050 deliberately kept SessionOutcome exhaustive. A wildcard match arm has no meaningful semantics for a terminal outcome, and the compile error on a new variant is a feature. So adding a variant after 1.0 would be a semver-breaking change that we want. Naming Other before the freeze makes the settlement classifier additive by construction while keeping the enum exhaustive. (Forward compatibility of the persisted data is explicitly not a goal. See the persist module docs, we want unknown state to error.) Update payjoin-cli to match the new shapes exhaustively. no wildcard arms, per 8c92050 surfacing the settlement txid in the history and cancel output, and pin the sealed JSON encodings of the terminal events in a serialization-shape test. StatusText becomes String rather than &'static str in order to accomodate the txid in format!.
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.
Overview
The previous implementation of the check_payment function assumed that if the outpoints of the Payjoin transaction have been removed from the UTXO set, it is an indication of the Payjoin being broadcasted by the sender. Moreover, it relied on the same closure to detect whether there is a double-spend attempt from the sender, if only a subset of the outpoints have been spent.
Both of the usages of the outpoint closure is incorrect. If the sender does RBF on the fallback transaction, this would change the transaction ID and cause the previous implementation to incorrectly detect double-spend. Moreover, the sender can use some of the UTXOs in the Payjoin session if they wish without necessarily "attacking" the receiver.
This change removes the outpoint closure, and instead skips the check if
the fallback transaction has any inputs which does not have witness
data. This assumes that the fallback transaction has been signed which
is a certainty at this point in the Payjoin session.
Closes #1214.
On the side: this PR also contains another small commit for completing a TODO in the unit tests.
List of Changes
check_paymentfunction and add skip if the fallback transaction is non-segwit.Testing
Next Step
#1211 contains a documentation update for the
check_paymentfunction. Will need to update that if and when this PR gets approved and merged, and also make sure that there are integration tests for covering p2pkh as well.