-
Notifications
You must be signed in to change notification settings - Fork 36.8k
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
Don't edit Chainparams after initialization #13311
Conversation
4b5e16a
to
6414f5b
Compare
to ease review, might be good to split this into a moveonly commit and then a subsequent one with changes if thats possible? |
Why move the version bits information to a separate file? This introduces a circular dependency between chainparams and versionbitsinfo, |
Sure, but I would like to wait for some concept acks first.
No, it does not. After this, versionbits depends onchainparams, which depends on versionbitsinfo, which depends on consensus/params. |
My apologies! I confused chainparams and consensus/params when reading this. |
Needs rebase due to merge of #13341 |
6414f5b
to
c3d5082
Compare
Rebased and separated MOVEONLY commit. |
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 with ultra minor nit
src/chainparams.cpp
Outdated
|
||
#include <assert.h> | ||
|
||
#include <chainparamsseeds.h> | ||
#include <boost/algorithm/string/classification.hpp> | ||
#include <boost/algorithm/string/split.hpp> |
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.
NB: it's still used in init.cpp, only for mempool replacement
src/chainparams.cpp
Outdated
|
||
#include <assert.h> | ||
|
||
#include <chainparamsseeds.h> | ||
#include <boost/algorithm/string/classification.hpp> |
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.
NB: it's still used in init.cpp, only for mempool replacement
src/test/test_bitcoin.cpp
Outdated
@@ -55,6 +55,9 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName) | |||
InitSignatureCache(); | |||
InitScriptExecutionCache(); | |||
fCheckBlockIndex = true; | |||
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. | |||
// TODO: fix the code to support SegWit blocks. | |||
gArgs.ForceSetArg("-vbparams", "segwit:0:999999999999"); |
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.
nit: would be nice to keep using Consensus::BIP9Deployment::NO_TIMEOUT
c3d5082
to
54c256d
Compare
rebased |
b2ad565
to
7067657
Compare
Fixed nit in #13311 (comment) |
src/chainparams.cpp
Outdated
@@ -280,7 +276,7 @@ class CTestNetParams : public CChainParams { | |||
*/ | |||
class CRegTestParams : public CChainParams { | |||
public: | |||
CRegTestParams() { | |||
CRegTestParams(ArgsManager& args) { |
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.
Is it necessary to pass in an entire ArgsManager object? It seems only the -vbparams value is used. What about just passing in the vbparams value?
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.
Well, the point of that is to make it easy to add further params, like in #8994 (probably not all of them are interesting for testing).
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.
Better to just pass the needed arg IMO, and only couple these classes if preferable based on the eventual use.
https://martinfowler.com/bliki/Yagni.html
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.
Could make this const ArgsManager& args
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 7067657731404c28ff87e46ec390992500ca13be
src/chainparams.cpp
Outdated
} | ||
} | ||
} | ||
|
||
static std::unique_ptr<CChainParams> globalChainParams; |
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.
Could change this to unique_ptr<const CChainParams>
to better ensure that params aren't changed after initialisation? (Means CreateChainParams()
return value also needs to change, but that seems to work fine)
src/chainparams.cpp
Outdated
{ | ||
globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout); | ||
SelectBaseParams(network); | ||
globalChainParams = CreateChainParams(network, gArgs); |
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 reference gArgs
directly in CreateChainParams()
when using REGTEST? This is the only place that actually calls CreateChainParams
with the args
parameter and the only place that calls it with chain==REGTEST
. That way you don't need to have two different ways of calling CreateChainParams
.
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 can remove the new way of calling CreateChainParams, but the idea was that some unittests could create their own custom ArgsManager instead of using gArgs. This would only serve for testing functions that explicitly take a CChainParams instead of relaying on Params().
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.
Tend to agree with @ajtowns.
but the idea was that some unittests could create their own custom ArgsManager instead of using gArgs
If needed it can mutate gArgs? Or this can be done when needed?
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 guess one can mutate gArgs to a given value for a given test and then back to its original value afterwards.
Or as you say, make this change afterwards when it's going to be used.
Concept ACK. |
7067657
to
ca040b5
Compare
@@ -58,6 +59,9 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName) | |||
InitSignatureCache(); | |||
InitScriptExecutionCache(); | |||
fCheckBlockIndex = true; | |||
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. | |||
// TODO: fix the code to support SegWit blocks. | |||
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT)); |
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.
2018-09-18 16:46:43 clang-tidy(pr=13311): src/test/test_bitcoin.cpp:64:61: warning: redundant cast to the same type [google-readability-casting]
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.
If I remove that casting, I get:
test/qt_test_test_bitcoin_qt-test_bitcoin.o: In function `tinyformat::detail::FormatArg::FormatArg<long>(long const&)':
/home/jt/code/bitcoin/src/./tinyformat.h:508: undefined reference to `Consensus::BIP9Deployment::NO_TIMEOUT'
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.
Cool! A false positive then. Thanks for investigating.
src/chainparams.cpp
Outdated
} | ||
bool found = false; | ||
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) { | ||
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[j].name) == 0) { |
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.
2018-09-18 16:46:43 clang-tidy(pr=13311): src/chainparams.cpp:377:17: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
src/chainparams.cpp
Outdated
@@ -270,7 +268,7 @@ class CTestNetParams : public CChainParams { | |||
*/ | |||
class CRegTestParams : public CChainParams { | |||
public: | |||
CRegTestParams() { | |||
CRegTestParams(const ArgsManager& args) { |
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.
2018-09-18 16:46:43 clang-tidy(pr=13311): src/chainparams.cpp:271:5: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
18d5f26
to
bd74fb9
Compare
Fixed 2 of the 3 clang warnings. |
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 bd74fb9e4c271bd901dfbb5ad1929b44fcadd735
std::vector<std::string> vDeploymentParams; | ||
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":")); | ||
if (vDeploymentParams.size() != 3) { | ||
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end"); |
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 don't like that this introduces more exceptions in code that can normally hit them by a mere typo. I'd prefer if we used exceptions only in exceptional circumstances, since it is not easy to follow the control flow with exceptions.
Note that the our other command line parsing is done with functions that return bool instead of void and append the error to a passed in string reference.
I see that the caller needs to throw, but that isn't reason enough to "poison" unrelated code.
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 think there's absolutely no problem in initialization exceptions that will prevent the binary from starting, this one should be cached (depending on binary) on bitcoin-cli.cpp, bitcoin-tx.cpp or bitcoind.cpp, when SelectParams is called, just like https://github.com/bitcoin/bitcoin/blob/master/src/chainparamsbase.cpp#L42
src/chainparams.cpp
Outdated
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2])); | ||
} | ||
bool found = false; | ||
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) { |
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.
2018-09-22 22:20:08 cpplint(pr=13311): src/chainparams.cpp:376: Missing spaces around < [whitespace/operators] [3]
bd74fb9
to
6fa901f
Compare
Fixed latest style nit. |
utACK 6fa901f. |
re-utACK 6fa901f |
6fa901f Don't edit Chainparams after initialization (Jorge Timón) 980b38f MOVEONLY: Move versionbits info out of versionbits.o (Jorge Timón) Pull request description: This encapsulates the "-vbparams" option, which is only meant for regtest, directly on CRegTestParams. This is a refactor and doesn't change functionality. Related to #8994 Tree-SHA512: 79771d729a63a720e743a9c77d5e2d80369f072d66202a43c1304e83a7d0ef7c6103d4968a03aea9666cc89a7203c618da972124a677b38cfe62ddaeb28f9f5d
06f1b42 Don't edit Chainparams after initialization (Jorge Timón) 875a47c MOVEONLY: Move versionbits info out of versionbits.o (Jorge Timón) Pull request description: This is a backport of bitcoin/bitcoin#13311 since it's already merged, merging this in elements-0.17 should at least make the next rebase slightly easier. And since we're heavily touching chainparams in elements, I think it's a good thing. Tree-SHA512: 177f6396a34ecf87b609b39a108cc2b1e5b49bd8d12b705a4ae0241c7a5007db754ff01d6d045ee1e6a219ec6c6767663cd98558752c83961c4aff3378aef5a2
5f23531 CRegTestParams: Use `args` instead of `gArgs`. (Kiminuo) Pull request description: This PR is a very minor follow-up to bitcoin#13311. I believe that `gArgs` was just overlooked at the modified line. ACKs for top commit: MarcoFalke: cr ACK 5f23531 Tree-SHA512: f4e4ed6b23fca60e88825b502f20a1341ee2e4429bc8a2a7e419057adb643abda11be2061fe7ee076931657736e629aff88fd2c33737c84c330dc9d64f368c30
5f23531 CRegTestParams: Use `args` instead of `gArgs`. (Kiminuo) Pull request description: This PR is a very minor follow-up to bitcoin#13311. I believe that `gArgs` was just overlooked at the modified line. ACKs for top commit: MarcoFalke: cr ACK 5f23531 Tree-SHA512: f4e4ed6b23fca60e88825b502f20a1341ee2e4429bc8a2a7e419057adb643abda11be2061fe7ee076931657736e629aff88fd2c33737c84c330dc9d64f368c30
6fa901f Don't edit Chainparams after initialization (Jorge Timón) 980b38f MOVEONLY: Move versionbits info out of versionbits.o (Jorge Timón) Pull request description: This encapsulates the "-vbparams" option, which is only meant for regtest, directly on CRegTestParams. This is a refactor and doesn't change functionality. Related to bitcoin#8994 Tree-SHA512: 79771d729a63a720e743a9c77d5e2d80369f072d66202a43c1304e83a7d0ef7c6103d4968a03aea9666cc89a7203c618da972124a677b38cfe62ddaeb28f9f5d
6fa901f Don't edit Chainparams after initialization (Jorge Timón) 980b38f MOVEONLY: Move versionbits info out of versionbits.o (Jorge Timón) Pull request description: This encapsulates the "-vbparams" option, which is only meant for regtest, directly on CRegTestParams. This is a refactor and doesn't change functionality. Related to bitcoin#8994 Tree-SHA512: 79771d729a63a720e743a9c77d5e2d80369f072d66202a43c1304e83a7d0ef7c6103d4968a03aea9666cc89a7203c618da972124a677b38cfe62ddaeb28f9f5d
* Merge bitcoin#13311: Don't edit Chainparams after initialization 6fa901f Don't edit Chainparams after initialization (Jorge Timón) 980b38f MOVEONLY: Move versionbits info out of versionbits.o (Jorge Timón) Pull request description: This encapsulates the "-vbparams" option, which is only meant for regtest, directly on CRegTestParams. This is a refactor and doesn't change functionality. Related to bitcoin#8994 Tree-SHA512: 79771d729a63a720e743a9c77d5e2d80369f072d66202a43c1304e83a7d0ef7c6103d4968a03aea9666cc89a7203c618da972124a677b38cfe62ddaeb28f9f5d * Resolve Merge with bitcoin#13311 * Incorporated review changes * Apply suggestions from code review * Update src/chainparams.cpp * Update src/chainparams.cpp Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com> Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
This encapsulates the "-vbparams" option, which is only meant for regtest, directly on CRegTestParams.
This is a refactor and doesn't change functionality.
Related to #8994