diff --git a/src/chain.h b/src/chain.h index 01011d54f19..98ba2202d97 100644 --- a/src/chain.h +++ b/src/chain.h @@ -210,6 +210,7 @@ class CBlockIndex int32_t nVersion; uint256 hashMerkleRoot; uint32_t nTime; + uint32_t block_height; uint32_t nBits; uint32_t nNonce; @@ -238,6 +239,7 @@ class CBlockIndex nVersion = 0; hashMerkleRoot = uint256(); nTime = 0; + block_height = 0; nBits = 0; nNonce = 0; } @@ -254,6 +256,7 @@ class CBlockIndex nVersion = block.nVersion; hashMerkleRoot = block.hashMerkleRoot; nTime = block.nTime; + block_height = block.block_height; nBits = block.nBits; nNonce = block.nNonce; } @@ -284,6 +287,7 @@ class CBlockIndex block.hashPrevBlock = pprev->GetBlockHash(); block.hashMerkleRoot = hashMerkleRoot; block.nTime = nTime; + block.block_height = block_height; block.nBits = nBits; block.nNonce = nNonce; return block; @@ -403,6 +407,9 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(hashPrev); READWRITE(hashMerkleRoot); READWRITE(nTime); + if (g_con_blockheightinheader) { + READWRITE(block_height); + } READWRITE(nBits); READWRITE(nNonce); } @@ -414,6 +421,7 @@ class CDiskBlockIndex : public CBlockIndex block.hashPrevBlock = hashPrev; block.hashMerkleRoot = hashMerkleRoot; block.nTime = nTime; + block.block_height = block_height; block.nBits = nBits; block.nNonce = nNonce; return block.GetHash(); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 64d73b28264..894cc884c49 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -4,9 +4,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include +#include +#include #include #include #include @@ -17,13 +18,13 @@ #include #include -static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) +static CBlock CreateGenesisBlock(const CScript& coinbase_sig, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) { CMutableTransaction txNew; txNew.nVersion = 1; txNew.vin.resize(1); txNew.vout.resize(1); - txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); + txNew.vin[0].scriptSig = coinbase_sig; txNew.vout[0].nValue = genesisReward; txNew.vout[0].scriptPubKey = genesisOutputScript; @@ -38,6 +39,12 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi return genesis; } +static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) +{ + CScript coinbase_sig = CScript() << 486604799 << CScriptNum(4) << std::vector((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); + return CreateGenesisBlock(coinbase_sig, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); +} + /** * Build the genesis block. Note that the output of its generation * transaction cannot be spent since it did not originally exist in the @@ -403,6 +410,7 @@ class CCustomParams : public CRegTestParams { { UpdateVersionBitsParametersFromArgs(args); + consensus.genesis_style = args.GetArg("-con_genesis_style", "default_style"); consensus.nSubsidyHalvingInterval = args.GetArg("-con_nsubsidyhalvinginterval", consensus.nSubsidyHalvingInterval); consensus.BIP16Exception = uint256S(args.GetArg("-con_bip16exception", "0x0")); consensus.BIP34Height = args.GetArg("-con_bip34height", consensus.BIP34Height); @@ -420,6 +428,10 @@ class CCustomParams : public CRegTestParams { consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0")); consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00")); + // Note: g_con_blockheightinheader is used instead of consensus.blockheight_in_header to avoid + // circular dependency + consensus.blockheight_in_header = g_con_blockheightinheader = gArgs.GetBoolArg("-con_blockheightinheader", false); + // All non-zero coinbase outputs must go to this scriptPubKey std::vector man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", "")); consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination @@ -457,12 +469,30 @@ class CCustomParams : public CRegTestParams { } } + void SetGenesisBlock() + { + if (consensus.genesis_style == "regtest2_style") { + // Same style as in https://github.com/bitcoin/bitcoin/pull/8994 + genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + + } else if (consensus.genesis_style == "default_style") { + CHashWriter h(SER_DISK, 0); + h << strNetworkID; + uint256 hash = h.GetHash(); + CScript coinbase_sig = CScript() << std::vector(hash.begin(), hash.end()); + genesis = CreateGenesisBlock(coinbase_sig, CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + + } else { + throw std::runtime_error(strprintf("%s: Unknown consensus.genesis_style %s.", __func__, consensus.genesis_style)); + } + } + public: CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args) { strNetworkID = chain; UpdateFromArgs(args); - genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + SetGenesisBlock(); consensus.hashGenesisBlock = genesis.GetHash(); } }; diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 09a5581bb8c..6ba9b071c53 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -21,9 +21,11 @@ void SetupChainParamsBaseOptions() gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " "This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS); + gArgs.AddArg("-con_genesis_style=