Skip to content

Commit 5f8cd7b

Browse files
committed
validation: Remove global ::ActivateBestChain
Instead use CChainState::ActivateBestChain, which is what the global one calls anyway.
1 parent 2a69647 commit 5f8cd7b

File tree

5 files changed

+9
-18
lines changed

5 files changed

+9
-18
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ void static ProcessGetBlockData(CNode& pfrom, Peer& peer, const CChainParams& ch
17001700
} // release cs_main before calling ActivateBestChain
17011701
if (need_activate_chain) {
17021702
BlockValidationState state;
1703-
if (!ActivateBestChain(state, chainparams, a_recent_block)) {
1703+
if (!::ChainstateActive().ActivateBestChain(state, chainparams, a_recent_block)) {
17041704
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString());
17051705
}
17061706
}
@@ -2960,7 +2960,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
29602960
a_recent_block = most_recent_block;
29612961
}
29622962
BlockValidationState state;
2963-
if (!ActivateBestChain(state, m_chainparams, a_recent_block)) {
2963+
if (!::ChainstateActive().ActivateBestChain(state, m_chainparams, a_recent_block)) {
29642964
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString());
29652965
}
29662966
}

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ static RPCHelpMan invalidateblock()
16031603
InvalidateBlock(state, Params(), pblockindex);
16041604

16051605
if (state.IsValid()) {
1606-
ActivateBestChain(state, Params());
1606+
::ChainstateActive().ActivateBestChain(state, Params());
16071607
}
16081608

16091609
if (!state.IsValid()) {
@@ -1643,7 +1643,7 @@ static RPCHelpMan reconsiderblock()
16431643
}
16441644

16451645
BlockValidationState state;
1646-
ActivateBestChain(state, Params());
1646+
::ChainstateActive().ActivateBestChain(state, Params());
16471647

16481648
if (!state.IsValid()) {
16491649
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
185185
}
186186

187187
BlockValidationState state;
188-
if (!ActivateBestChain(state, chainparams)) {
188+
if (!::ChainstateActive().ActivateBestChain(state, chainparams)) {
189189
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
190190
}
191191

src/validation.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,10 +2899,6 @@ bool CChainState::ActivateBestChain(BlockValidationState &state, const CChainPar
28992899
return true;
29002900
}
29012901

2902-
bool ActivateBestChain(BlockValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
2903-
return ::ChainstateActive().ActivateBestChain(state, chainparams, std::move(pblock));
2904-
}
2905-
29062902
bool CChainState::PreciousBlock(BlockValidationState& state, const CChainParams& params, CBlockIndex *pindex)
29072903
{
29082904
{
@@ -4681,7 +4677,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
46814677
// Activate the genesis block so normal node progress can continue
46824678
if (hash == chainparams.GetConsensus().hashGenesisBlock) {
46834679
BlockValidationState state;
4684-
if (!ActivateBestChain(state, chainparams, nullptr)) {
4680+
if (!::ChainstateActive().ActivateBestChain(state, chainparams, nullptr)) {
46854681
break;
46864682
}
46874683
}

src/validation.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@ void StopScriptCheckWorkerThreads();
167167
* @returns The tx if found, otherwise nullptr
168168
*/
169169
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
170-
/**
171-
* Find the best known block, and make it the tip of the block chain
172-
*
173-
* May not be called with cs_main held. May not be called in a
174-
* validationinterface callback.
175-
*/
176-
bool ActivateBestChain(BlockValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
177170
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
178171

179172
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
@@ -648,6 +641,8 @@ class CChainState
648641
void PruneAndFlush();
649642

650643
/**
644+
* Find the best known block, and make it the tip of the block chain
645+
*
651646
* Make the best chain active, in multiple steps. The result is either failure
652647
* or an activated best chain. pblock is either nullptr or a pointer to a block
653648
* that is already loaded (to avoid loading it again from disk).
@@ -664,7 +659,7 @@ class CChainState
664659
bool ActivateBestChain(
665660
BlockValidationState& state,
666661
const CChainParams& chainparams,
667-
std::shared_ptr<const CBlock> pblock) LOCKS_EXCLUDED(cs_main);
662+
std::shared_ptr<const CBlock> pblock = nullptr) LOCKS_EXCLUDED(cs_main);
668663

669664
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
670665

0 commit comments

Comments
 (0)