-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: Fixed signed integer overflow for large feerates #29434
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,13 @@ CAmount AmountFromValue(const UniValue& value, int decimals) | |
| return amount; | ||
| } | ||
|
|
||
| CFeeRate ParseFeeRate(const UniValue& json) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Would have named it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively could have made the limit a parameter, because that also makes it clearer.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, may do if I re-touch. |
||
| { | ||
| CAmount val{AmountFromValue(json)}; | ||
| if (val >= COIN) throw JSONRPCError(RPC_INVALID_PARAMETER, "Fee rates larger than or equal to 1BTC/kvB are not accepted"); | ||
| return CFeeRate{val}; | ||
| } | ||
|
|
||
| uint256 ParseHashV(const UniValue& v, std::string_view name) | ||
| { | ||
| const std::string& strHex(v.get_str()); | ||
|
|
@@ -678,11 +685,13 @@ static void CheckRequiredOrDefault(const RPCArg& param) | |
| void force_semicolon(ret_type) | ||
|
|
||
| // Optional arg (without default). Can also be called on required args, if needed. | ||
| TMPL_INST(nullptr, const UniValue*, maybe_arg;); | ||
| TMPL_INST(nullptr, std::optional<double>, maybe_arg ? std::optional{maybe_arg->get_real()} : std::nullopt;); | ||
| TMPL_INST(nullptr, std::optional<bool>, maybe_arg ? std::optional{maybe_arg->get_bool()} : std::nullopt;); | ||
| TMPL_INST(nullptr, const std::string*, maybe_arg ? &maybe_arg->get_str() : nullptr;); | ||
|
|
||
| // Required arg or optional arg with default value. | ||
| TMPL_INST(CheckRequiredOrDefault, const UniValue&, *CHECK_NONFATAL(maybe_arg);); | ||
| TMPL_INST(CheckRequiredOrDefault, bool, CHECK_NONFATAL(maybe_arg)->get_bool();); | ||
| TMPL_INST(CheckRequiredOrDefault, int, CHECK_NONFATAL(maybe_arg)->getInt<int>();); | ||
| TMPL_INST(CheckRequiredOrDefault, uint64_t, CHECK_NONFATAL(maybe_arg)->getInt<uint64_t>();); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,17 @@ def run_test(self): | |
| txid_in_block = self.wallet.sendrawtransaction(from_node=node, tx_hex=raw_tx_in_block) | ||
| self.generate(node, 1) | ||
| self.mempool_size = 0 | ||
| # Also check feerate. 1BTC/kvB fails | ||
| assert_raises_rpc_error(-8, "Fee rates larger than or equal to 1BTC/kvB are not accepted", lambda: self.check_mempool_result( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (fa2a4fd): We could test negative values as well.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unrelated to this pull request, so I am happy to review another pull that adds this check.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a PR to cover this #29459 |
||
| result_expected=None, | ||
| rawtxs=[raw_tx_in_block], | ||
| maxfeerate=1, | ||
| )) | ||
| # ... 0.99 passes | ||
| self.check_mempool_result( | ||
| result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': 'txn-already-known'}], | ||
| rawtxs=[raw_tx_in_block], | ||
| maxfeerate=0.99, | ||
| ) | ||
|
|
||
| self.log.info('A transaction not in the mempool') | ||
|
|
||
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.
It is nice that
DEFAULT_MAX_RAW_TX_FEE_RATEis now deduplicated and is only mentioned once at the parameter definition:Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, this is a nice side-effect of the changes here, due to using
self.Arg().