Skip to content

Conversation

jtimon
Copy link
Contributor

@jtimon jtimon commented Aug 23, 2014

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.

@sipa
Copy link
Member

sipa commented Aug 23, 2014

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.

@theuni
Copy link
Member

theuni commented Aug 28, 2014

I'll verify this today.

/** Wrapper that serializes like CTransaction, but with the modifications
* required for the signature hash done in-place
*/
class CTransactionSignatureSerializer {
Copy link
Member

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.

@theuni
Copy link
Member

theuni commented Aug 28, 2014

I can attest to the code movement, other than the 2 issues raised above.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 29, 2014

@theuni Great, thanks. I can leave the std thing for a separate PR, no problem.
I'm confused about the anonymous namespace though. I thought it would be equivalent to just remove empty lines (which you know I did too). I don't understand its purpose, any reason to maintain that?

@theuni
Copy link
Member

theuni commented Aug 29, 2014

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

@sipa
Copy link
Member

sipa commented Aug 29, 2014

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.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 29, 2014

So should I maintain the anonymous namespace or is it ok to delete it?

@jtimon
Copy link
Contributor Author

jtimon commented Aug 29, 2014

Pushed again with the std nit solved, but I left the deletion of the anonymous namespace.
It's not something important so if it's going to hold back this PR I'll just restore it, but that stackoverflow thread doesn't convince me that we need it here.

@theuni
Copy link
Member

theuni commented Aug 29, 2014

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

cory@cory-i7:~/dev/bitcoin(code-movement)$ git diff code-movement origin/pr/4754
diff --git a/src/script/script.cpp b/src/script/script.cpp
index be6e849..60d1bea 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -7,6 +7,8 @@

 #include <boost/foreach.hpp>

+using namespace std;
+
 const char* GetOpName(opcodetype opcode)
 {
     switch (opcode)
@@ -183,7 +185,7 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
     // get the last item that the scriptSig
     // pushes onto the stack:
     const_iterator pc = scriptSig.begin();
-    std::vector<unsigned char> data;
+    vector<unsigned char> data;
     while (pc < scriptSig.end())
     {
         opcodetype opcode;

@theuni
Copy link
Member

theuni commented Aug 29, 2014

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.

@sipa
Copy link
Member

sipa commented Aug 29, 2014

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

@jtimon
Copy link
Contributor Author

jtimon commented Aug 30, 2014

CheckSig is called by scriptutils::CombineMultisig
CheckSig (and CTransactionSignatureSerializer) is moved above evalscript to prevent a redundant delcaration of checksig just before evalscript, but now that checksig is in the .h this movement was not necessary, sorry.
I guess it will be better to just leave it this way now.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 30, 2014

Would it make sense to move CombineMultisig to interpreter to keep CheckSig() private?

@sipa
Copy link
Member

sipa commented Aug 30, 2014

No, exposing CheckSig seems the right approach for that. Multisig related
stuff doesn't belong in interpreter inho.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 31, 2014

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.
To avoid wasting the review work (as @theuni explained), it is better that the merger does the rebase himself.

@sipa
Copy link
Member

sipa commented Aug 31, 2014

  • You removed the recently added CScript::clear() method.
  • Apart from that, verified move-only between _1fa679edc5a1eb379049191e8ee18a3b8a0a5a05 and _243fb7a97cf9747a78acd81a66b362d427b1557a.

ACK if you add CScript::clear again.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 31, 2014

Restored CScript::clear() (without rebasing)

@sipa
Copy link
Member

sipa commented Sep 1, 2014

ACK.
Tested testnet reindex.
Verified move-only 1fa679edc5a1eb379049191e8ee18a3b8a0a5a05..2b0f9f9d5c3c4c8a60302951fccad65ed6eb7575.

@jtimon
Copy link
Contributor Author

jtimon commented Sep 2, 2014

Rebased after #4812's merge.

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4754_ff51b1a1169c2bb271006620a4b648dc1385f081/ for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@sipa
Copy link
Member

sipa commented Sep 8, 2014

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 \
Copy link

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.

Copy link
Member

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.

Copy link

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

Copy link
Contributor Author

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?

Copy link

Choose a reason for hiding this comment

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

@sipa @jtimon See #4881 for a cleanup ;). Couldn't resist.... perhaps just base #4755 on that?

@laanwj
Copy link
Member

laanwj commented Sep 8, 2014

Untested ACK

sipa added a commit that referenced this pull request Sep 8, 2014
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
@sipa
Copy link
Member

sipa commented Sep 8, 2014

Merged by eecd3c0.

@sipa sipa closed this Sep 8, 2014
@jtimon jtimon deleted the libscript0 branch September 13, 2014 21:05
#ifndef H_BITCOIN_SCRIPT_COMPRESSOR
#define H_BITCOIN_SCRIPT_COMPRESSOR

#include "script/script.h"
Copy link
Contributor

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

Copy link
Member

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.

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

8 participants