Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Oct 29, 2015

This makes it simpler for people to create new testchains in their own branches by removing the need to create a new static global variable for the new chains.

It also prepares chainparams and chainparamsbase to be cleaned out of globals by moving the globals and related functions (Params(), SelectParams(), etc) outside, maybe to globals/server.o and globals/common.o respectively.

But that would need another PR after this, something @theuni has been wanting to do for some time.
I would prefer to do this first to be able to leave the 2 factories (which don't need to depend on any global) where they are.
Part of #6382

@gmaxwell
Copy link
Contributor

This adds news without frees. I really don't think making this non-static is the right thing to do.

@jtimon
Copy link
Contributor Author

jtimon commented Oct 29, 2015

Moved the containers from extern back to static.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably there's a better example of tests that don't have to depend on the chainparam globals (in this case cGlobalSwitchingChainParams) anymore to make sure they test the same as when CBaseChainParams::MAIN is selected.
Note how the const for the params' reference wasn't possible before.

@jtimon
Copy link
Contributor Author

jtimon commented Nov 4, 2015

Added some commits to replace Container with boost::scoped_pointer. That also reduces the total diff (by not adding a new file), which is nice.
I'm ready to squash if people are happy with boost::scoped_pointer

@dcousens
Copy link
Contributor

dcousens commented Nov 5, 2015

utACK

@dcousens
Copy link
Contributor

dcousens commented Nov 5, 2015

Nice work @jtimon

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from 34173db to f4d308a Compare November 10, 2015 14:58
@jtimon
Copy link
Contributor Author

jtimon commented Nov 10, 2015

Squashed.

Copy link
Member

Choose a reason for hiding this comment

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

This looks dangerous, as it destroys the chainparams object created by the previous caller. Can you either document this, or switch to a solution that doesn't need that (for example, keeping a std::map<string, CChainParams)?

@jtimon
Copy link
Contributor Author

jtimon commented Nov 28, 2015

@sipa good point. I would prefer to just remove all its uses (now the factory can be used directly instead) than to think much about solving that problem though (maybe there's not so many calls at this point, I will check).

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from 5d9e172 to dbaf458 Compare November 28, 2015 14:06
@jtimon
Copy link
Contributor Author

jtimon commented Nov 28, 2015

Added a commit to get rid of CChainParams& Params(std::string). It's not very big (+18 -23) but it required me to rebase.

@sipa
Copy link
Member

sipa commented Nov 28, 2015

test/miner_tests.cpp:62 needs the old function still.

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from dbaf458 to c81fd49 Compare November 28, 2015 16:45
@jtimon
Copy link
Contributor Author

jtimon commented Nov 28, 2015

Oops, fixed.

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch 2 times, most recently from 2e57103 to fd6893d Compare November 29, 2015 23:18
@jtimon
Copy link
Contributor Author

jtimon commented Nov 29, 2015

Rebased(1)

@dcousens
Copy link
Contributor

re-ACK

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from fd6893d to c64d533 Compare November 30, 2015 11:33
@jtimon
Copy link
Contributor Author

jtimon commented Nov 30, 2015

@MarcoFalke Thanks for the heads up, build fixed.

@maflcko
Copy link
Member

maflcko commented Dec 2, 2015

Needs rebase due to #7128

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from c64d533 to d4bb7a8 Compare December 3, 2015 11:49
@jtimon
Copy link
Contributor Author

jtimon commented Dec 3, 2015

Rebased(2) [2 since I started counting for this particular PR. But although the commit says may 22, I've been trying to introduce a proper factory since much longer, at the very least since Nov 6, 2014 see #5229. I've been rebasing maintaining it in one way or another since then, but, still, I'll pretend I understand why this is not ready for 0.12 and that #7128 has been merged first. I'll keep rebasing this particular PR until it's finally merged or nacked, but I'm afraid I won't be able to make this kind of promise many more times].

Copy link
Member

Choose a reason for hiding this comment

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

I don't like this change, it is useful to have the port numbers for both networks in the help output
(and we have the same for -port)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I don't like special cases for testnet3 (or any other chain), which I usually find with rgrep "test" or rgrep CBaseChainParams::TESTNET.
Maybe we can loop through all the default ports for each supported chain as in
jtimon@28d961f ?
I mean, that would require something like jtimon@042fdb0 first.

Copy link
Member

Choose a reason for hiding this comment

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

As said, we're doing exactly the same for -port. What makes -rpcport different? #7128 unified these.

Looping through all networks would be overkill, there's no good reason to list regtest here, which is hidden (unless --help-debug). I think the current solution is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@laanwj what about jtimon@dd35471 ?
This way you can bitcoind -testnet --help but bitcoind -regtest --help too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rewarding unification, the change in port was also introduced only 5 days ago in #6961

Copy link
Member

Choose a reason for hiding this comment

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

This way you can bitcoind -testnet --help but bitcoind -regtest --help too.

I don't think that is better than just listing both in the standard help message. Parametrizing the help message on the network, I dunno, that's not something I'd expect as user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That can be documented, but I'll just restore the old messages and make another local variable for testnet3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, 2 more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding looping and not wanting to show regtest's information, we could easily do that just by leaving regtest out of supportedChains (see jtimon@160d874#diff-64cbe1ad5465e13bc59ee8bb6f3de2e7R20 ). Although that would also leave it out from jtimon@160d874#diff-de33fb0129cd5121c7098035527b26fdR14 and jtimon@28d961f , which is probably not a big deal. The special case for testnet3 can be solved by replacing a "main and testnet" enumaration whether we loop around 2 or 3 elements.
Just a thought. Or we can just leave it as it is, it's just I thought that I had when I was paranoid about jtimon@28d961f maybe being controversial (as a "too altcoinish" commit) and I just remembered.
Of course, that can be done later if it's done.

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from dd35471 to d7938c8 Compare December 3, 2015 19:57
@jtimon
Copy link
Contributor Author

jtimon commented Dec 3, 2015

Restored the testnet3 special case as requested by @laanwj

Copy link
Member

Choose a reason for hiding this comment

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

Where is the !?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason we we're using !testnet, which is the same as main and !!main, but the opposite of !!testnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to have solved it ages ago in jtimon@3d03f15 (#6423) but that commit depended on the cursed PR #6068 (just as cursed as its several predecessors).

Copy link
Member

Choose a reason for hiding this comment

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

In theory it's not defined for main, it's defined for testnet/regtest only;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What that text refers to, is that users aren't currently allowed to -acceptnonstdtxn=true on mainnet, they can only set -acceptnonstdtxn=false in testnet/regtest, which makes the fact that the displayed default is false (when in testnet/regtest the default is actually true) even more stupid.
I wanted to have solved this in jtimon@a4b28c4 but it depends on the previously mentioned commit.

Copy link
Member

Choose a reason for hiding this comment

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

What about default: %u -> default: %u (testnet), default: %u (regtest)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really think we should solve this by allowing -acceptnonstdtxn=true on mainnet. See jtimon@a4b28c4

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from d7938c8 to 2cffa7f Compare December 3, 2015 20:29
@dcousens
Copy link
Contributor

dcousens commented Dec 3, 2015

re-utACK

@jtimon
Copy link
Contributor Author

jtimon commented Jan 7, 2016

ping

@jtimon
Copy link
Contributor Author

jtimon commented Jan 13, 2016

Rebased (3)

@dcousens
Copy link
Contributor

re-ACK bd13782

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from bd13782 to 21f4629 Compare February 20, 2016 04:11
@jtimon
Copy link
Contributor Author

jtimon commented Feb 20, 2016

Rebase(4)

@jtimon jtimon force-pushed the chainparams-factory-0.12.99 branch from c3fdc95 to 670a464 Compare February 22, 2016 19:18
@jtimon
Copy link
Contributor Author

jtimon commented Feb 26, 2016

This is way older than "Oct 29, 2015", @laanwj can you please merge it or close it?

@jtimon jtimon closed this Mar 3, 2016
@laanwj
Copy link
Member

laanwj commented Mar 3, 2016

I'm not convinced of the need for this. At least to me it doesn't really make the code easier to understand or follow.

Do you need this for anything specific?

@jtimon
Copy link
Contributor Author

jtimon commented Mar 3, 2016

I've provided many examples of how this could be useful in the past (including the sizetest testchain, sorry, I don’t have the pr number at hand). This also allows to remove effectively-global-variables from chainparams (without moving the factory out) as discussed very long ago with @theuni.
Hopefully my refactors will make more sense as part of bitcoin jt once it starts implementing extra functionality in minimal ways (thanks to the previous refactors). And hopefully somebody will look at that branch and ask for things from it to be backported to bitcoin.

Thank you for asking about what you don't understand, even if it's very late. A "no" is always better than continued silence.

@laanwj
Copy link
Member

laanwj commented Mar 3, 2016

Thank you for asking about what you don't understand, even if it's very late. A "no" is always better than continued silence.

Yes, sorry for that. I'm just very busy. I have trouble keeping up with all the pulls, and I need to prioritize things that fix bugs or address immediate issues to things that are more speculative like refactors. I wish it was different, and we had a paid full-time team on this and it didn't rest for such a large part on my shoulders :(

jtimon added a commit to jtimon/bitcoin that referenced this pull request Mar 11, 2016
jtimon pushed a commit to jtimon/bitcoin that referenced this pull request Mar 11, 2016
jtimon referenced this pull request in sipa/bitcoin Apr 6, 2016
Rebased by Pieter Wuille.
Cleanup by Matt Corallo.
@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.

7 participants