You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrade or replace bitcoind in integration tests #369
Currently bitcoind is on 0.21 which doesn't support bech32m addresses and is preventing us from using taproot in integration tests.
My attempts to upgrade it have failed so far (bitcoind 0_22 fails because it creates legacy wallets by default, which don't support bech32m. bitcoind 0_23 and above fail because of some deadlock between tests running in parallel).
It looks like bitcoind might be on its way out so if upgrading doesn't work perhaps we should consider replacing this dependency with something else.
What closing this entails
Update to use corepc-node so we can run a more recent version of bitcoin core
Consider an upgrade to a new client like alpen's in order to support this new version
I made a local fork of corepc that attempts to implement the missing functions for the v28 client version. I had partial success in writing those and getting it to compile and pushed my progress here (resorted to many hacks and shortcuts so it's not pretty...). I also have a working branch that modifies rust-payjoin to use this local corepc instead of bitcoind
However, some problems remain:
When running all tests they just fail immediately due to a timeout error. Debug prints seem to indicate that tests hang on the "generating coins" initialization step and minreq kills the hung requests.
I ran into a similar issue when I attempted to upgrade bitcoind and mentioned it in the top comment. Perhaps they are related:
bitcoind 0_23 and above fail because of some deadlock between tests running in parallel
I can run tests one at a time e.g. cargo test v1_to_v1 but there are various incompatibilities that I "fixed" in my corepc branch with ugly hacks or simply commenting out unneeded fields.
walletcreatefundedpsbt expects amounts expressed in BTC but corepc passes satoshis.
Serialization errors like PSBTs not converted to string when calling PSBT RPCs.
Deserialization errors from RPC results like a required is_compressed field that is in fact optional in the RPC response.
Overall it seems corepc is not yet mature enough for us to make the switch at this time.
@nothingmuch mentioned a potential workaround for upgrading bitcoind which would involve using a Nix flake to initialize bitcoind and skipping the auto-download, calling the Nix binary directly.
Currently bitcoind is on 0.21 which doesn't support bech32m addresses and is preventing us from using taproot in integration tests.
I set the BITCOIND_EXE to a locally compiled bitcoind bin. Generating bech32m addresses worked fine however the v1-v1 taproot test failed for a different reason.
thread 'integration::v1::v1_to_v1_taproot' panicked at payjoin/tests/integration.rs:126:13:
assertion `left == right` failed
left: 4899999811 SAT
right: 4899999812 SAT
Side note: I believe the bitcoind crate will skip autodownload if it detects bitcoind in the PATH.
Instead of ignoring certain tests we could enable them based on the version of bitcoind
Generating bech32m addresses worked fine however the v1-v1 taproot test failed for a different reason.
thread 'integration::v1::v1_to_v1_taproot' panicked at payjoin/tests/integration.rs:126:13:
assertion `left == right` failed
left: 4899999811 SAT
right: 4899999812 SAT
I wrote the v1-v1 taproot test but I guess I never confirmed that it actually works. Exact fee calculations are tricky to get right in tests. My first guess is that the value returned by predicted_tx_weight() in the test doesn't match the one returned by InputPair::expected_input_weight for taproot inputs.
first guess is that the value returned by predicted_tx_weight() in the test doesn't match the one returned by InputPair::expected_input_weight for taproot inputs
Correct. When I pulled network_fees from the psbt directly the test passed
Makes sense, ideally we'd just use network_fees and drop the manual fee calculations in tests. IIRC that doesn't work for the non-taproot tests because ECSDA signatures lengths vary. expected_input_weight returns the worst-case weight so we can make conservative fee estimations.
If you push a working branch with your bitcoind changes I can take a look at why predicted_tx_weight isn't matching the expected weight.
Noting this isn't really so much tech debt as it is maintenance. When the dependency was taken on it was state of the art, and the state of the art changed.
Not really tech debt to pay back, but regular maintenance
Makes sense, ideally we'd just use network_fees and drop the manual fee calculations in tests. IIRC that doesn't work for the non-taproot tests because ECSDA signatures lengths vary. expected_input_weight returns the worst-case weight so we can make conservative fee estimations.
If you push a working branch with your bitcoind changes I can take a look at why predicted_tx_weight isn't matching the expected weight.
I can put it up but there isn't much code changed. To reproduce you just need to run latest bitcoin core locally and set BITCOIN_EXE envar
I replicated the taproot error with a local bitcoind_exe.
thread 'integration::v1::v1_to_v1_taproot' panicked at payjoin/tests/integration.rs:126:13:
assertion `left == right` failed
left: 4899999811 SAT
right: 4899999812 SAT
This is strange... the payjoin input calculations actually match the expected values. The reason it's off-by-one is because the original PSBT is paying 1 sat more than we should expect 🤔 I added some debug prints:
let psbt = build_original_psbt(&sender,&uri)?;dbg!(psbt.clone().extract_tx_unchecked_fee_rate().weight());dbg!(psbt.fee().unwrap());
520 WU is exactly 130 vB, and we explicitly specify a feerate of DEFAULT_MIN_RELAY_TX_FEE which is 1 sat/vB, so I would expect the original PSBT fee to be 130 SAT...
Activity
DanGould commentedon Oct 16, 2024
bitcoind-json-rpc-regtest appears to be the favored upgrade path in the rust-bitcoin issue linked in OP
DanGould commentedon Dec 2, 2024
some functions we use from
Clientare missing. These are the ones we used and what's already implemented in bitcoind-json-rpc-regtest.spacebear21 commentedon Jan 7, 2025
bitcoind-json-rpc-regtest has been archived and development is now happening at https://github.com/rust-bitcoin/corepc. The corresponding crate is corepc-node.
spacebear21 commentedon Jan 13, 2025
I made a local fork of
corepcthat attempts to implement the missing functions for thev28client version. I had partial success in writing those and getting it to compile and pushed my progress here (resorted to many hacks and shortcuts so it's not pretty...). I also have a working branch that modifies rust-payjoin to use this localcorepcinstead ofbitcoindHowever, some problems remain:
minreqkills the hung requests.bitcoindand mentioned it in the top comment. Perhaps they are related:cargo test v1_to_v1but there are various incompatibilities that I "fixed" in mycorepcbranch with ugly hacks or simply commenting out unneeded fields.walletcreatefundedpsbtexpects amounts expressed in BTC butcorepcpasses satoshis.is_compressedfield that is in fact optional in the RPC response.Overall it seems
corepcis not yet mature enough for us to make the switch at this time.spacebear21 commentedon Jan 13, 2025
@nothingmuch mentioned a potential workaround for upgrading
bitcoindwhich would involve using a Nix flake to initialize bitcoind and skipping the auto-download, calling the Nix binary directly.arminsabouri commentedon Feb 2, 2025
I set the
BITCOIND_EXEto a locally compiled bitcoind bin. Generating bech32m addresses worked fine however the v1-v1 taproot test failed for a different reason.Side note: I believe the
bitcoindcrate will skip autodownload if it detectsbitcoindin thePATH.Instead of ignoring certain tests we could enable them based on the version of bitcoind
spacebear21 commentedon Feb 4, 2025
I wrote the v1-v1 taproot test but I guess I never confirmed that it actually works. Exact fee calculations are tricky to get right in tests. My first guess is that the value returned by
predicted_tx_weight()in the test doesn't match the one returned byInputPair::expected_input_weightfor taproot inputs.arminsabouri commentedon Feb 5, 2025
Correct. When I pulled
network_feesfrom the psbt directly the test passedspacebear21 commentedon Feb 5, 2025
Makes sense, ideally we'd just use
network_feesand drop the manual fee calculations in tests. IIRC that doesn't work for the non-taproot tests because ECSDA signatures lengths vary.expected_input_weightreturns the worst-case weight so we can make conservative fee estimations.If you push a working branch with your bitcoind changes I can take a look at why
predicted_tx_weightisn't matching the expected weight.DanGould commentedon Feb 12, 2025
Noting this isn't really so much tech debt as it is maintenance. When the dependency was taken on it was state of the art, and the state of the art changed.
Not really tech debt to pay back, but regular maintenance
arminsabouri commentedon Feb 12, 2025
I can put it up but there isn't much code changed. To reproduce you just need to run latest bitcoin core locally and set
BITCOIN_EXEenvarspacebear21 commentedon Feb 13, 2025
I replicated the taproot error with a local bitcoind_exe.
This is strange... the payjoin input calculations actually match the expected values. The reason it's off-by-one is because the original PSBT is paying 1 sat more than we should expect 🤔 I added some debug prints:
520 WU is exactly 130 vB, and we explicitly specify a feerate of
DEFAULT_MIN_RELAY_TX_FEEwhich is 1 sat/vB, so I would expect the original PSBT fee to be 130 SAT...spacebear21 commentedon Feb 13, 2025
I replicated this with bitcoin-cli alone:
The fee is 131 sats despite the vsize being 130vB and the fee_rate of 1sat/vB.
DanGould commentedon Aug 26, 2025
Seems like
corepc-nodeand bitcoind-async-client would let us close this upgrade, test taproot, and close this issue for 1.0 stability.This is not really an API issue but it does plug a small hole in our tests.
arminsabouri commentedon Sep 5, 2025
closed by #1041