Skip to content

Commit ea2b425

Browse files
committed
Merge pull request #5997
4e38217 Chainparams: Refactor: Remove redundant HashGenesisBlock() getter (Jorge Timón)
2 parents 622e3c9 + 4e38217 commit ea2b425

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/chainparams.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CChainParams
4040
};
4141

4242
const Consensus::Params& GetConsensus() const { return consensus; }
43-
const uint256& HashGenesisBlock() const { return consensus.hashGenesisBlock; }
4443
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
4544
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
4645
int GetDefaultPort() const { return nDefaultPort; }

src/init.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ bool AppInit2(boost::thread_group& threadGroup)
602602
#endif
603603

604604
// ********************************************************* Step 2: parameter interactions
605+
const CChainParams& chainparams = Params();
605606

606607
// Set this early so that parameter interactions go to console
607608
fPrintToConsole = GetBoolArg("-printtoconsole", false);
@@ -694,8 +695,8 @@ bool AppInit2(boost::thread_group& threadGroup)
694695
InitWarning(_("Warning: Unsupported argument -benchmark ignored, use -debug=bench."));
695696

696697
// Checkmempool and checkblockindex default to true in regtest mode
697-
mempool.setSanityCheck(GetBoolArg("-checkmempool", Params().DefaultConsistencyChecks()));
698-
fCheckBlockIndex = GetBoolArg("-checkblockindex", Params().DefaultConsistencyChecks());
698+
mempool.setSanityCheck(GetBoolArg("-checkmempool", chainparams.DefaultConsistencyChecks()));
699+
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
699700
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
700701

701702
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
@@ -1038,7 +1039,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10381039

10391040
// If the loaded chain has a wrong genesis, bail out immediately
10401041
// (we're likely using a testnet datadir, or the other way around).
1041-
if (!mapBlockIndex.empty() && mapBlockIndex.count(Params().HashGenesisBlock()) == 0)
1042+
if (!mapBlockIndex.empty() && mapBlockIndex.count(chainparams.GetConsensus().hashGenesisBlock) == 0)
10421043
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
10431044

10441045
// Initialize the block index (no-op if non-empty database was already loaded)

src/main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ static int64_t nTimeTotal = 0;
16801680

16811681
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck)
16821682
{
1683+
const CChainParams& chainparams = Params();
16831684
AssertLockHeld(cs_main);
16841685
// Check it again in case a previous version let a bad block in
16851686
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck))
@@ -1691,7 +1692,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
16911692

16921693
// Special case for the genesis block, skipping connection of its transactions
16931694
// (its coinbase is unspendable)
1694-
if (block.GetHash() == Params().HashGenesisBlock()) {
1695+
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
16951696
if (!fJustCheck)
16961697
view.SetBestBlock(pindex->GetBlockHash());
16971698
return true;
@@ -2541,8 +2542,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
25412542

25422543
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev)
25432544
{
2545+
const Consensus::Params& consensusParams = Params().GetConsensus();
25442546
uint256 hash = block.GetHash();
2545-
if (hash == Params().HashGenesisBlock())
2547+
if (hash == consensusParams.hashGenesisBlock)
25462548
return true;
25472549

25482550
assert(pindexPrev);
@@ -2612,6 +2614,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
26122614

26132615
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex)
26142616
{
2617+
const CChainParams& chainparams = Params();
26152618
AssertLockHeld(cs_main);
26162619
// Check for duplicate
26172620
uint256 hash = block.GetHash();
@@ -2632,7 +2635,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
26322635

26332636
// Get prev block index
26342637
CBlockIndex* pindexPrev = NULL;
2635-
if (hash != Params().HashGenesisBlock()) {
2638+
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
26362639
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
26372640
if (mi == mapBlockIndex.end())
26382641
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
@@ -3119,6 +3122,7 @@ bool InitBlockIndex() {
31193122

31203123
bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
31213124
{
3125+
const CChainParams& chainparams = Params();
31223126
// Map of disk positions for blocks with unknown parent (only used for reindex)
31233127
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent;
31243128
int64_t nStart = GetTimeMillis();
@@ -3164,7 +3168,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
31643168

31653169
// detect out of order blocks, and store them for later
31663170
uint256 hash = block.GetHash();
3167-
if (hash != Params().HashGenesisBlock() && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) {
3171+
if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) {
31683172
LogPrint("reindex", "%s: Out of order block %s, parent %s not known\n", __func__, hash.ToString(),
31693173
block.hashPrevBlock.ToString());
31703174
if (dbp)
@@ -3179,7 +3183,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
31793183
nLoaded++;
31803184
if (state.IsError())
31813185
break;
3182-
} else if (hash != Params().HashGenesisBlock() && mapBlockIndex[hash]->nHeight % 1000 == 0) {
3186+
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
31833187
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
31843188
}
31853189

@@ -3221,6 +3225,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
32213225

32223226
void static CheckBlockIndex()
32233227
{
3228+
const Consensus::Params& consensusParams = Params().GetConsensus();
32243229
if (!fCheckBlockIndex) {
32253230
return;
32263231
}
@@ -3263,7 +3268,7 @@ void static CheckBlockIndex()
32633268
// Begin: actual consistency checks.
32643269
if (pindex->pprev == NULL) {
32653270
// Genesis block checks.
3266-
assert(pindex->GetBlockHash() == Params().HashGenesisBlock()); // Genesis block's hash must match.
3271+
assert(pindex->GetBlockHash() == consensusParams.hashGenesisBlock); // Genesis block's hash must match.
32673272
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
32683273
}
32693274
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)

0 commit comments

Comments
 (0)