-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Make script more modular #4754
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
Make script more modular #4754
Conversation
Idea ACK on splitting script in a base, interpreter and utils module. You'll need to fix a boost foreach include somewhere though, and I haven't verified that it's move only. |
f2b17e2
to
95d1245
Compare
5ee9504
to
164e56b
Compare
I'll verify this today. |
/** Wrapper that serializes like CTransaction, but with the modifications | ||
* required for the signature hash done in-place | ||
*/ | ||
class CTransactionSignatureSerializer { |
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.
This was moved out of the anon namespace.
I can attest to the code movement, other than the 2 issues raised above. |
@theuni Great, thanks. I can leave the std thing for a separate PR, no problem. |
@jtimon See https://github.com/bitcoin/bitcoin/pull/4754/files#diff-be2905e2f5218ecdbe4e55637dac75f3L978 for what changed. The same question is asked and answered well here: https://stackoverflow.com/questions/1147903/anonymous-namespace-class-definition It's a rather insignificant functional change, I only pointed it out for the sake of being thorough. |
Right, anonymous namespaces in C++ are weird and have little to do with actual namespacing... they just prevent symbols from being visible externally, similar to static functions/globals in C. |
So should I maintain the anonymous namespace or is it ok to delete it? |
Pushed again with the std nit solved, but I left the deletion of the anonymous namespace. |
@jtimon for reviews like this where we're strictly verifying code movement, please avoid rebasing until the end, just add the nit fixes on top. Your rebase could've changed anything, so all former reviews would be invalid. In this case, I stashed your pre-rebased branch before pulling. For anyone else who may be checking the movement, the diff is as-expected:
|
I don't see why you'd remove the anon namespace as it's definitely a good thing, but it's not worth arguing here. ACK. |
@jtimon They're not pointless. They allow the compiler to omit generated code if every instance of a function/method is inlined, make assumptions about how a function gets called, reduce risk of symbol name collisions, and speed up linking due to fewer exported symbols. I generally try to surround 'private' code in .cpp with an anonymous namespace for that reason. Though it's hardly wrong to remove them. |
CheckSig is called by scriptutils::CombineMultisig |
Would it make sense to move CombineMultisig to interpreter to keep CheckSig() private? |
No, exposing CheckSig seems the right approach for that. Multisig related |
Added a fix to the last commit (without rebasing) that restores the order for a simpler diff between the old script.cpp and interpreter.cpp in which I also restore the anonymous namespace. |
ACK if you add CScript::clear again. |
Restored CScript::clear() (without rebasing) |
ACK. |
Rebased after #4812's merge. |
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4754_ff51b1a1169c2bb271006620a4b648dc1385f081/ for binaries and test log. |
ACK. Verified move-only. This needs a trivial rebase on top of #4865, but let's do that at merge time. |
@@ -98,7 +98,12 @@ BITCOIN_CORE_H = \ | |||
rpcclient.h \ | |||
rpcprotocol.h \ | |||
rpcserver.h \ | |||
script.h \ | |||
script/interpreter.h \ |
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.
Can you follow the alphabetical ordering please? I'm starting to get frustrated... I'm not allowed to cleanup and quite often pulls get in that don't even try to match that.
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.
Let's fix that after merging 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 really hope someone does it and also at some time our headers and includes reflect 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.
Yes, sorry. Maybe #4755 is a good place to fix 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.
Untested ACK |
e088d65 Separate script/sign (jtimon) 9294a4b Separate CScriptCompressor (jtimon) c4408a6 Separate script/standard (jtimon) da03e6e Separate script/interpreter (jtimon) cbd22a5 Move CScript class and dependencies to script/script (jtimon) 86dbeea Rename script.h/.cpp to scriptutils.h/.cpp (plus remove duplicated includes) (jtimon) Rebased-by: Pieter Wuille
Merged by eecd3c0. |
#ifndef H_BITCOIN_SCRIPT_COMPRESSOR | ||
#define H_BITCOIN_SCRIPT_COMPRESSOR | ||
|
||
#include "script/script.h" |
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.
In file included from ./script/compressor.h:9:
./script/script.h:197:19: error: no matching conversion for functional-style cast from 'const char [57]' to
'scriptnum_error'
throw scriptnum_error("CScriptNum(const std::vector&) : overflow");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./script/script.h:173:7: note: candidate constructor (the implicit copy constructor) not viable: no known
conversion from 'const char [57]' to 'const scriptnum_error' for 1st argument
class scriptnum_error : public std::runtime_error
^
./script/script.h:176:14: note: candidate constructor not viable: no known conversion from
'const char [57]' to 'const std::string' (aka 'const basic_string<char, char_traits,
allocator >') for 1st argument
explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
^
1 error generated.
make[1]: *** [qt/qt_libbitcoinqt_a-peertablemodel.o] Error 1
make: *** [src/qt/bitcoin-qt] Error 2
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.
This should be fixed in master by 3a757c5.
While the building system is not ready for #4692 , we can start moving the code already.
When #4692 gets reopened other PRs touching script can be rebased on top of this one and decrease the chances of them being breaking/getting broke by 4692.