-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Chainparams: Separate globals and depedendent functions #6359
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
Conversation
de0c715 to
4f9a138
Compare
4f9a138 to
7901a6a
Compare
Also remove SelectBaseParamsFromCommandLine and SelectParamsFromCommandLine
7901a6a to
db85b3d
Compare
|
Since I'm still working on this...closing for now. I mainly wanted to ping @theuni and what is here works and is enough to start receiving feedback. |
|
@jtimon I'm not sure it's worth the complication of a factory here. Given that all chainparams and consensusparams are immutable, why not just pass around new instances when necessary? That should still be cheap, and much simpler? Especially given the trend to pass the params around as necessary rather than call Params() directly. Something like: static CBaseChainParams::Network nCurrentParams = CBaseChainParams::MAX_NETWORK_TYPES;
const CChainParams Params() {
switch (nCurrentParams) {
case CBaseChainParams::MAIN:
return CChainParams(CMainParams());
case CBaseChainParams::TESTNET:
return CChainParams(CTestNetParams());
case CBaseChainParams::REGTEST:
return CChainParams(CRegTestParams());
default:
assert(false && "Unimplemented network");
return CChainParams(CMainParams());
}
}
void SelectParams(CBaseChainParams::Network network) {
SelectBaseParams(network);
nCurrentParams = network;
}Hell, since there are no virtual functions left (nor should there be), we could even do away with the inheritance and just make CBaseChainParams::Network a ctor arg for CChainParams. |
|
The main point of the factory is that it is not on globals/ because once we're finished "passing chainparams around" there should be no need for any global at all: You either take it as parameter or use the factory (this includes removing the SelectParams from But if copying the object in the factory (like you do with the The enum doesn't scale very well once you go beyond -testnet and -regtest (see #5229 in fact, I'm preparing a PR to add infinite new testing altchains). The same happens with the single constructor parameter. |
|
@theuni I've been exploring your suggestion and it's not so straight-forward as you may think. |
This shares the first commit with #6230.
This is an alternative to theuni@123f3b0 which @theuni wasn't even proposing yet. But I would like your feedback on the factory and the container (which are shared with #6068 ).
This is blocking #6229 and #5229.
EDIT:
The fixup commit cleaning up the includes
may make more sense after more of #5970 (for example, #6163, we're not that far away from making miner.cpp independent from the chainparams globals)is left for later.