Skip to content

Commit 4e38217

Browse files
committed
Chainparams: Refactor: Remove redundant HashGenesisBlock() getter
1 parent c8a1350 commit 4e38217

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
@@ -41,7 +41,6 @@ class CChainParams
4141
};
4242

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

src/init.cpp

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

609609
// ********************************************************* Step 2: parameter interactions
610+
const CChainParams& chainparams = Params();
610611

611612
// Set this early so that parameter interactions go to console
612613
fPrintToConsole = GetBoolArg("-printtoconsole", false);
@@ -699,8 +700,8 @@ bool AppInit2(boost::thread_group& threadGroup)
699700
InitWarning(_("Warning: Unsupported argument -benchmark ignored, use -debug=bench."));
700701

701702
// Checkmempool and checkblockindex default to true in regtest mode
702-
mempool.setSanityCheck(GetBoolArg("-checkmempool", Params().DefaultConsistencyChecks()));
703-
fCheckBlockIndex = GetBoolArg("-checkblockindex", Params().DefaultConsistencyChecks());
703+
mempool.setSanityCheck(GetBoolArg("-checkmempool", chainparams.DefaultConsistencyChecks()));
704+
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
704705
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
705706

706707
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
@@ -1043,7 +1044,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10431044

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

10491050
// 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)