Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payjoin sends #608

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Payjoin sends #608

merged 2 commits into from
Jan 25, 2024

Conversation

DanGould
Copy link

@DanGould DanGould commented Oct 19, 2023

supersede #572
fix ci errors
awaiting mutiny-node merge as a dependency for this

Relies on MutinyWallet/mutiny-node#647 and MutinyWallet/bitcoin-waila#8

Test with @DanGould's payjoin receiver
visit https://mutiny.payjoin.org:4433/bip21?amount=0.00066666 to get a bip21

  • waila part
  • node part

-- @benalleng

@DanGould DanGould marked this pull request as draft October 19, 2023 19:18
@benalleng benalleng mentioned this pull request Oct 31, 2023
2 tasks
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

In my testing I got it to work twice!
https://mutinynet.com/tx/3c5436f1edf7d4c32a5ccf2448c1e963f52bb8a0fb6f8688d7e78a14e1cbe80b
https://mutinynet.com/tx/ca2bca759e84730e8bd995b98edbcce0df0bea26965c39d7293cdae2bae65206

After those 2 however, I continued getting a 400 bad request error
XHRPOST https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=1&maxadditionalfeecontribution=59&minfeerate=1.008 [HTTP/1.1 400 Bad Request 1532ms] { "errorCode": "original-psbt-rejected", "message": "The receiver rejected the original PSBT." }

probably has to do with my hacky fixes to the types in the node where I made ConfirmationTarget::OnChainSweep? not 100% sure

@DanGould
Copy link
Author

DanGould commented Nov 1, 2023

In my testing I got it to work twice!
https://mutinynet.com/tx/3c5436f1edf7d4c32a5ccf2448c1e963f52bb8a0fb6f8688d7e78a14e1cbe80b
https://mutinynet.com/tx/ca2bca759e84730e8bd995b98edbcce0df0bea26965c39d7293cdae2bae65206

After those 2 however, I continued getting a 400 bad request error
XHRPOST https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=1&maxadditionalfeecontribution=59&minfeerate=1.008 [HTTP/1.1 400 Bad Request 1532ms] { "errorCode": "original-psbt-rejected", "message": "The receiver rejected the original PSBT." }

@benalleng

I don't think this failed because of your hack, but because for whatever reason requests after your last success reused the same input 3c5436f1edf7d4c32a5ccf2448c1e963f52bb8a0fb6f8688d7e78a14e1cbe80b:0. That input was banned to prevent probing of the receiver's UTXOs. Does mutiny employ a mechanism to lock UTXOs from being added to subsequent PSBT constructions? If so, perhaps the input in question was unlocked after a wallet restart, then once it tried to spend again and failed it couldn't get past the ban.

One way to mitigate this would be to add a switch that defaults to payjoin but allows you to spend in a naive way by switching off after pj failure. The receiver could also include a more detailed "message" to post to the debug log that says "input {txid:vout} seen before, original PSBT rejected to prevent a probing attack."

image

