-
Notifications
You must be signed in to change notification settings - Fork 41
fix(types): use f64 for DecodePsbt fee field #431
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
base: master
Are you sure you want to change the base?
Conversation
Add Fee(ParseAmountError) variant to handle fee conversion failures. This prepares for the upcoming change from u64 to f64 for the fee field. Affected versions: v17, v23, v24, v30
Bitcoin Core returns the fee as a floating-point BTC value, not satoshis. Change fee field from u64 to f64 and update conversion to use Amount::from_btc() instead of Amount::from_sat(). Affected versions: v17, v23, v24, v30
jamillambert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix.
The CI failure is just a missing feature gate on the assert_eq!(json.psbt_version... which only exists for v23 and above.
Could you fix the existing test rather than adding a second one? or rename the two tests to clearly state what they are each testing, so it's clear when one fails and the other passes what the issue is.
If you combine them in this case or for other RPCs make sure you keep the existing syntax that states the error type when converting to the modelled type.
let model: Result<mtype::DecodePsbt, DecodePsbtError> = json.into_model();
Thank you for great feedback. I obviously had insufficient local testing, this spurred me to setup some local CI infrastructure so I can avoid so many CI failures in the future. I will combine with the existing test |
I find that testing the modified test in v17, the version you made the change in, and v30 catches most problems. Or if there is a version feature gate the versions on either side. Saves running all version tests. |
|
Ok so I opted to make the test handle the various changes to the All except the MuSig2 changes in v30, I don't know enough about this TBH. Edit: I tested locally across 18 versions, all passing:
|
5188074 to
d42c60b
Compare
Test improvements for decode_psbt covering version-specific behaviour across Bitcoin Core v17-v30: - Add doc comments explaining version-specific PSBT behavior - Document fee calculation: v17 (no utxoupdatepsbt), v18-v19 (p2sh-segwit default breaks utxoupdatepsbt detection), v20+ (bech32 default works) - Gate xpubs field assertions correctly (v22_and_below vs v23+) - Add taproot field test with tap_internal_key (v24+) - Add TODO for MuSig2 fields (v30) The fee field is None on v17-v19 because: - v17: No utxoupdatepsbt RPC exists - v18-v19: utxoupdatepsbt can't detect p2sh-segwit (default address type) as segwit without descriptors, so UTXO data isn't populated (hence no fee calc) - v20+: Default changed to bech32 (PR #16884), native segwit is directly detected, so fee calc works
d42c60b to
127cfca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is long and confusing. Some of the issues were already there from before this PR:
- The block in the middle with imports, but no feature gate or any reason to be in a block. A separate helper function would be cleaner.
- The comment on the top is unnecessarily long.
- Instead of hard coding the random
xpubit could be derived from a fixed seed like in other tests:
let secp = bitcoin::secp256k1::Secp256k1::new();
let seed = [0u8; 32];
let xprv = Xpriv::new_master(Network::Regtest, &seed).unwrap();
let xpub = Xpub::from_priv(&secp, &xprv);
- Similarly
keycan be derived, which makes it clearer that it is just a random key and the long hex currently written in the test isn't something specific or important.
@tcharding wrote the original test so there may be a reason for the block and hard coded xpub I have missed?
Thank you for your valuable review time @jamillambert. I agree this can be tightened in the manner you describe, I will move to draft to address |
As per raised in #429, addressing type discrepancies between
corepc-typesand Bitcoin CoreBitcoin Core returns the
feefield in thedecodepsbtRPC response as a floating-point (double) BTC value, not as satoshis (integer). The current implementation usesu64for the fee field and converts it withAmount::from_sat(), which causes a deserialisation failure.Minimal repro with a PSBT from Bitcoin Core's functional tests.
https://github.com/bitcoin/bitcoin/blob/13891a8a685d255cb13dd5018e3d5ccc18b07c34/test/functional/data/rpc_psbt.json#L96
This change:
u64tof64inDecodePsbtstruct (as required in v17, v23, v24, v30)Amount::from_btc()instead ofAmount::from_sat()Fee(ParseAmountError)error variant toDecodePsbtErrorfor proper error handling of the fee