mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 15:20:49 +01:00
refactor: init indexes, decouple 'Start()' from the creation step
No behavior change. The goal here is to group indexes, so we can perform the same initialization and verification process equally for all of them. The checks performed inside `StartIndexes` will be expanded in the subsequent commits.
This commit is contained in:
parent
2ebc7e68cc
commit
225e213110
3 changed files with 18 additions and 10 deletions
21
src/init.cpp
21
src/init.cpp
|
@ -1554,25 +1554,22 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
|
g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
|
||||||
if (!g_txindex->Start()) {
|
node.indexes.emplace_back(g_txindex.get());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& filter_type : g_enabled_filter_types) {
|
for (const auto& filter_type : g_enabled_filter_types) {
|
||||||
InitBlockFilterIndex([&]{ return interfaces::MakeChain(node); }, filter_type, cache_sizes.filter_index, false, fReindex);
|
InitBlockFilterIndex([&]{ return interfaces::MakeChain(node); }, filter_type, cache_sizes.filter_index, false, fReindex);
|
||||||
if (!GetBlockFilterIndex(filter_type)->Start()) {
|
node.indexes.emplace_back(GetBlockFilterIndex(filter_type));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
||||||
g_coin_stats_index = std::make_unique<CoinStatsIndex>(interfaces::MakeChain(node), /*cache_size=*/0, false, fReindex);
|
g_coin_stats_index = std::make_unique<CoinStatsIndex>(interfaces::MakeChain(node), /*cache_size=*/0, false, fReindex);
|
||||||
if (!g_coin_stats_index->Start()) {
|
node.indexes.emplace_back(g_coin_stats_index.get());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now that all indexes are loaded, start them
|
||||||
|
StartIndexes(node);
|
||||||
|
|
||||||
// ********************************************************* Step 9: load wallet
|
// ********************************************************* Step 9: load wallet
|
||||||
for (const auto& client : node.chain_clients) {
|
for (const auto& client : node.chain_clients) {
|
||||||
if (!client->load()) {
|
if (!client->load()) {
|
||||||
|
@ -1878,3 +1875,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StartIndexes(NodeContext& node)
|
||||||
|
{
|
||||||
|
for (auto index : node.indexes) if (!index->Start()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -73,4 +73,7 @@ bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip
|
||||||
*/
|
*/
|
||||||
void SetupServerArgs(ArgsManager& argsman);
|
void SetupServerArgs(ArgsManager& argsman);
|
||||||
|
|
||||||
|
/** Validates requirements to run the indexes and spawns each index initial sync thread */
|
||||||
|
bool StartIndexes(node::NodeContext& node);
|
||||||
|
|
||||||
#endif // BITCOIN_INIT_H
|
#endif // BITCOIN_INIT_H
|
||||||
|
|
|
@ -15,8 +15,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
class BanMan;
|
|
||||||
class AddrMan;
|
class AddrMan;
|
||||||
|
class BanMan;
|
||||||
|
class BaseIndex;
|
||||||
class CBlockPolicyEstimator;
|
class CBlockPolicyEstimator;
|
||||||
class CConnman;
|
class CConnman;
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
|
@ -58,6 +59,7 @@ struct NodeContext {
|
||||||
std::unique_ptr<ChainstateManager> chainman;
|
std::unique_ptr<ChainstateManager> chainman;
|
||||||
std::unique_ptr<BanMan> banman;
|
std::unique_ptr<BanMan> banman;
|
||||||
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
||||||
|
std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct
|
||||||
std::unique_ptr<interfaces::Chain> chain;
|
std::unique_ptr<interfaces::Chain> chain;
|
||||||
//! List of all chain clients (wallet processes or other client) connected to node.
|
//! List of all chain clients (wallet processes or other client) connected to node.
|
||||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
||||||
|
|
Loading…
Add table
Reference in a new issue