Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CheckBlockIndex to validation.cpp
Browse files Browse the repository at this point in the history
* The global fCheckBlockIndex is only used once and has no interaction.
* Update CheckBlockIndex function header to use Chainparams instead of
  consensusParams
Mark Erhardt committed Nov 11, 2019
1 parent a7aec7a commit 340acd0
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
@@ -1009,7 +1009,6 @@ bool AppInitParameterInteraction()
if (ratio != 0) {
mempool.setSanityCheck(1.0 / ratio);
}
fCheckBlockIndex = gArgs.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
fCheckpointsEnabled = gArgs.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);

hashAssumeValid = uint256S(gArgs.GetArg("-assumevalid", chainparams.GetConsensus().defaultAssumeValid.GetHex()));
2 changes: 1 addition & 1 deletion src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
fs::create_directories(m_path_root);
gArgs.ForceSetArg("-datadir", m_path_root.string());
ClearDatadirCache();
gArgs.ForceSetArg("-checkblockindex", "1");
SelectParams(chainName);
SeedInsecureRand();
gArgs.ForceSetArg("-printtoconsole", "0");
@@ -79,7 +80,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
SetupNetworking();
InitSignatureCache();
InitScriptExecutionCache();
fCheckBlockIndex = true;
static bool noui_connected = false;
if (!noui_connected) {
noui_connect();
18 changes: 9 additions & 9 deletions src/validation.cpp
Original file line number Diff line number Diff line change
@@ -115,7 +115,6 @@ std::atomic_bool fReindex(false);
bool fHavePruned = false;
bool fPruneMode = false;
bool fRequireStandard = true;
bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
size_t nCoinCacheUsage = 5000 * 300;
uint64_t nPruneTarget = 0;
@@ -2876,7 +2875,7 @@ bool CChainState::ActivateBestChain(BlockValidationState &state, const CChainPar
if (ShutdownRequested())
break;
} while (pindexNewTip != pindexMostWork);
CheckBlockIndex(chainparams.GetConsensus());
CheckBlockIndex(chainparams);

// Write changes periodically to disk, after relay.
if (!FlushStateToDisk(chainparams, state, FlushStateMode::PERIODIC)) {
@@ -3018,7 +3017,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParam
to_mark_failed = invalid_walk_tip;
}

CheckBlockIndex(chainparams.GetConsensus());
CheckBlockIndex(chainparams);

{
LOCK(cs_main);
@@ -3640,7 +3639,7 @@ bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValid
for (const CBlockHeader& header : headers) {
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
bool accepted = g_blockman.AcceptBlockHeader(header, state, chainparams, &pindex);
::ChainstateActive().CheckBlockIndex(chainparams.GetConsensus());
::ChainstateActive().CheckBlockIndex(chainparams);

if (!accepted) {
return false;
@@ -3689,7 +3688,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;

bool accepted_header = m_blockman.AcceptBlockHeader(block, state, chainparams, &pindex);
CheckBlockIndex(chainparams.GetConsensus());
CheckBlockIndex(chainparams);

if (!accepted_header)
return false;
@@ -3755,7 +3754,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block

FlushStateToDisk(chainparams, state, FlushStateMode::NONE);

CheckBlockIndex(chainparams.GetConsensus());
CheckBlockIndex(chainparams);

return true;
}
@@ -4497,7 +4496,7 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
// no tip due to m_chain being empty!
PruneBlockIndexCandidates();

CheckBlockIndex(params.GetConsensus());
CheckBlockIndex(params);
}
}

@@ -4727,8 +4726,9 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
return nLoaded > 0;
}

void CChainState::CheckBlockIndex(const Consensus::Params& consensusParams)
void CChainState::CheckBlockIndex(const CChainParams& chainparams)
{
static bool fCheckBlockIndex = gArgs.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
if (!fCheckBlockIndex) {
return;
}
@@ -4781,7 +4781,7 @@ void CChainState::CheckBlockIndex(const Consensus::Params& consensusParams)
// Begin: actual consistency checks.
if (pindex->pprev == nullptr) {
// Genesis block checks.
assert(pindex->GetBlockHash() == consensusParams.hashGenesisBlock); // Genesis block's hash must match.
assert(pindex->GetBlockHash() == chainparams.GetConsensus().hashGenesisBlock); // Genesis block's hash must match.
assert(pindex == m_chain.Genesis()); // The current active chain's genesis block must be this block.
}
if (!pindex->HaveTxsDownloaded()) assert(pindex->nSequenceId <= 0); // nSequenceId can't be set positive for blocks that aren't linked (negative is used for preciousblock)
3 changes: 1 addition & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
@@ -152,7 +152,6 @@ extern std::atomic_bool fReindex;
*/
extern bool g_parallel_script_checks;
extern bool fRequireStandard;
extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled;
extern size_t nCoinCacheUsage;
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
@@ -718,7 +717,7 @@ class CChainState {
*
* By default this only executes fully when using the Regtest chain; see: fCheckBlockIndex.
*/
void CheckBlockIndex(const Consensus::Params& consensusParams);
void CheckBlockIndex(const CChainParams& chainparams);

/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

0 comments on commit 340acd0

Please sign in to comment.