Skip to content

Commit 6a07593

Browse files
instagibbsdongcarl
authored andcommitted
restore bitcoin regtest gen block using -genesis_style
- also regenerate test data for getblockstats
1 parent 0be3b22 commit 6a07593

File tree

6 files changed

+250
-232
lines changed

6 files changed

+250
-232
lines changed

src/chainparams.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ class CCustomParams : public CRegTestParams {
475475
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
476476
initialFreeCoins = gArgs.GetArg("-initialfreecoins", 0);
477477

478+
// Determines type of genesis block
479+
consensus.genesis_style = gArgs.GetArg("-con_genesis_style", "elements");
480+
478481
// Custom chains connect coinbase outputs to db by default
479482
consensus.connect_genesis_outputs = gArgs.GetArg("-con_connect_coinbase", true);
480483

@@ -512,16 +515,28 @@ class CCustomParams : public CRegTestParams {
512515
}
513516
}
514517

518+
void SetGenesisBlock() {
519+
if (consensus.genesis_style == "bitcoin") {
520+
// For compatibility with bitcoin (regtest)
521+
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
522+
} else if (consensus.genesis_style == "elements") {
523+
// Intended compatibility with Liquid v1 and elements-0.14.1
524+
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
525+
genesis = CreateGenesisBlock(CScript(commit), CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0);
526+
if (initialFreeCoins != 0) {
527+
AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), initialFreeCoins, CScript() << OP_TRUE);
528+
}
529+
} else {
530+
throw std::runtime_error(strprintf("Invalid -genesis_style (%s)", consensus.genesis_style));
531+
}
532+
}
533+
515534
public:
516535
CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args)
517536
{
518537
strNetworkID = chain;
519538
UpdateFromArgs(args);
520-
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
521-
genesis = CreateGenesisBlock(CScript(commit), CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0);
522-
if (initialFreeCoins != 0) {
523-
AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), initialFreeCoins, CScript() << OP_TRUE);
524-
}
539+
SetGenesisBlock();
525540
consensus.hashGenesisBlock = genesis.GetHash();
526541
}
527542
};

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void SetupChainParamsBaseOptions()
2727
gArgs.AddArg("-con_blocksubsidy", "Defines the amount of block subsidy to start with, at genesis block.", false, OptionsCategory::ELEMENTS);
2828
gArgs.AddArg("-con_connect_coinbase", "Connect outputs in genesis block to utxo database.", false, OptionsCategory::ELEMENTS);
2929
gArgs.AddArg("-con_blockheightinheader", "Whether the chain includes the block height directly in the header, for easier validation of block height in low-resource environments. (default: true)", false, OptionsCategory::CHAINPARAMS);
30+
gArgs.AddArg("-con_genesis_style=<style>", "Use genesis style <style> (default: elements). Results in genesis block compatibility with various networks. Allowed values: elements, bitcoin", true, OptionsCategory::ELEMENTS);
3031
}
3132

3233
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct Params {
8383
CAmount genesis_subsidy;
8484
bool connect_genesis_outputs;
8585
// g_con_blockheightinheader global hack instead of proper arg due to circular dep
86+
std::string genesis_style;
8687
};
8788
} // namespace Consensus
8889

0 commit comments

Comments
 (0)