Skip to content

Avoid unused locals for CScript::IsWitnessProgram#12938

Closed
Empact wants to merge 1 commit intobitcoin:masterfrom
Empact:test-only-iswitnessprogram
Closed

Avoid unused locals for CScript::IsWitnessProgram#12938
Empact wants to merge 1 commit intobitcoin:masterfrom
Empact:test-only-iswitnessprogram

Conversation

@Empact
Copy link
Copy Markdown
Contributor

@Empact Empact commented Apr 11, 2018

For those cases where the version and program are not useful.

@Empact Empact force-pushed the test-only-iswitnessprogram branch from e8b04fb to b9f0169 Compare April 11, 2018 04:22
@practicalswift
Copy link
Copy Markdown
Contributor

utACK b9f0169bcce3ca7c9d0646ddda5bf264062be87b

Nice simplification

@Empact Empact changed the title Overload CScript::IsWitnessProgram with a test-only version Avoid unused locals for CScript::IsWitnessProgram Apr 12, 2018
Copy link
Copy Markdown
Contributor

@jimpo jimpo left a comment

Choose a reason for hiding this comment

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

utACK b9f0169

Comment thread src/script/script.cpp Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might as well return this directly.

Copy link
Copy Markdown
Contributor Author

@Empact Empact Apr 13, 2018

Choose a reason for hiding this comment

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

I like that style too, but held back for the sake of simplifying review. Here's my choice if I'm to simplify the method:

static constexpr bool IsOP_N(const unsigned char op)
{
    return (op == OP_0 || (op >= OP_1 && op <= OP_16));
}

// A witness program is any valid CScript that consists of a 1-byte push opcode
// followed by a data push between 2 and 40 bytes.
bool CScript::IsWitnessProgram() const
{
    return ((this->size() >= 4 && this->size() <= 42) &&
            IsOP_N((*this)[0]) &&
            (size_t)((*this)[1] + 2) == this->size());
}

Incidentally, this matches the style of IsPayToWitnessScriptHash and IsPayToScriptHash, above. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Empact looks good, I'd ACK that.

Copy link
Copy Markdown
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

utACK b9f0169.

Comment thread src/script/script.cpp Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Empact looks good, I'd ACK that.

@fanquake fanquake requested a review from sipa April 16, 2018 03:53
@Empact Empact force-pushed the test-only-iswitnessprogram branch from 1bc4896 to e953c69 Compare June 1, 2018 12:12
@Empact
Copy link
Copy Markdown
Contributor Author

Empact commented Jun 1, 2018

Rebased, squashed, and updated to take advantage of IsSmallInteger from #13194

@Empact Empact force-pushed the test-only-iswitnessprogram branch 3 times, most recently from 588e930 to 9057444 Compare June 1, 2018 13:52
@sdaftuar
Copy link
Copy Markdown
Member

sdaftuar commented Jun 1, 2018

I am generally a concept NACK on changes like this; IMO the review burden for refactoring consensus-critical code typically outweighs the benefits.

For those cases where the version and program are not useful.
@Empact Empact force-pushed the test-only-iswitnessprogram branch from 9057444 to 943f3b7 Compare June 1, 2018 22:48
@laanwj
Copy link
Copy Markdown
Member

laanwj commented Jun 24, 2018

I am generally a concept NACK on changes like this; IMO the review burden for refactoring consensus-critical code typically outweighs the benefits.

Agree, seems to risky, closing.

@laanwj laanwj closed this Jun 24, 2018
@Empact Empact deleted the test-only-iswitnessprogram branch July 2, 2018 17:10
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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