Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Sep 30, 2022

No description provided.

@maflcko
Copy link
Member Author

maflcko commented Sep 30, 2022

No description provided.

@luke-jr
Copy link
Member

luke-jr commented Sep 30, 2022

Suggest splitting up any fixes from the API change at least, so the fixes can be backported.

@maflcko
Copy link
Member Author

maflcko commented Sep 30, 2022

There is no API change, but I've split the commit into three (bugfix / refactor)

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4444376

@@ -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());
Copy link
Member

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).

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good 👍🏼

@ryanofsky
Copy link
Contributor

I can definitely understand why the getBool alias for isTrue is a footgun and should be removed. I also think the changes in this PR replacing isTrue with get_bool are appropriate in places where values are type checked, and you want to throw an exception when an unexpected type is encountered.

But in the places where you are replacing isFalse and isTrue with things like isBool && get_bool I think it makes code less clear. getBool really seems like a footgun. But isFalse isTrue don't seem like problems any more than isNull is. They just seem like things that are appropriate to use some places, not appropriate other places.

@ryanofsky
Copy link
Contributor

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.

@maflcko
Copy link
Member Author

maflcko commented Sep 30, 2022

But isFalse isTrue don't seem like problems any more than isNull is. They just seem like things that are appropriate to use some places, not appropriate other places.

The UniValue is*() checks are meant for types, with the exception of isTrue/isFalse, which are checking the type and value, which seems confusing to me.

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 commit starts with "bugfix:", so it should be possible to find it.

@ryanofsky
Copy link
Contributor

ryanofsky commented Sep 30, 2022

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 30, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky, furszy
Stale ACK aureleoules

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26129 (wallet, refactor: FundTransaction(): return out-params as util::Result structure by theStack)
  • #25273 (wallet: Pass through transaction locktime and preset input sequences and scripts to CreateTransaction by achow101)

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.

@maflcko
Copy link
Member Author

maflcko commented Oct 3, 2022

steps to reproduce, expected behavior, actual behavior

This is also there, see #26213 (comment)

@maflcko
Copy link
Member Author

maflcko commented Nov 16, 2022

Rebased. Should be trivial to re-review.

Copy link
Contributor

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bbbb41e

@maflcko
Copy link
Member Author

maflcko commented Dec 1, 2022

@ryanofsky Did you want to re-NACK this?

Copy link
Contributor

@ryanofsky ryanofsky left a 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:

  1. Had better commit descriptions that made it obvious how behavior was changing or not changing
  2. 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.

@maflcko maflcko changed the title univalue: Remove confusing getBool/isTrue/isFalse rpc: Add missing bool type checks in RPC code Dec 5, 2022
@maflcko maflcko changed the title rpc: Add missing bool type checks in RPC code rpc: Strict type checking for RPC boolean parameters Dec 5, 2022
@maflcko maflcko force-pushed the 2209-uni-bool- branch 2 times, most recently from fa20f92 to fa5c5e7 Compare December 5, 2022 13:59
@maflcko
Copy link
Member Author

maflcko commented Dec 5, 2022

Force pushed to add a test and docs, thanks!

MarcoFalke added 2 commits December 7, 2022 17:55
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.
Copy link
Contributor

@ryanofsky ryanofsky left a 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!

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 9, 2022
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>
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code ACK fa0153e

@fanquake fanquake merged commit 3b5fb6e into bitcoin:master Dec 10, 2022
fanquake added a commit to bitcoin-core/gui that referenced this pull request Dec 10, 2022
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
@maflcko maflcko deleted the 2209-uni-bool-💉 branch December 10, 2022 12:08
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 10, 2022
…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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 10, 2022
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
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Jan 20, 2023
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>
@bitcoin bitcoin locked and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants