mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge bitcoin/bitcoin#21866: [Bundle 7/7] validation: Farewell, global Chainstate!
6f994882devalidation: Farewell, global Chainstate! (Carl Dong)972c5166eeqt/test: Reset chainman in ~ChainstateManager instead (Carl Dong)6c3b5dc0c1scripted-diff: tree-wide: Remove all review-only assertions (Carl Dong)3e82abb8ddtree-wide: Remove stray review-only assertion (Carl Dong)f323248abaqt/test: Use existing chainman in ::TestGUI (can be scripted-diff) (Carl Dong)6c15de129cscripted-diff: wallet/test: Use existing chainman (Carl Dong)ee0ab1e959fuzz: Initialize a TestingSetup for test_one_input (Carl Dong)0d61634c06scripted-diff: test: Use existing chainman in unit tests (Carl Dong)e197076219test: Pass in CoinsTip to ValidateCheckInputsForAllFlags (Carl Dong)4d99b61014test/miner_tests: Pass in chain tip to CreateBlockIndex (Carl Dong)f0dd5e6bb4test/util: Use existing chainman in ::PrepareBlock (Carl Dong)464c313e30init: Use existing chainman (Carl Dong) Pull request description: Based on: #21767 à la Mr. Sandman ``` Mr. Chainman, bring me a tip (bung, bung, bung, bung) Make it the most work that I've ever seen (bung, bung, bung, bung) Rewind old tip till we're at the fork point (bung, bung, bung, bung) Then tell it that it's time to call Con-nectTip Chainman, I'm so alone (bung, bung, bung, bung) No local objects to call my own (bung, bung, bung, bung) Please make sure I have a ref Mr. Chainman, bring me a tip! ``` This is the last bundle in the #20158 series. Thanks everyone for their diligent review. I would like to call attention to https://github.com/bitcoin/bitcoin/issues/21766, where a few leftover improvements were collated. - Remove globals: - `ChainstateManager g_chainman` - `CChainState& ChainstateActive()` - `CChain& ChainActive()` - Remove all review-only assertions. ACKs for top commit: jamesob: reACK6f994882debased on the contents of ariard: Code Review ACK6f99488. jnewbery: utACK6f994882deachow101: Code Review ACK6f994882deryanofsky: Code review ACK6f994882de. Tree-SHA512: 4052ea79360cf0efd81ad0ee3f982e1d93aab1837dcec75f875a56ceda085de078bb3099a2137935d7cc2222004ad88da94b605ef5efef35cb6bc733725debe6
This commit is contained in:
18
src/init.cpp
18
src/init.cpp
@@ -283,7 +283,7 @@ void Shutdown(NodeContext& node)
|
||||
init::UnsetGlobals();
|
||||
node.mempool.reset();
|
||||
node.fee_estimator.reset();
|
||||
node.chainman = nullptr;
|
||||
node.chainman.reset();
|
||||
node.scheduler.reset();
|
||||
|
||||
try {
|
||||
@@ -1175,8 +1175,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);
|
||||
|
||||
assert(!node.chainman);
|
||||
node.chainman = &g_chainman;
|
||||
ChainstateManager& chainman = *Assert(node.chainman);
|
||||
node.chainman = std::make_unique<ChainstateManager>();
|
||||
ChainstateManager& chainman = *node.chainman;
|
||||
|
||||
assert(!node.peerman);
|
||||
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),
|
||||
@@ -1381,7 +1381,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// If the loaded chain has a wrong genesis, bail out immediately
|
||||
// (we're likely using a testnet datadir, or the other way around).
|
||||
if (!chainman.BlockIndex().empty() &&
|
||||
!g_chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
}
|
||||
|
||||
@@ -1396,7 +1396,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
|
||||
// (otherwise we use the one already on disk).
|
||||
// This is called again in ThreadImport after the reindex completes.
|
||||
if (!fReindex && !::ChainstateActive().LoadGenesisBlock(chainparams)) {
|
||||
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock(chainparams)) {
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
}
|
||||
@@ -1545,21 +1545,21 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// ********************************************************* Step 8: start indexers
|
||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
|
||||
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex);
|
||||
if (!g_txindex->Start(::ChainstateActive())) {
|
||||
if (!g_txindex->Start(chainman.ActiveChainstate())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& filter_type : g_enabled_filter_types) {
|
||||
InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex);
|
||||
if (!GetBlockFilterIndex(filter_type)->Start(::ChainstateActive())) {
|
||||
if (!GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
||||
g_coin_stats_index = std::make_unique<CoinStatsIndex>(/* cache size */ 0, false, fReindex);
|
||||
if (!g_coin_stats_index->Start(::ChainstateActive())) {
|
||||
if (!g_coin_stats_index->Start(chainman.ActiveChainstate())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1607,7 +1607,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
|
||||
// No locking, as this happens before any background thread is started.
|
||||
boost::signals2::connection block_notify_genesis_wait_connection;
|
||||
if (::ChainActive().Tip() == nullptr) {
|
||||
if (chainman.ActiveChain().Tip() == nullptr) {
|
||||
block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(std::bind(BlockNotifyGenesisWait, std::placeholders::_2));
|
||||
} else {
|
||||
fHaveGenesis = true;
|
||||
|
||||
Reference in New Issue
Block a user