-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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 BaseSignatureCreator a pure interface #12803
Conversation
utACK 6d4bf33 |
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.
utACK 6d4bf33. I like 2nd commit as it makes DummySignatureCreator
a "private" class.
Travis error seams unrelated:
feature_blocksdir.py failed, Duration: 1 s
stdout:
2018-03-28T00:22:53.604000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_test_runner_20180328_001902/feature_blocksdir_15
2018-03-28T00:22:54.024000Z TestFramework (INFO): Starting with non exiting blocksdir ...
2018-03-28T00:22:54.024000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/test_framework.py", line 126, in main
self.run_test()
File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/feature_blocksdir.py", line 24, in run_test
self.assert_start_raises_init_error(0, ["-blocksdir="+self.options.tmpdir+ "/blocksdir"], "Specified blocks director")
AttributeError: 'BlocksdirTest' object has no attribute 'assert_start_raises_init_error'
src/script/sign.cpp
Outdated
class DummySignatureCreator final : public BaseSignatureCreator { | ||
public: | ||
const BaseSignatureChecker& Checker() const override; | ||
bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override final; |
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.
Remove final
since class definition is final? Or add final
in DummySignatureChecker::CheckSig
above?
bd830ef
to
b56e9cf
Compare
@kallewoof You may be interested in this for message script signing. |
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.
Very nice clean up! I believe this will make things easier to do the signmessage proofs for sure.
utACK b56e9cf2b743c1f135606e08ccdaa6bf43b09f62
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.
utACK b56e9cf2b743c1f135606e08ccdaa6bf43b09f62. Interface change seems good. I don't understand the reason for introducing a dummy_signature_creator
global though. Since the object doesn't have any state, it doesn't seem like a performance optimization, and it doesn't seem like there are other advantages, so it's not clear why you'd introduce a global singleton that wasn't actually needed.
src/script/sign.cpp
Outdated
vchSig[6 + 33 + 32] = SIGHASH_ALL; | ||
return true; | ||
} | ||
const BaseSignatureCreator& dummy_signature_creator = DummySignatureCreator(); |
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 commit "Make DummySignatureCreator a singleton"
New global variable should probably have g_ prefix.
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.
Actually, it's a constant.
@ryanofsky My preference for having a singleton is because it reduces the amount of code in header files. |
Sounds good, thanks for explanation. |
b56e9cf
to
9ea9521
Compare
Updated to use LOUD_SCREAMING_NOTATION for global constants. |
Why? Isn't it a global variable? |
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.
utACK 9ea9521fc882b93a51e426cb10f04f530dedb813. Only change since last review is constant names.
Why? Isn't it a global variable?
It is in the sense that a global constant is a type of global variable. Either notation would seem fine to use in this case.
utACK 9ea9521.
Usually I see upper case names as |
From https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md:
|
@sipa the first thing I did was looking the developer notes, hence the utACK. I still see that as macros 😄 |
@sipa PR description needs to be updated. |
Done! |
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.
utACK 37ce177e36063acc11d92fd76e72e2d312452e20
Regarding 9ea9521fc882b93a51e426cb10f04f530dedb813 I'm not convinced of the value of making it a singleton, but if others see it, I guess I'm not opposed to it.
utACK 9ea9521fc882b93a51e426cb10f04f530dedb813
vchSig[6 + 33 + 32] = SIGHASH_ALL; | ||
return true; | ||
} | ||
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(); |
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.
why not just use a std::unique_ptr ? when is this being destroyed?
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.
That seems unnecessarily complicated. This is just a constant, with no storage associated with it, that exists at the start of the program and is always there.
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.
What is the scope of the object that this reference points to? It's not just this line, I hope?
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.
Initializing a const reference with a temporary extends the lifetime of the temporary to that of the reference. The goal here is avoiding the need to have the DummySignatureCreator
type externally visible (the reference type can be different from the dynamic type). An alternative would be to have a static object of type DummySignatureCreator
, and then const BaseSignatureCreator&
exported referencing it. This approach combines the two into one line.
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.
re-utACK 9ea9521fc882b93a51e426cb10f04f530dedb813
utACK 9ea9521 Though now I do wish |
9ea9521
to
be67831
Compare
utACK be67831 |
be67831 Make DummySignatureCreator a singleton (Pieter Wuille) 190b8d2 Make BaseSignatureCreator a pure interface (Pieter Wuille) Pull request description: * Removes the `m_provider` field from `BaseSignatureCreator`. Instead both a `SigningProvider` (which provides keys and scripts) and a `BaseSignatureCreator` (which implements the transaction-specific (or other) signing logic) are passed into and down in `ProduceSignature`, making the two concepts orthogonal. * Makes `BaseSignatureCreator` a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing). * As `DummySignatureCreator` now becomes a stateless object, turn it into a singleton `DUMMY_SIGNATURE_CREATOR`. Tree-SHA512: 5f1f4512e4ea7d02a31df7b9ede55008efa716c5b74a2630ca1c2fc6599584d8bf5f5641487266127f4b3788033803539fbd22b03ef1219c83c10da2d3da3dcd
Summary: be67831 Make DummySignatureCreator a singleton (Pieter Wuille) 190b8d2 Make BaseSignatureCreator a pure interface (Pieter Wuille) Pull request description: * Removes the `m_provider` field from `BaseSignatureCreator`. Instead both a `SigningProvider` (which provides keys and scripts) and a `BaseSignatureCreator` (which implements the transaction-specific (or other) signing logic) are passed into and down in `ProduceSignature`, making the two concepts orthogonal. * Makes `BaseSignatureCreator` a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing). * As `DummySignatureCreator` now becomes a stateless object, turn it into a singleton `DUMMY_SIGNATURE_CREATOR`. Tree-SHA512: 5f1f4512e4ea7d02a31df7b9ede55008efa716c5b74a2630ca1c2fc6599584d8bf5f5641487266127f4b3788033803539fbd22b03ef1219c83c10da2d3da3dcd Backport of Core PR12803 bitcoin/bitcoin#12803 Depends on D3888 Test Plan: make check test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3889
be67831 Make DummySignatureCreator a singleton (Pieter Wuille) 190b8d2 Make BaseSignatureCreator a pure interface (Pieter Wuille) Pull request description: * Removes the `m_provider` field from `BaseSignatureCreator`. Instead both a `SigningProvider` (which provides keys and scripts) and a `BaseSignatureCreator` (which implements the transaction-specific (or other) signing logic) are passed into and down in `ProduceSignature`, making the two concepts orthogonal. * Makes `BaseSignatureCreator` a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing). * As `DummySignatureCreator` now becomes a stateless object, turn it into a singleton `DUMMY_SIGNATURE_CREATOR`. Tree-SHA512: 5f1f4512e4ea7d02a31df7b9ede55008efa716c5b74a2630ca1c2fc6599584d8bf5f5641487266127f4b3788033803539fbd22b03ef1219c83c10da2d3da3dcd
be67831 Make DummySignatureCreator a singleton (Pieter Wuille) 190b8d2 Make BaseSignatureCreator a pure interface (Pieter Wuille) Pull request description: * Removes the `m_provider` field from `BaseSignatureCreator`. Instead both a `SigningProvider` (which provides keys and scripts) and a `BaseSignatureCreator` (which implements the transaction-specific (or other) signing logic) are passed into and down in `ProduceSignature`, making the two concepts orthogonal. * Makes `BaseSignatureCreator` a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing). * As `DummySignatureCreator` now becomes a stateless object, turn it into a singleton `DUMMY_SIGNATURE_CREATOR`. Tree-SHA512: 5f1f4512e4ea7d02a31df7b9ede55008efa716c5b74a2630ca1c2fc6599584d8bf5f5641487266127f4b3788033803539fbd22b03ef1219c83c10da2d3da3dcd
be67831 Make DummySignatureCreator a singleton (Pieter Wuille) 190b8d2 Make BaseSignatureCreator a pure interface (Pieter Wuille) Pull request description: * Removes the `m_provider` field from `BaseSignatureCreator`. Instead both a `SigningProvider` (which provides keys and scripts) and a `BaseSignatureCreator` (which implements the transaction-specific (or other) signing logic) are passed into and down in `ProduceSignature`, making the two concepts orthogonal. * Makes `BaseSignatureCreator` a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing). * As `DummySignatureCreator` now becomes a stateless object, turn it into a singleton `DUMMY_SIGNATURE_CREATOR`. Tree-SHA512: 5f1f4512e4ea7d02a31df7b9ede55008efa716c5b74a2630ca1c2fc6599584d8bf5f5641487266127f4b3788033803539fbd22b03ef1219c83c10da2d3da3dcd
m_provider
field fromBaseSignatureCreator
. Instead both aSigningProvider
(which provides keys and scripts) and aBaseSignatureCreator
(which implements the transaction-specific (or other) signing logic) are passed into and down inProduceSignature
, making the two concepts orthogonal.BaseSignatureCreator
a pure interface without constructor, making it easier to implement new derivations of it (for example for message signing).DummySignatureCreator
now becomes a stateless object, turn it into a singletonDUMMY_SIGNATURE_CREATOR
.