Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented May 2, 2020

Commit 92bcd70 presumably added a check that a dest of type CNoDestination implies an empty scriptChange.

However, it accidentally checked for boost::variant::empty, which always returns false: https://www.boost.org/doc/libs/1_72_0/doc/html/boost/variant.html#id-1_3_46_5_4_1_1_16_2-bb

@fanquake
Copy link
Member

fanquake commented May 3, 2020

Looks like this was pointed out at the time:

It's not clear to me what this assert is checking for.

If dest is not empty, we got a change destination and so scriptChange is not empty. If dest is empty, then scriptChange will be empty. So this just covers all cases and can't fail?
....
I guess it's fine, but it just seems like useless code that might be confusing to future readers. I would suggest that it be removed in a followup that touches this code.

Maybe just remove entirely as suggested by @achow101 ?

@maflcko
Copy link
Member Author

maflcko commented May 3, 2020

At least now the check will fail when the assumption doesn't hold, so it is no longer entirely useless and confusing. I have a slight preference to document this assumption. Either with a CHECK_NONFATAL, or a test, or a developer comment, not sure about removing it altogether.

@maflcko maflcko removed the Tests label May 3, 2020
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Concept ACK.

@maflcko maflcko force-pushed the 2004-walletAssertAlwaysTrue branch 2 times, most recently from fafdd1d to fa1529d Compare May 3, 2020 14:37
@promag
Copy link
Contributor

promag commented May 3, 2020

Concept ACK, how did you catch this?

Could we also do this?

CScript GetScriptForDestination(const CTxDestination& dest)
{
    CScript script;

    bool result = boost::apply_visitor(CScriptVisitor(&script), dest);
    assert(result != script.empty());
    return script;
}

@maflcko
Copy link
Member Author

maflcko commented May 3, 2020

Concept ACK, how did you catch this?

Reading the source code and boost documentation

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

Yikes, good catch.

The reason I added that check was there used to be an early return if the keypool ran out. I want to make sure we don't send change into a void. We now return later (line 2999) if this error occurs. That check relies on scriptChange.empty(), hence my assert here to make really sure of that.

@maflcko maflcko force-pushed the 2004-walletAssertAlwaysTrue branch from fa1529d to fa9bec6 Compare May 4, 2020 11:27
@maflcko
Copy link
Member Author

maflcko commented May 4, 2020

switched to IsValidDestination helper

@maflcko maflcko force-pushed the 2004-walletAssertAlwaysTrue branch from fa9bec6 to fa51acb Compare May 4, 2020 11:32
@maflcko maflcko force-pushed the 2004-walletAssertAlwaysTrue branch from fa51acb to fa47cf9 Compare May 4, 2020 14:41
@Sjors
Copy link
Member

Sjors commented May 4, 2020

utACK fa47cf9

@maflcko
Copy link
Member Author

maflcko commented May 4, 2020

Open-Close to re-run ci. See #15847 (comment)

@maflcko maflcko closed this May 4, 2020
@maflcko maflcko reopened this May 4, 2020
@laanwj laanwj merged commit 88b2652 into bitcoin:master May 6, 2020
@maflcko maflcko deleted the 2004-walletAssertAlwaysTrue branch May 6, 2020 13:13
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 12, 2020
…true

fa47cf9 wallet: Fix typo in assert that is compile-time true (MarcoFalke)

Pull request description:

  Commit 92bcd70 presumably added a check that a `dest` of type `CNoDestination` implies an empty `scriptChange`.

  However, it accidentally checked for `boost::variant::empty`, which always returns false: https://www.boost.org/doc/libs/1_72_0/doc/html/boost/variant.html#id-1_3_46_5_4_1_1_16_2-bb

ACKs for top commit:
  Sjors:
    utACK fa47cf9

Tree-SHA512: 9626b1e2947039853703932a362c2ee204e002d3344856eb93eef0e0f833401336f2dfa80fd43b83c8ec6eac624e6302aee771fb67aec436ba6483be02b8d615
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 28, 2021
Summary:
> Commit 92bcd70 (D8667] presumably added a check that a dest of type CNoDestination implies an empty scriptChange.
>
> However, it accidentally checked for boost::variant::empty, which always returns false:

This is a backport of Core [[bitcoin/bitcoin#18853 | PR18853]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9081
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants