-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: check for non-representable CFeeRates #20546
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
wallet: check for non-representable CFeeRates #20546
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
the error message and error code should be the same when an invalid BTC/kb amount is rejected |
Concept ACK |
The other "too-low" fee messages I am aware of are: Amount out of range |
It would be confusing if 0.00000001 and 0.000000001 produced different error messages |
fee_rate=0.000000001
...which is not a great error message, as it indicates neither which argument is invalid, nor why. How about: fee_rate=0.00000001
This is close to these similar error messages: Invalid amount for -paytxfee=: '%s' (must be at least %s) |
Just found a bug in RPC send. It only allows fee rates to be passed as a number, not as a string. Fixing with a commit here since it fits with the changes. Edit: fixed in #20573 (merged). |
Then the error message should be fixed. But that is an issue that can be solve completely separate. It shouldn't be a reason to make the behaviour inconsistent. |
307ecc5
to
03b30e9
Compare
Done. Fixing the rpc send bug and improving the AmountFromValue error messages in separate pulls. |
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.
TBH, I don't understand how this can close #20534 if the behavior is kept consistent. After merge the behavior described there is still the same. An error is caught at the "right" place internally but if the user can't tell the difference this rather seems to be a refactor?
The bug fix is that the response is consistent, though I agree it somewhat less user friendly. I have a follow-up that improves the error responses here and in AmountFromValue. |
I wonder if this check shouldn't be in AmountFromValue and apply to fundrawtransaction and walletcreatefundedpsbt as well. |
E.g. zero is ok for those but between zero and 0.001 sat/vB is invalid. |
the check should be in AmountFromValue. My issue is purely about parsing decimals, not about specific rpcs. To clarify, I might be misunderstanding what you fix here, but approach NACK if this is a fix for the parsing issue I created. |
03b30e9
to
d580e9c
Compare
Pulled in the |
d580e9c
to
7d6c6aa
Compare
7d6c6aa
to
670c6ef
Compare
rebased |
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.
Concept ACK
Thanks for compressing this a bit, makes it easier to review for me at least. I had some thoughts but no major issues. Will follow up soon with another pass.
and use it instead of constructing CFeeRates in conditionals
similar to AmountFromValue() with an additional check for non-representable CFeeRates in the exclusive range of 0 to 0.001 sat/vB as CFeeRate rounds these values down to CFeeRate(0)
1fc25a4
to
236f556
Compare
Thanks for reviewing @fjahr, updated with your feedback per |
Code review ACK 236f556 |
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 236f556
This PR fixes the behavior shown in #20534
Master: Not representable, should through error code: -3
./src/bitcoin-cli -regtest -named sendtoaddress address=<addr> amount=1.23 fee_rate=0.0009
error code: -6
error message:
Fee rate (0.000 sat/vB) is lower than the minimum fee rate setting (1.000 sat/vB)
PR: throws error code: -3
./src/bitcoin-cli -regtest -named sendtoaddress address=<addr> amount=1.23 fee_rate=0.0009
error code: -3
error message:
Invalid amount
(changed title because the only behaviour changes are in the wallet and this is not a refactor) |
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.
Approach re-NACK
Concept ACK
NACK 236f556 😰
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
NACK 236f556708fb619167b72cca451d0048a9274646 😰
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgD5Av/Xab0IOByGeikbyUJLvFeyqNKCpgDZOwPp8IH3gMOw0RsQSOTba1Mw/mi
TYwJbgZs861puVMSvVGcdp3knH4GsE2SnhX/h3h3ozL1lEu0s4K0uksel7PtrwWH
Om4oCDT3kNNAcrGE/HBvCk723gx3JwT5zOWbBv6X//ESGrkUM9+yMbg3od4HBhmG
o24Ju8mugPXPKY9eQ+IG2RzXWItZPVVJIQBOVgD5awIBy15rgK50oOnLbT/8Mw8/
xbgaOZJzmt+3VczxsOTX+Qp+FMvX1fEJgO4Blsrk5bx2COy+tMst3lU16Vw9vcjh
huXxo7VdqiFPZB/q0BRg1Ysxl2o8o6ldKhrFm/W6Vtr5v3iIYxg7PTVjZAsJY98a
6DFpasP/KkWRwJSbqT63GETinOE+hKlu8sZO2X8R0NRGsyF+d9Lkyjq0FJsn4GDu
fcPe1KUYGa0nKQB7TvbZSBHxZ/eM84Qg1tCtX88rVLgXtuQCnFt92aW0l5PScw1I
4tC98cjZ
=4KcO
-----END PGP SIGNATURE-----
Timestamp of file with hash d9e37613c2875ff346833a9cd2c564a076e87e0eb46dd8c7fa743c1e891d0796 -
const CAmount amount{AmountFromValue(value)}; | ||
const CFeeRate fee_rate{CFeeRate::FromSatB(amount)}; | ||
if (fee_rate.IsZero() && amount != 0) { | ||
// passed value is an unrepresentable fee rate between 0 and 0.001 sat/vB |
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.
8885b72: Whether a feerate is representable or not has nothing to do with 0
9.99999999999999999999999999999 isn't representable and also isn't zero
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.
You need to fix this in AmountFromValue
, as I pointed out earlier: #20546 (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 explain how and why this needs to be in AmountFromValue
? Do we pass in an is_sat_b_fee_rate
bool to it, so it has context? Is that an improvement over a dedicated function? I feel like I'm failing to read your mind on this since a couple months now.
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.
dropped the 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.
AmountFromValue
parses the string and fails if the amount is not representable, thus any check about representability should be in AmountFromValue
.
btc/kb are representable when there are at most 8 digits. sat/b are representable when there are at most 3 digits. How you pass in the digits shouldn't matter. Can be done as normal argument or template argument (and function alias, if this makes the code easier to read).
Thanks for testing! This shows that the error message here isn't as helpful as it could be, but I have a branch that improves the various error messages as a follow-up. |
Can you explain why? |
because it doesn't fix the bug. See:
Both calls should fail because the amount is not representable |
Ah, thanks for explaining. I thought that comment was referring to the commit. |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
This patch fixes the issue described in #20534 "values smaller than 0.001 sat/B can't be represented by CFeeRate, but they are not rejected" but I agree this should also be fixed. The approach here won't suffice so am trying a different one. |
Closing for now in favor of #21786. |
As part of our migration to sat/vB feerates that began with #20305, this pull should resolve #20534 and improve/reduce the size of #20391 that adds a
setfeerate
RPC in sat/vB, as well as for a futureestimatefeerate
RPC in sat/vB. The code changes are less than 40 lines. Most of the diff is test coverage, as these changes touch a number of RPCs.Changes:
CFeeRate::FromSatB
andCFeeRate::FromBtcKb
named constructorsCFeeRate::IsZero()
class member helper to replace== CFeeRate(0)
conditionals and avoid object allocations/constructionsFeeRateFromValueInSatB()
utility function that callsAmountFromValue()
and then performs an additional check for non-representableCFeeRate
values in the range between 0 and 0.001 sat/vB