-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix(types): use f64 for DecodePsbt fee field #431
Conversation
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:
|
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 |
|
Thanks for the review feedback mate. I've addressed the feedback:
Hoping test is now more concise, yet still covers off the various changes to the RPC method across versions. I'm open to explicit direction on how to proceed if you'd like further changes. I get the sense there's a desire to uplift test quality across the codebase - happy to help with that broader effort if you can point me in the right direction. BTW not expecting any fast response this time of year, happy holidays too! |
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.
I'll have a proper look after Christmas but from first glance it's much improved and I think you can undraft it.
Hope you have a nice holidays too!
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.
Can you squash the last two commits?
In the rust-bitcoin org the convention is to change the existing commits in a PR to address review comments rather than adding the fix as a new commit at the end.
The rest looks good though.
| // v24+: Taproot fields (e.g. `tap_internal_key`). | ||
| #[cfg(not(feature = "v23_and_below"))] | ||
| { | ||
| psbt.inputs[0].tap_internal_key = Some(keys.x_only_public_key); |
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.
nit: No need for parenthesis, right?
|
LGTM, could be squashed into a single patch IMO. Thanks for the contribution man, you are killing it. reviewed: 604443e |
Sure thing, thanks for the advice |
03073d8 to
96480e4
Compare
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(). - Add Fee(ParseAmountError) variant to DecodePsbtError for proper error handling of fee conversion failures - Improve integration test with derived keys and version-specific assertions - Add TestKeys struct in lib.rs for reusable key derivation 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 - v20+: Default changed to bech32 (PR #16884), native segwit is directly detected, so fee calculation works
96480e4 to
3113bf1
Compare
tcharding
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.
ACK 3113bf1
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