-
Notifications
You must be signed in to change notification settings - Fork 38.7k
CTestNetParams and CRegTestParams extend directly from CChainParams #6381
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
CTestNetParams and CRegTestParams extend directly from CChainParams #6381
Conversation
421de17 to
7cc689e
Compare
|
Seems fairly trivial and clean. Tested on regtest, testnet and mainnet. |
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'd rather not see the 'data' (the actual prefix bytes) move to code. Can you pass them in as parameters instead, and call this function from each of the constructors?
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 we should only keep a base58PrefixStyle here and move everything else to base58.o in a later PR.
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 think that's a good idea. All chain-specific data should be here, IMHO. Minimize the number of places where code needs to be changed to add a new chain.
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.
Exactly, that's what I'm doing in #6382.
To create a new chain you just choose one of the existing base58Prefix styles and you're good to go.
Unless you need to create a new base58Prefix style...when is that a good idea anyway?
In any case, it seems you're not against anything I'm doing here (which reduces the number of places where code needs to be changed to add a new chain), but you would prefer that I go beyond this with respect to base58 prefixes.
To me the next step is decoupling base58 from Params() global-like function, but that's not as simple as it may seem.
Things can be improved in later PRs: here I'm doing the minimum to eliminate inheritance between the different CChainParams implementations.
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 consider the base58 prefixes to be a property of a chain, and something that should be unique to it. I don't see why a new chain should keep using the base58 style of another chain.
So, no, I think the actual prefixes should stay right where they are. Moving them to a different function feels like unnecessarily changing data into code, and moving it to a different file is even worse.
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 you're too focussed on DRY to see the bigger picture: the reason you don't want to repeat yourself is because if the same logic is implemented in several places, you don't want to change two things when improving one. But this is not the case here: it's simple data that happens to be the same for both chains.
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 I find worse is the fact that chain-specific data used to be nicely grouped per chain. This breaks that for no good reason.
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.
There's nothing wrong with not repeating yourself either (or I've failed to
understand what is wrong with it. I think that the fact that testnet and
regtest is what is historical and there's no need to have different
prefixes with each chain. In fact, as said, it doesn't scale. For example,
I'm creating N new chains for sizetest, should they have different
prefixes? IMO either main or test prefixes are fine for it, there's really
no good reason to ever introduce a third one (or I haven't hear it yet).
On Jul 10, 2015 12:03 AM, "Pieter Wuille" [email protected] wrote:
In src/chainparams.cpp
#6381 (comment):
- * database.
- * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
- * CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
- * CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
- * CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
- * vMerkleTree: 4a5e1e
- */
+static CBlock CreateGenesisBlock(uint32_t nTime=1231006505, uint32_t nNonce=2083236893, uint32_t nBits=0x1d00ffff, int32_t nVersion=1, const CAmount& genesisReward=50 * COIN)
+{- const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
- CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
- return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
+}
+static void AssignBase58PrefixStyle(std::vector* base58Prefixes, Base58PrefixStyle base58PrefixStyle)
The fact that regtest and testnet use the same style addresses is
historical IMHO. There is nothing wrong with copying the values - they just
happen to have the values, for unrelated reasons. Maybe some day we want to
change the regtest ones without changing the testnet one.—
Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/6381/files#r34309159.
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 odd to me. I think different network should have different prefixes. Otherwise you risk using the wrong address on the wrong chain...
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 you always use the same prfix there's no such risk. Again, what could go
wrong with Alpha or Freicoin for not having unique (again, this doesn't
scale) prefixes?
In any case, I'm not only focusing on DRY: I just don't understand what's
wrong with the static function (assuming there's going to be prefixes
reuse).
On Jul 10, 2015 12:26 AM, "Pieter Wuille" [email protected] wrote:
In src/chainparams.cpp
#6381 (comment):
- * database.
- * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
- * CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
- * CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
- * CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
- * vMerkleTree: 4a5e1e
- */
+static CBlock CreateGenesisBlock(uint32_t nTime=1231006505, uint32_t nNonce=2083236893, uint32_t nBits=0x1d00ffff, int32_t nVersion=1, const CAmount& genesisReward=50 * COIN)
+{- const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
- CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
- return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
+}
+static void AssignBase58PrefixStyle(std::vector* base58Prefixes, Base58PrefixStyle base58PrefixStyle)
That seems odd to me. I think different network should have different
prefixes. Otherwise you risk using the wrong address on the wrong chain...—
Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/6381/files#r34311076.
|
Sorry for the rant above, @jtimon It took me a while to see your point of view. If you think that there is no need for more than 2 base58 styles, I fully agree with the approach you're taking. You see "use mainnet or testnet style addresses" as the chain property. I see "what prefix byte to use" as the chain property. |
…ChainParams ...instead of CMainParams and CTestNetParams respectively Do the same for CBaseChainParams. The inheritance was only reducing readibility in this case
7cc689e to
c4973aa
Compare
|
Needed rebase. |
|
Untested ACK. |
|
utACK.
That has always been a gripe of me, too. |
|
Yeah, I tried just using parametrized constructors for the factory in an alternate version of #6382 but the code didn't look better but actually worse (even using jtimon@25e99a0 in the unified constructor). Anyway, feel free to improve things later: this is just good enough for something like #6382. |
Agreed. That could be kind of useful for testing. |
…chy-0.11.99 Chainparams: Introduce CreateGenesisBlock() static function Chainparams: CTestNetParams and CRegTestParams extend directly from CChainParams ...instead of CMainParams and CTestNetParams respectively Do the same for CBaseChainParams. The inheritance was only reducing readibility in this case
Bitcoin 0.12 chainparams cleanups Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6222 - bitcoin/bitcoin#6381 - bitcoin/bitcoin#6473 - bitcoin/bitcoin#6242 Part of #2074.
Bitcoin 0.12 chainparams cleanups Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6222 - bitcoin/bitcoin#6381 - bitcoin/bitcoin#6473 - bitcoin/bitcoin#6242 Part of #2074.
As mentioned by @theuni on #6359 , the hierarchy between the different chainparam implementations is not necessary. I think that in fact it makes each of them less readable (since the leave part of their initialization to parent classes).
It also simplifies the introduction of new chains, like in #6382.