-
Notifications
You must be signed in to change notification settings - Fork 37.8k
rpc: Strict type checking for RPC boolean parameters #26213
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
The head ref may contain hidden characters: "2209-uni-bool-\u{1F489}"
Conversation
No description provided. |
Suggest splitting up any fixes from the API change at least, so the fixes can be backported. |
fa81eda
to
4444376
Compare
There is no API change, but I've split the commit into three (bugfix / 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.
ACK 4444376
src/util/system.cpp
Outdated
@@ -492,7 +492,7 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const | |||
{ | |||
std::vector<std::string> result; | |||
for (const util::SettingsValue& value : GetSettingsList(strArg)) { | |||
result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str()); | |||
result.push_back(value.isBool() ? (value.get_bool() ? "1" : "0") : value.get_str()); |
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.
not for this PR, but would be good to place the "1" and "0" strings in constants, so we don't hardcode them when they are needed (here, in SettingToString
, SettingToInt
, and inside the univalue implementation).
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 presume SettingsValue
is supposed to be independent of UniValue
implementation details. Otherwise we could just return the UniValue internal string representation?
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.
ok yeah, agree.
leaving out the UniValue
implementation, at least all settings methods could share the same constant (SettingToString
, ArgsManager::SoftSetBoolArg
, ArgsManager::GetArgs
).
but.. just a small thing anyway.
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.
Maybe a inline std::string BoolToSetting(bool val) { return val ? "1" : "0"; }
helper?
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.
sounds good 👍🏼
I can definitely understand why the But in the places where you are replacing |
Also agree with luke it would be nice to put the bugfix in a separate minimal PR so it easier to backport and easier to see what the actual bug is. |
The UniValue
The commit starts with "bugfix:", so it should be possible to find it. |
I'm sure it's possible to figure it out, but it would be easier if something said what the bug was: steps to reproduce, expected behavior, actual behavior |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
This is also there, see #26213 (comment) |
4444376
to
bbbb41e
Compare
Rebased. Should be trivial to re-review. |
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 bbbb41e
@ryanofsky Did you want to re-NACK this? |
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 think there are still some issues with this PR, and at a minimum the commit descriptions should be updated to more clearly describe what is changing (suggestions in review comments below). But the code looks correct so I will add my code review ACK bbbb41e. I'd much more happily ACK this if it:
- Had better commit descriptions that made it obvious how behavior was changing or not changing
- Moved the third commit changing the UniValue API (bbbb41e) into a separate PR from the first commit changing RPC behavior (fa493c7). The small second cleanup commit (fa671a1) could go in either of these two PRs. But trying to do RPC bugfixes and UniValue API changes in the same PR IMO makes the RPC bugfixes more confusing to understand, and the UniValue API change harder to discuss and agree about.
fa20f92
to
fa5c5e7
Compare
Force pushed to add a test and docs, thanks! |
This makes the code more robust, see previous commit. In general replacing isTrue with get_bool is not equivalent because get_bool can throw exceptions, but in this case, exceptions won't happen because of RPCTypeCheck() and isNull() checks in the preceding code.
fa5c5e7
to
fa0153e
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.
Code review ACK fa0153e
Looks great, thanks for taking various suggestions!
Drop UniValue::getBool method because it is easy to confuse with the UniValue::get_bool method, and could potentially cause bugs. Unlike get_bool, getBool doesn't ensure that the value is a boolean and returns false for all integer, string, array, and object values instead of throwing an exceptions. The getBool method is also redundant because it is an alias for isTrue. There were only 5 getBool() calls in the codebase, so this commit replaces them with isTrue() or get_bool() calls as appropriate. These changes were originally made by MarcoFalke in bitcoin#26213 but were dropped to limit the scope of that PR. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
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.
Code ACK fa0153e
293849a univalue: Remove confusing getBool method (Ryan Ofsky) Pull request description: Drop `UniValue::getBool` method because it is easy to confuse with the `UniValue::get_bool` method, and could potentially cause bugs. Unlike `get_bool`, `getBool` doesn't ensure that the value is a boolean and returns false for all integer, string, array, and object values instead of throwing an exception. The `getBool` method is also redundant because it is an alias for `isTrue`. There were only 5 `getBool()` calls in the codebase, so this commit replaces them with `isTrue()` or `get_bool()` calls as appropriate. These changes were originally made by MarcoFalke in bitcoin/bitcoin#26213 but were dropped to limit the scope of that PR. ACKs for top commit: justinpickering: ACK bitcoin/bitcoin@293849a sipa: utACK 293849a w0xlt: ACK bitcoin/bitcoin@293849a hebasto: ACK 293849a, also verified that the removed `getBool` method is not mentioned in any docs: furszy: ACK 293849a Tree-SHA512: 9fbfe5e2083410f123b18703a0cc0161ecbbb4958f331c9ff808dcfcc6ad499b0e896abd16fb8ea200c53ba29878db9812ce141e59cc5e0fd174741b0bcb192d
…ters fa0153e refactor: Replace isTrue with get_bool (MarcoFalke) fa2cc5d bugfix: Strict type checking for RPC boolean parameters (MarcoFalke) Pull request description: ACKs for top commit: ryanofsky: Code review ACK fa0153e furszy: Code ACK fa0153e Tree-SHA512: b221f823c69d90c94447fd491071ff3659cfd512872b495ebc3e711f50633351974102c9ef7e50fa4a393c4131d349adea8fd41cc9d66f1f31e1f5e7a5f78757
293849a univalue: Remove confusing getBool method (Ryan Ofsky) Pull request description: Drop `UniValue::getBool` method because it is easy to confuse with the `UniValue::get_bool` method, and could potentially cause bugs. Unlike `get_bool`, `getBool` doesn't ensure that the value is a boolean and returns false for all integer, string, array, and object values instead of throwing an exception. The `getBool` method is also redundant because it is an alias for `isTrue`. There were only 5 `getBool()` calls in the codebase, so this commit replaces them with `isTrue()` or `get_bool()` calls as appropriate. These changes were originally made by MarcoFalke in bitcoin#26213 but were dropped to limit the scope of that PR. ACKs for top commit: justinpickering: ACK bitcoin@293849a sipa: utACK 293849a w0xlt: ACK bitcoin@293849a hebasto: ACK 293849a, also verified that the removed `getBool` method is not mentioned in any docs: furszy: ACK 293849a Tree-SHA512: 9fbfe5e2083410f123b18703a0cc0161ecbbb4958f331c9ff808dcfcc6ad499b0e896abd16fb8ea200c53ba29878db9812ce141e59cc5e0fd174741b0bcb192d
Drop UniValue::getBool method because it is easy to confuse with the UniValue::get_bool method, and could potentially cause bugs. Unlike get_bool, getBool doesn't ensure that the value is a boolean and returns false for all integer, string, array, and object values instead of throwing an exceptions. The getBool method is also redundant because it is an alias for isTrue. There were only 5 getBool() calls in the codebase, so this commit replaces them with isTrue() or get_bool() calls as appropriate. These changes were originally made by MarcoFalke in bitcoin/bitcoin#26213 but were dropped to limit the scope of that PR. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
No description provided.