Skip to content
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

Add iswitness parameter to decode- and fundrawtransaction RPCs #11178

Merged
merged 2 commits into from Dec 19, 2017
Merged

Add iswitness parameter to decode- and fundrawtransaction RPCs #11178

merged 2 commits into from Dec 19, 2017

Conversation

meshcollider
Copy link
Contributor

Suggested in #10481 (comment), this adds the option to explicitly choose whether a serialized transaction should be decoded as a witness or non-witness transaction rather than relying on the heuristic checks in #10481. The parameter defaults to relying on #10481 if not included, but it overrides that if included.

@meshcollider meshcollider changed the title Add iswitness parameter to decode- and fundrawtransaction RPCs [WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs Aug 28, 2017
@meshcollider meshcollider changed the title [WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs Add iswitness parameter to decode- and fundrawtransaction RPCs Aug 28, 2017
@meshcollider
Copy link
Contributor Author

@achow101 @roconnor-blockstream you might want to take a look at this :)

Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

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

utACK 55e2b9c8a13b5f80d03936f4275cd9e3828e4b3f

@@ -108,7 +108,7 @@ bool CheckTxScriptsSanity(const CMutableTransaction& tx)
return true;
}

bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness)
bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness, bool fTryWitness)
Copy link
Member

Choose a reason for hiding this comment

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

snake_case

@meshcollider
Copy link
Contributor Author

Changed style as requested, thanks @achow101

@luke-jr
Copy link
Member

luke-jr commented Sep 2, 2017

Please don't change the style of existing code, only the new code... :/

@meshcollider
Copy link
Contributor Author

@luke-jr the style refactor only touches a tiny amount of code inside that single function, in a similar way to adding braces to existing if-statements when modifying nearby code. I'd argue that this small change to existing code style is worth it for the consistency, especially between try_witness and try_no_witness

Copy link
Member

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

Missing tests.

return false;
}


return true;
Copy link
Member

Choose a reason for hiding this comment

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

If you move this return true; inside the if (try_witness) block, the if(!try_witness) inside the catch above becomes unnecessary. I think that'd be a cleaner flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea yep, done

"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"

"\nArguments:\n"
"1. \"hexstring\" (string, required) The transaction hex string\n"
"2. iswitness (boolean, optional) Whether the transaction hex is a serialized witness transaction \n"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: trailing space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return false;
}
}
catch (const std::exception&) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: catch on the same line as }.

try {
ssData >> tx;
if (!ssData.empty()) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Even shorter: invert this test and make it return true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice 👍

if (ssData.empty()) {
return true;
}
} catch (const std::exception&) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

And now this line is unnecessary as well :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, changed. Next you'll want me to move the try-catch outside the if statements so there only needs to be one of them ;) Thanks for reviewing!

Copy link
Member

Choose a reason for hiding this comment

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

Nope, that wouldn't actually work. If both flags were true, and the first attempt to deserialize throws, you still want to try the second.

CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
try {
ssData >> tx;
if (ssData.eof() && CheckTxScriptsSanity(tx)) {
if (ssData.eof() && (CheckTxScriptsSanity(tx) || !try_witness)) {
Copy link
Member

Choose a reason for hiding this comment

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

One final tiny nit: swap the arguments, as checking a boolean is much faster than CheckTxScriptsSanity.

@sipa
Copy link
Member

sipa commented Sep 4, 2017

utACK 3d16658226cd08911200dbd90db762dc3409e443

@meshcollider
Copy link
Contributor Author

Rebased

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.

utACK 6f39ac0

Probably could merge given 3 acks.

@laanwj
Copy link
Member

laanwj commented Dec 19, 2017

utACK 6f39ac0

@laanwj laanwj merged commit 6f39ac0 into bitcoin:master Dec 19, 2017
laanwj added a commit that referenced this pull request Dec 19, 2017
…on RPCs

6f39ac0 Add test for decoderawtransaction bool (MeshCollider)
bbdbe80 Add iswitness parameter to decode- and fundrawtransaction RPCs (MeshCollider)

Pull request description:

  Suggested in #10481 (comment), this adds the option to explicitly choose whether a serialized transaction should be decoded as a witness or non-witness transaction rather than relying on the heuristic checks in #10481. The parameter defaults to relying on #10481 if not included, but it overrides that if included.

Tree-SHA512: d4846a5bb7d64dc19c516445488b00af329fc1f4181d9dfdf9f2382a086568edc98250a4ac7594e24a1bc231dfdee53c699b12c8380c355b920a67cc6770b7a9
laanwj added a commit to laanwj/bitcoin that referenced this pull request Dec 19, 2017
Looks like another `assert_raises_jsonrpc` snuck in with bitcoin#11178.
Change it to `assert_raises_rpc_error`.
maflcko pushed a commit that referenced this pull request Dec 19, 2017
4508519 test: Fix rawtransactions test (Wladimir J. van der Laan)

Pull request description:

  Looks like another `assert_raises_jsonrpc` snuck in with #11178. Change it to `assert_raises_rpc_error`.

Tree-SHA512: c2c2fb78be5dcc490981896cf60be1fba0b41c385a4f18de084b2e0a042c5b06bf6da617d3bf3b7e585b728554f5c8e1814b85045ba542cca9dfb7b826fda75a
hkjn pushed a commit to hkjn/bitcoin that referenced this pull request Jan 13, 2018
Looks like another `assert_raises_jsonrpc` snuck in with bitcoin#11178.
Change it to `assert_raises_rpc_error`.
HashUnlimited pushed a commit to chaincoin/chaincoin that referenced this pull request Mar 15, 2018
Looks like another `assert_raises_jsonrpc` snuck in with bitcoin#11178.
Change it to `assert_raises_rpc_error`.
@meshcollider meshcollider deleted the 201708_rawtx_bool branch October 15, 2018 12:22
@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.

None yet

8 participants