diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -149,9 +149,10 @@ DisconnectResult DisconnectBlock(const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view); - bool ConnectBlock(const Config &config, const CBlock &block, - CValidationState &state, CBlockIndex *pindex, - CCoinsViewCache &view, bool fJustCheck = false); + bool ConnectBlock(const CBlock &block, CValidationState &state, + CBlockIndex *pindex, CCoinsViewCache &view, + const CChainParams ¶ms, + BlockValidationOptions options, bool fJustCheck = false); // Block disconnection on our pcoinsTip: bool DisconnectTip(const Config &config, CValidationState &state, @@ -1658,16 +1659,17 @@ * done; ConnectBlock() can fail if those validity checks fail (among other * reasons). */ -bool CChainState::ConnectBlock(const Config &config, const CBlock &block, - CValidationState &state, CBlockIndex *pindex, - CCoinsViewCache &view, bool fJustCheck) { +bool CChainState::ConnectBlock(const CBlock &block, CValidationState &state, + CBlockIndex *pindex, CCoinsViewCache &view, + const CChainParams ¶ms, + BlockValidationOptions options, + bool fJustCheck) { AssertLockHeld(cs_main); assert(pindex); assert(*pindex->phashBlock == block.GetHash()); int64_t nTimeStart = GetTimeMicros(); - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); + const Consensus::Params &consensusParams = params.GetConsensus(); // Check it again in case a previous version let a bad block in // NOTE: We don't currently (re-)invoke ContextualCheckBlock() or @@ -1683,8 +1685,7 @@ // re-enforce that rule here (at least until we make it impossible for // GetAdjustedTime() to go backward). if (!CheckBlock(block, state, consensusParams, - BlockValidationOptions(config) - .withCheckPoW(!fJustCheck) + options.withCheckPoW(!fJustCheck) .withCheckMerkleRoot(!fJustCheck))) { if (state.CorruptionPossible()) { // We don't write down blocks to disk if they may have been @@ -1964,8 +1965,7 @@ return true; } - if (!WriteUndoDataForBlock(blockundo, state, pindex, - config.GetChainParams())) { + if (!WriteUndoDataForBlock(blockundo, state, pindex, params)) { return false; } @@ -2443,8 +2443,8 @@ DisconnectedBlockTransactions &disconnectpool) { AssertLockHeld(cs_main); - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); + const CChainParams ¶ms = config.GetChainParams(); + const Consensus::Params &consensusParams = params.GetConsensus(); assert(pindexNew->pprev == chainActive.Tip()); // Read block from disk. @@ -2470,7 +2470,8 @@ (nTime2 - nTime1) * MILLI, nTimeReadFromDisk * MICRO); { CCoinsViewCache view(pcoinsTip.get()); - bool rv = ConnectBlock(config, blockConnecting, state, pindexNew, view); + bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, params, + BlockValidationOptions(config)); GetMainSignals().BlockChecked(blockConnecting, state); if (!rv) { if (state.IsInvalid()) { @@ -4155,7 +4156,8 @@ FormatStateMessage(state)); } - if (!g_chainstate.ConnectBlock(config, block, state, &indexDummy, viewNew, + if (!g_chainstate.ConnectBlock(block, state, &indexDummy, viewNew, + config.GetChainParams(), validationOptions, true)) { return false; } @@ -4589,8 +4591,8 @@ int nCheckLevel, int nCheckDepth) { LOCK(cs_main); - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); + const CChainParams ¶ms = config.GetChainParams(); + const Consensus::Params &consensusParams = params.GetConsensus(); if (chainActive.Tip() == nullptr || chainActive.Tip()->pprev == nullptr) { return true; @@ -4726,8 +4728,8 @@ "VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); } - if (!g_chainstate.ConnectBlock(config, block, state, pindex, - coins)) { + if (!g_chainstate.ConnectBlock(block, state, pindex, coins, params, + BlockValidationOptions(config))) { return error("VerifyDB(): *** found unconnectable block at %d, " "hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(),