-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Improvements in CChainParams #3824
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
|
@jtimon You're creating a lot of minor pulls that depend on each other. |
|
@laanwj only this one is dependent on the others. The rest are valid independently, just related. So I have no problem putting them all on a single pull request, but to save me some pain, could you please tell me if there's any problem with each of the individual changes (or improvement, renaming of method...) before I do that? Note: It is the first time that I use git in a project with this level of concurrency in development so I appreciate your patience. |
|
Well people's opinion may vary but I generally like 'one pull request solves one issue'. Too granular makes indeed it hard to merge (especially if they're 'change the world' commits), but too fine and everyone loses track of the larger view of what you're trying to do. This may be just right, I just noticed a flood of pulls and thought I'd warn you :-) It does make sense to split up GUI and core changes. Merging GUI changes is much easier, in general. |
|
Thanks again for the feedback, much appreciated. Probably I should have referenced our previous discussion at #3812 |
|
I've putted them all together except the GUI change. |
src/chainparams.cpp
Outdated
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 chainparams accessing the OS, makes it an ugly dependency for people who want to use this module in other code. I prefer it to just contain constants.
|
Does this actually make the code clearer, though? Now when checking the various places regtest mode was special cased, you can see that a special case exists but you have no idea without rummaging through chainparams.cpp (reading all of it) when it will actually happen. Was this change motivated by some other work or do you think it's just clearer this way? |
|
I prefer the old code, NACK from me on this change. |
|
I really hate how we're assigning weird properties to regtest, and making them only accessible under IsRegTest(). Imho, these should just be separate command-line options or separate RPCs, instead of overloading their meaning for regtest. |
|
So to be clear: I consider this pullreq a step towards making special behaviour not hardcoded to regtest, but it's not enough. |
|
The motivation is to make it easier to create new modes. Particularly, I plan to create a mode where proof of work is completely replaced by signatures of a "centralized miner". Other full nodes can connect and validate, but only whoever can provide a valid scriptSig can produce new blocks. Also RegTest() global-like function feels a bit ugly to me, which brings me to some related questions I have: Shouldn't be TestNet() and RegTest() be methods of CChainParams? Maybe a virtual bool CChainParams::isNetwork(Network) could be a solution. |
|
Meh, all the same. I dislike explicit tests for particular modes. The high-level code should not need to know nor care about which mode is active. It should just care about its properties. |
|
Apart from the boost:hardware_concurrence call, ACK from me. |
|
Leaving aside the style issues for a moment - such a "centralised miner" mode seems pointless. You could just as well have a regular SQL database and dispose with the block chain algorithm entirely at that point? sipa: as I said, I feel like that's applying style theory over practice here. In practice, just testing properties of the mode simply makes the code harder to understand without improving modularity or maintainability in any real way. |
|
I think reading: if (Params().MineBlocksOnDemand()) is just as obvious as if (RegTest()) Though the question should really be: why is this behaviour specific to regtest at all? |
|
The former simply repeats logic redundantly: if (Params().MineBlocksOnDemand()) { The conditional tells you nothing beyond "this behaviour is network mode specific" and requires you to go hunting in order to find out more. if (RegTest()) { is much more informative - it tells you when that code path actually becomes active, in easy to read language. It's specific to regtest because that's the only time it would appear to be useful. If someone came up with another case where it was wanted (that doesn't involve weird entirely non-Bitcoinish uses) then it'd make sense to generalise it some more and document when it can happen with a comment. |
|
How is any of this different from RequireRPCPassword() ? It is true that the private chain is "non-bitcoinish" (related to off-chain transactions) and it's probably only useful with more changes that won't possibly get into bitcoin. I would just like to minimize the divergence from bitcoin's codebase. But still, this makes it easier to create more testing modes I honestly haven't thought about yet. Anyway, we should focus on the readability and maintainability, and I still think RegTest() is pretty ugly. Any thoughts on the consistency of the use of these global functions as opposed to methods in CChainParams interface? |
|
@mikehearn we can also change the comment to be non-redundant and avoid you to "hunt on chainparams.cpp" if that's the problem. if (Params().MineBlocksOnDemand()) { |
|
I'm not sure how |
|
As I understood it (and explained to @jtimon) the idea of ChainParams is to contain
Especially the second set of properties could made data-driven (moved to a configuration file) to make it possible to define your own testing modes. Using a clunky 'is a' operation like RegTest() breaks this. So IMO this pull is an improvement. @jtimon Please do document the new methods of CChainParams clearly with a comment: what does this flag do, and why would someone want to do that. @sipa +1 CChainParams should only contain constants. The boost concurrency call is not a constant and depends on the execution environment. |
|
Updates: -Non-constant value for default threads removed as suggested by @sipa |
|
ACK. Enough bikeshedding. |
|
Fixed typo "doesn't requires" -> "doesn't require" |
protocol.h instead of the other way around
|
paymentserver.cpp:502: error: "TestNet" was not declared in this scope |
|
This is the commit and line that breaks the PR: bdc83e8#diff-7823229685ea2f6633c45d94ebab1aa9R502 Feedback by @Diapolo welcomed. Could be replace with: If we want to support regtest, the following would be better: Another possibility is creating a new networkStr parameter and do something like this: In this case, I would have preferred that the NetworkStr parameter contained "testnet" instead of "test", but maybe it's too late to change that on details.network()? Thoughts? |
|
I created a mapping networkID -> Payment Protocol network name method as suggested by @wumpus on IRC instead of creating a new field in chainparams for that. |
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/f0a83fc256023f68cc046bd096de69f16ce9d394 for binaries and test log. |
|
ACK |
2 similar comments
|
ACK |
|
ACK |
f0a83fc Use Params().NetworkID() instead of TestNet() from the payment protocol (jtimon) 2871889 net.h was using std namespace through chainparams.h included in protocol.h (jtimon) c8c52de Replace virtual methods with static attributes, chainparams.h depends on protocol.h instead of the other way around (jtimon) a3d946e Get rid of TestNet() (jtimon) 6fc0fa6 Add RPCisTestNet chain parameter (jtimon) cfeb823 Add RequireStandard chain parameter (jtimon) 21913a9 Add AllowMinDifficultyBlocks chain parameter (jtimon) d754f34 Move majority constants to chainparams (jtimon) 8d26721 Get rid of RegTest() (jtimon) cb9bd83 Add DefaultCheckMemPool chain parameter (jtimon) 2595b9a Add DefaultMinerThreads chain parameter (jtimon) bfa9a1a Add MineBlocksOnDemand chain parameter (jtimon) 1712adb Add MiningRequiresPeers chain parameter (jtimon)
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.
@jtimon Are you sure this check is correct? Seems like a hack to use the 0 in DefaultMinerThreads() to query for regtest mode, no?
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's the point of this PR, not to have to check for regtest at all.
Right now the default is 0 for main and testnet, and 1 for regtest. But now you can create a testnet2 or regtest2 which defaults at 5, for example.
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.
Perhaps the comment shouldn't explicitly refer to regtest anymore either :)
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.
@mikehearn suggested that is was clearer since otherwise you need to go to chainparams to know if it's regtest behaviour, that's why I restored the old comments or added comments referencing regtest or testnet in some places.
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 principle a boolean 'MineWithMultipleThreads' would have been good enough here, as I don't see a realistic reason why a network would want '5 mining threads!'. Then again, that seems like bikeshed painting, this is fine.
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, since it's only regtest what uses 1 as default, a boolean would have served as well. an int seemed more generic, but it is true that the chances of it being used at all are almost null.
|
@jtimon, please stop mixing irc and github. I'm not the guy you're talking to on irc. |
|
I'm sorry, my mistake, I believe wumpus on irc is @laanwj here. |
|
@jtimon That's correct. |
f0a83fc Use Params().NetworkID() instead of TestNet() from the payment protocol (jtimon) 2871889 net.h was using std namespace through chainparams.h included in protocol.h (jtimon) c8c52de Replace virtual methods with static attributes, chainparams.h depends on protocol.h instead of the other way around (jtimon) a3d946e Get rid of TestNet() (jtimon) 6fc0fa6 Add RPCisTestNet chain parameter (jtimon) cfeb823 Add RequireStandard chain parameter (jtimon) 21913a9 Add AllowMinDifficultyBlocks chain parameter (jtimon) d754f34 Move majority constants to chainparams (jtimon) 8d26721 Get rid of RegTest() (jtimon) cb9bd83 Add DefaultCheckMemPool chain parameter (jtimon) 2595b9a Add DefaultMinerThreads chain parameter (jtimon) bfa9a1a Add MineBlocksOnDemand chain parameter (jtimon) 1712adb Add MiningRequiresPeers chain parameter (jtimon)
f0a83fc Use Params().NetworkID() instead of TestNet() from the payment protocol 2871889 net.h was using std namespace through chainparams.h included in protocol.h c8c52de Replace virtual methods with static attributes, chainparams.h depends on protocol.h instead of the other way around a3d946e Get rid of TestNet() 6fc0fa6 Add RPCisTestNet chain parameter cfeb823 Add RequireStandard chain parameter 21913a9 Add AllowMinDifficultyBlocks chain parameter d754f34 Move majority constants to chainparams 8d26721 Get rid of RegTest() cb9bd83 Add DefaultCheckMemPool chain parameter 2595b9a Add DefaultMinerThreads chain parameter bfa9a1a Add MineBlocksOnDemand chain parameter 1712adb Add MiningRequiresPeers chain parameter
Replace direct references to RegTest() with constant parameters on CChainParams interface.
EDIT: dependency merged