Skip to content

Request v0 PSBTs from Bitcoin Core 32 - #2058

Open
AdityaKaushal17 wants to merge 1 commit into
payjoin:masterfrom
AdityaKaushal17:fix/core32-psbtv2
Open

AdityaKaushal17 wants to merge 1 commit into
payjoin:masterfrom
AdityaKaushal17:fix/core32-psbtv2

Conversation

@AdityaKaushal17

Copy link
Copy Markdown

Fixes #2054

Reviewer: @spacebear21

On Core 32, walletcreatefundedpsbt returns a v2 PSBT by default. rust-bitcoin 0.32 can only parse v0, so payjoin-cli send fails with conversion of the psbt field failed before it even reaches the receiver. On Core 31.1 it works fine.

As discussed in #2054, this PR asks Core for a v0 PSBT when the node is 32 or newer, and leaves the call as it is for 31 and older.

What I changed

  • Check the node version with getnetworkinfo the first time create_psbt runs, and cache it, so commands that don't send never need it.
  • On Core 32+, call walletcreatefundedpsbt through call_raw and pass psbt_version=0 as the 7th argument. The typed client has no way to pass this argument, so I added a TODO to switch back once it does.
  • On older nodes, the typed call is unchanged.
  • walletprocesspsbt keeps whatever version it gets, so nothing after this needs changing.
  • options goes through the same serde_json::to_value as the typed call, so fee_rate is still sent in sat/vB. I added a unit test for this (375 sat/kwu -> 1.5).
  • Moved the params and the version check into two small functions so they can be unit tested without a Core 32 node.
  • locktime is now a plain u32, since both branches use it.
  • Added a changelog fragment.

Testing

What Result
./contrib/test_local.sh pass: payjoin (309 lib, 16 integration), payjoin-cli (10 unit incl. 2 new, 9 e2e), payjoin-mailroom (93 unit, 3 integration)
./contrib/lint.sh, fmt, clippy, docs, codespell pass
Core 32.1.0 e2e::send_receive_payjoin_v1 and e2e::send_receive_payjoin_v2_to_v1 pass

I couldn't run nix fmt -- --ci because I don't have nix installed.

Things to note

  • I only tested on 32.1.0. The check is >= 320000, but I haven't tried 32.0 myself.
  • Other places that call walletcreatefundedpsbt (payjoin integration tests and the FFI tests) don't pass psbt_version, so they'll probably break on Core 32 too. I left those out to keep this PR small.
  • Receiving on 32.1 still fails, but for a different reason: gettransaction no longer returns bip125-replaceable, and bitcoind-async-client 0.16.1 expects it. That breaks 4 v2 e2e tests on 32.1. I'll open a separate issue for it, which is why I didn't touch the supported versions in the README.

AI disclosure: I used Claude Code to help write the code and this description, and ran a local AI review before opening. I went through the diff and ran the tests myself.

Pull Request Checklist

Please confirm the following before requesting review:

Bitcoin Core 32 returns a version 2 PSBT from walletcreatefundedpsbt
by default. rust-bitcoin 0.32 only parses version 0, so payjoin-cli
send failed against such a node.

Ask getnetworkinfo for the node version once and reuse the answer.
For Core 32 and later, call walletcreatefundedpsbt through call_raw
with psbt_version=0, since bitcoind-async-client has no way to pass
that argument. Earlier versions keep the existing typed call.

The version check and the raw arguments are built by small functions
so that unit tests cover them without a Core 32 node. The locktime is
now a plain u32 because both branches need the value.

Receiving on Core 32 still fails where gettransaction is parsed,
because the node no longer returns bip125-replaceable. That is left
for a separate change.

Fixes payjoin#2054

@caarloshenriq caarloshenriq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK d735229

I don't have a Core 32 node, so I haven't run the new path. I checked that bitcoind-async-client 0.16.1 sends only five positional args to walletcreatefundedpsbt, so call_raw is needed, and that the raw params match what the typed call sends (locktime, and options serialized the same way, so fee_rate stays in sat/vB). The unit tests pass and clippy is clean.

Since CI runs an older bitcoind, the Core 32 branch is only covered by your manual e2e run. Is bumping the test node to 32 tracked anywhere? That would also catch the other walletcreatefundedpsbt callers you mentioned.

@AdityaKaushal17

Copy link
Copy Markdown
Author

ACK d735229

I don't have a Core 32 node, so I haven't run the new path. I checked that bitcoind-async-client 0.16.1 sends only five positional args to walletcreatefundedpsbt, so call_raw is needed, and that the raw params match what the typed call sends (locktime, and options serialized the same way, so fee_rate stays in sat/vB). The unit tests pass and clippy is clean.

Since CI runs an older bitcoind, the Core 32 branch is only covered by your manual e2e run. Is bumping the test node to 32 tracked anywhere? That would also catch the other walletcreatefundedpsbt callers you mentioned.

Thanks for reviewing! Not tracked as far as I can see. Bumping the test node to 32 would also hit the gettransaction/bip125-replaceable problem I mentioned, so the 4 v2 e2e tests would fail until that’s fixed. I’ll open an issue for that and include a CI test node bump to Core 32 as part of it, so the other walletcreatefundedpsbt callers get covered too.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 43924149511

Coverage remained the same at 87.657%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 7 uncovered changes across 1 file (77 of 84 lines covered, 91.67%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
payjoin-cli/src/app/wallet.rs 84 77 91.67%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
payjoin-cli/src/app/wallet.rs 1 91.02%

Coverage Stats

Coverage Status
Relevant Lines: 18326
Covered Lines: 16064
Line Coverage: 87.66%
Coverage Strength: 104.09 hits per line

💛 - Coveralls

This branch has not been deployed

No deployments
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.

payjoin-cli fails on Bitcoin Core 32.1: wallet RPCs return PSBTv2

3 participants