sentDetails.txid = txid;
sentDetails.fee_estimate = feeEstimate() ?? 0;
} else if (payjoinEnabled()) {
const txid = await state.mutiny_wallet?.send_payjoin(
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we add a try-catch block to enable that fallback to normal send?

try {
const txid = await state.mutiny_wallet?.send_payjoin(
                        destination()!.original,
                        amountSats(),
                        tags
                    );
} catch {
const txid = await state.mutiny_wallet?.send_to_address(
                        address()!,
                        amountSats(),
                        tags
);
}

though this brings up the comment you made in the mutiny-node about where the waila should parse the receive string as some parsing would be needed between destination.original() and address()

Copy link
Collaborator

Choose a reason for hiding this comment

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

easy enough to just regex away the unimportant stuff, but still worth considering

Copy link
Author

@DanGould DanGould Nov 1, 2023

Choose a reason for hiding this comment

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

I'm not sure we should assume someone wants to spend as naive tx if they can avoid it. some automated payment processors will automatically spend the naive tx if payjoin fails but senders may want to try another utxo or choose something else like ln instead of immediately sending w/o a privacy preserving measure

Copy link
Collaborator

Choose a reason for hiding this comment

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

right, that makes sense

@benalleng
Copy link
Collaborator

benalleng commented Nov 1, 2023

Was it a user error? Did I send too rapidly? what do you think was the flow that caused the ban, if this is a mutiny-wallet bug wonder how we can get around it to make sure any user doesn't get banned as manual UTXO selection by the user is avoided

@benalleng
Copy link
Collaborator

benalleng commented Nov 1, 2023

reproduced the error
Got several successes before failure though!
https://mutinynet.com/tx/cd38e01043445e086f4289239909f8404bf809c1ce45ea25bce6281b6fb92de8
https://mutinynet.com/tx/828d97d3a2532121fbd8942d97e6225eb0529b5ba1c547f006b0e9c4541f4543
https://mutinynet.com/tx/494b5144b69cb67cec315080bc4b7e9fc88fcd42c7e96e2f7679c37b31096d53
https://mutinynet.com/tx/d1ebaf0e09a841f1cd61ab67729a94d096d8d6e0bc482e5e4982a07104e91db0

attempt 5:

got a frontend only error
Failed too sign unsure what caused it

attempt 6:

got the error i have seen before likely indicating I am banned, perhaps there is some relation to the error in attempt 5?

XHRPOST
https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=0&maxadditionalfeecontribution=59&minfeerate=1.008
[HTTP/1.1 400 Bad Request 1695ms]

1

{ "errorCode": "original-psbt-rejected", "message": "The receiver rejected the original PSBT." }


attempt 7:

same error as attempt 6

@DanGould
Copy link
Author

If a payjoin_psbt response failed to sign and a request was replayed, that utxo would be banned so this would be expected behavior. Do we have any more logs / detailed on why Failed too sign cropped up?

@benalleng
Copy link
Collaborator

Couldn't recreate the Failed to sign error this time and only got one success before failure, unsure of why its happening

@DanGould
Copy link
Author

DanGould commented Nov 13, 2023

Does this issue require a playwright e2e test to proceed? Have you any logs from those failed runs?

@benalleng benalleng force-pushed the payjoin-sends branch 4 times, most recently from 0d13499 to b4cc22f Compare November 22, 2023 22:58
@benalleng benalleng force-pushed the payjoin-sends branch 5 times, most recently from e47c2c0 to b9a089c Compare December 2, 2023 07:12
@DanGould
Copy link
Author

DanGould commented Dec 4, 2023

I believe this is now ready for review. @benalleng Do we know why OpenSSL failed on iOS here? I don't think it's related to this PR, as it adds no changes to OpenSSL crypto

@benalleng
Copy link
Collaborator

benalleng commented Dec 4, 2023

Yeah I brought it up to everybody on the matrix dev server, the consensus is that it is related to some secret that non-branch PR's / non-contributors don't have access to

@benalleng
Copy link
Collaborator

As for this PR I think it's ready to go, I know at the moment we are going to hold off on adding the optionality for the sender, i.e. the toggle to switch to naive send so we don't need to add that here

@benalleng benalleng marked this pull request as ready for review December 4, 2023 20:32
@DanGould
Copy link
Author

DanGould commented Dec 5, 2023

I agree the toggle can come later. The same function can be had for now by pasting in the plain address instead of a &pj= containing uri.

@futurepaul
Copy link
Collaborator

I'm getting "Failed to create payjoin request" running this locally. It doesn't look like the request to https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=0&maxadditionalfeecontribution=59&minfeerate=1.008 is getting a response?

@DanGould
Copy link
Author

Oops, the public ip of that server was changed. I reset the DNS A record but it may take some hours to propagate. mutiny.payjoin.org should be 110.169.157.242

@futurepaul
Copy link
Collaborator

Hm still not working for me, same timeout for https://110.169.157.242:4433/?v=1&additionalfeeoutputindex=1&maxadditionalfeecontribution=59&minfeerate=1.008

@DanGould
Copy link
Author

DanGould commented Dec 14, 2023

Thanks for your patience on this, my server was moved to one with a dynamic ip. It has been changed to a static one at 157.245.59.46 which mutiny.payjoin.org:4433 should point to. The https cert is not right yet, but I don't think mutiny-node's reqwest is configured without tls because default-features = false so it could still work.

However, ignoring TLS certificates is very dangerous and should be fixed immediately https://github.com/MutinyWallet/mutiny-node/blob/2c332b43269ade626b8c195fc0a3a7870c640b94/mutiny-core/Cargo.toml#L37 reqwest uses browser TLS in a wasm environment.

@DanGould
Copy link
Author

https://mutiny.payjoin.org:4433 is running and secured by TLS now. Please excuse the wait 🙏

@benalleng
Copy link
Collaborator

benalleng commented Dec 14, 2023

getting an error when trying to test now: Can't broadcast. PSBT rejected by mempool. has there been a new change to the mutinynet mempool policy?

Edit: full error looks like it might be happening in payjoin server
400 error at https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=0&maxadditionalfeecontribution=59&minfeerate=1.008
request: cHNidP8BAIkBAAAAAe0FwKIBZIfDEOCCtr/UwPQBjBTem1KNUB2RogezmNyYAQAAAAD9////AiUUDQAAAAAAIlEgf4CcEwehHtY7hSlHxJl4m+ixy+PVDcBhTZIFarDSFx8QJwAAAAAAACJRIMjfFLKpcxOYVaYTI6b9nSiJonL+qH4qJ0r6bshM+CKTrCUKAAABASvUOw0AAAAAACJRIEjN+Sn8Tl5PR0kmUySlTs21HZ4Nc130HdiWIz5A9U3xAQcAAQhCAUD7a+RSg4fWgq3D4Wv3YhuYiD3tJ69gsiiRbebEF/8/ZLlBv4h5TComqVYlfd3IrCO5P71ixqUB+3w2t8Dg8avmARNA+2vkUoOH1oKtw+Fr92IbmIg97SevYLIokW3mxBf/P2S5Qb+IeUwqJqlWJX3dyKwjuT+9YsalAft8NrfA4PGr5iEWOpgW1fPG+DGXIcdyXi2Zc8xQ6aa2yA35dJIvP/hAkFAZAC6AK99WAACAAQAAgAAAAIABAAAAEQAAAAEXIDqYFtXzxvgxlyHHcl4tmXPMUOmmtsgN+XSSLz/4QJBQAAEFIE69POTLBBNE0gjF628w+3XGEm8VOp/xR51Q9Gcjt8rMIQdOvTzkywQTRNIIxetvMPt1xhJvFTqf8UedUPRnI7fKzBkALoAr31YAAIABAACAAAAAgAEAAAALAAAAAAA=
reponse: { "errorCode": "original-psbt-rejected", "message": "Can't broadcast. PSBT rejected by mempool." }

@benthecarman
Copy link
Collaborator

getting an error when trying to test now: Can't broadcast. PSBT rejected by mempool. has there been a new change to the mutinynet mempool policy?

No, haven't in months

@DanGould
Copy link
Author

Weird. When I run testmempoolaccept on the tx you submitted I get non-final error.

bitcoin-cli testmempoolaccept '["01000000000101ed05c0a2016487c310e082b6bfd4c0f4018c14de9b528d501d91a207b398dc980100000000fdffffff0225140d00000000002251207f809c1307a11ed63b852947c499789be8b1cbe3d50dc0614d92056ab0d2171f1027000000000000225120c8df14b2a973139855a61323a6fd9d2889a272fea87e2a274afa6ec84cf822930140fb6be4528387d682adc3e16bf7621b98883ded27af60b228916de6c417ff3f64b941bf88794c2a26a956257dddc8ac23b93fbd62c6a501fb7c36b7c0e0f1abe6ac250a00"]'
[
  {
    "txid": "875ed948c456d763225354658b12241af6ebf9df45bb11596b270d6d3f143c60",
    "wtxid": "b1b5bf107baa8155bda3f54bbdf90cdaefa1ad1616b14f9512890e1bb7a0cc48",
    "allowed": false,
    "reject-reason": "non-final"
  }
]

@DanGould
Copy link
Author

I just sent a successful payjoin from this branch. The signet server there was not synced before after maintenence. It should be fixed now

@futurepaul
Copy link
Collaborator

Hate to be a continual bearer of bad news but I tried to send to your sample address and got another error:

Screenshot 2023-12-18 at 5 34 15 PM

@benalleng
Copy link
Collaborator

Can you see the network request response to see if it was an error communicating with the payjoin server or something else?

@futurepaul
Copy link
Collaborator

it's a 400 bad request:
{ "errorCode": "original-psbt-rejected", "message": "The receiver rejected the original PSBT." }

@DanGould
Copy link
Author

The prior request that failed still included an input which was recorded as seen, so this subsequent request was rejected. I've deleted the seen_inputs database and restarted the server. Thanks for the persistence.

sentDetails.destination = address();
sentDetails.txid = txid;
sentDetails.fee_estimate = feeEstimate() ?? 0;
} else if (payjoinEnabled()) {
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure a sweep should necessarily preclude payjoin on the isMax condition. A receiver offered a sweep could still take the opportunity to contribute an input or use transaction cut-through, and otherwise just broadcast the original psbt as a basic sweep. It doesn't break this PR but should be considered for incremental change later.

@futurepaul
Copy link
Collaborator

futurepaul commented Dec 27, 2023

Error processing payjoin response: couldn't decode PSBT: error in PSBT base64 encoding
{errorCode: "original-psbt-rejected", message: "Missing payment."} (400 bad request error)

request:
https://mutiny.payjoin.org:4433/?v=1&additionalfeeoutputindex=1&maxadditionalfeecontribution=59&minfeerate=1.008
payload:
cHNidP8BAH0BAAAAAdPbOhyZ3wNXGuMe2Ey1vGJ3BRASvUXdlsoO8DYM5hI6AQAAAAD9////AhAnAAAAAAAAFgAUh0ETrcYGZIHGUo9ui7vw2w8pYS1cGQEAAAAAACJRIHWOKlfizYzeNj+o6vk2tFCNNvhX36MfGfYbs6A5ct99CbIKAAABASv/QAEAAAAAACJRIL61n+KaCpzVGNkJBX/ASadNWVNYQIvb2M3eiJDCv87KAQcAAQhCAUCl3cUkYEaBSV9d50ckZLrgDjQibvbTKNHYcVCUv5CAbYbapJKmoK1LGyUDOIafJ+Q7ABRrR5/ahlQht0pFM2a7ARNApd3FJGBGgUlfXedHJGS64A40Im720yjR2HFQlL+QgG2G2qSSpqCtSxslAziGnyfkOwAUa0ef2oZUIbdKRTNmuyEWL48baGI+w0e5GEmqwWmcABdJDaEG0fBMo27iBnPOgpsZAJEiV9NWAACAAQAAgAAAAIABAAAAFQAAAAEXIC+PG2hiPsNHuRhJqsFpnAAXSQ2hBtHwTKNu4gZzzoKbAAABBSCmRFjFT1mEcvHv7SBEMwe/2yze55SLpGPXumvW1L2uMSEHpkRYxU9ZhHLx7+0gRDMHv9ss3ueUi6Rj17pr1tS9rjEZAJEiV9NWAACAAQAAgAAAAIABAAAAAgAAAAA=

@DanGould
Copy link
Author

DanGould commented Jan 3, 2024

@futurepaul It looks like the original bip21 from the description belonged to an old wallet, so the output did not pay the receiver you were calling. I updated the description to let you fetch a bip21 from the live server which I'll repeat here:

https://mutiny.payjoin.org:4433/bip21?amount=0.00066666, which I have just tested on my local machine to success

@DanGould
Copy link
Author

DanGould commented Jan 8, 2024

mutiny.payjoin.org is down for maintenance and should be up tomorrow

@DanGould
Copy link
Author

DanGould commented Jan 9, 2024

mutiny.payjoin.org is up and synced

@DanGould
Copy link
Author

rebased on master w/ new ActivityEditor change

@benthecarman
Copy link
Collaborator

image
Tested and it worked for me. The payjoin notice is a bit big compared to everything else, not sure what a better way would be though

@DanGould
Copy link
Author

@benthecarman hell yeah brother

Happy to follow up with a toggle that fits in the table like bitcoin design recommends

image

@benthecarman
Copy link
Collaborator

Yeah that might be cleaner

@DanGould
Copy link
Author

DanGould commented Jan 24, 2024

as of now this is the same element / size as other warning InfoBoxes
image

We could also spruce up the notice in VStack like this but I do believe that's out of the scope of this PR

image

Copy link
Collaborator

@benthecarman benthecarman left a comment

Choose a reason for hiding this comment

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

lets just get this in

Copy link
Collaborator

@futurepaul futurepaul left a comment

Choose a reason for hiding this comment

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

works for me! added one line so the balance shows up when an onchain request has an amount set (that was my bad)

Screenshot 2024-01-25 at 1 12 35 PM

@benthecarman benthecarman merged commit 0324b49 into MutinyWallet:master Jan 25, 2024
3 of 4 checks passed
@DanGould DanGould deleted the payjoin-sends branch January 25, 2024 16:16
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