Merge a55904a80c into merged_master (Bitcoin PR bitcoin/bitcoin#21866)

Paying the piper for some lazy use of globals, including ones I added
in 8e770d3f21

Had to add another couple methods to interfaces::Chain
This commit is contained in:
Andrew Poelstra 2021-07-29 13:18:11 +00:00
commit 34da23bd1a
41 changed files with 270 additions and 365 deletions

View file

@ -293,7 +293,7 @@ void Shutdown(NodeContext& node)
init::UnsetGlobals();
node.mempool.reset();
node.fee_estimator.reset();
node.chainman = nullptr;
node.chainman.reset();
node.scheduler.reset();
node.reverification_scheduler.reset();
@ -1235,8 +1235,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(),
@ -1441,7 +1441,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?"));
}
@ -1456,7 +1456,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;
}
@ -1605,21 +1605,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;
}
}
@ -1667,7 +1667,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;
@ -1848,7 +1848,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
if (gArgs.GetBoolArg("-validatepegin", Params().GetConsensus().has_parent_chain)) {
uiInterface.InitMessage(_("Awaiting mainchain RPC warmup").translated);
}
if (!MainchainRPCCheck(true)) { //Initial check only
if (!MainchainRPCCheck(true, node.chainman.get())) { //Initial check only
const std::string err_msg = "ERROR: elements is set to verify pegins but cannot get a valid response from the mainchain daemon. Please check debug.log for more information.\n\nIf you haven't setup a bitcoind please get the latest stable version from https://bitcoincore.org/en/download/ or if you do not need to validate pegins set in your elements configuration validatepegin=0";
// We fail immediately if this node has RPC server enabled
if (gArgs.GetBoolArg("-server", false)) {
@ -1864,7 +1864,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// Start the lightweight block re-evaluation scheduler thread
node.reverification_scheduler->m_service_thread = std::thread([&] { util::TraceThread( "reevaluation_scheduler", [&] { node.reverification_scheduler->serviceQueue(); }); });
CScheduler::Function f2 = std::bind(&MainchainRPCCheck, false);
CScheduler::Function f2 = std::bind(&MainchainRPCCheck, false, node.chainman.get());
unsigned int check_rpc_every = gArgs.GetArg("-recheckpeginblockinterval", 120);
if (check_rpc_every) {
node.reverification_scheduler->scheduleEvery(f2, std::chrono::seconds(check_rpc_every));