Skip to content

Commit 225e213

Browse files
committed
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.
1 parent 2ebc7e6 commit 225e213

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/init.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,25 +1554,22 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15541554
}
15551555

15561556
g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
1557-
if (!g_txindex->Start()) {
1558-
return false;
1559-
}
1557+
node.indexes.emplace_back(g_txindex.get());
15601558
}
15611559

15621560
for (const auto& filter_type : g_enabled_filter_types) {
15631561
InitBlockFilterIndex([&]{ return interfaces::MakeChain(node); }, filter_type, cache_sizes.filter_index, false, fReindex);
1564-
if (!GetBlockFilterIndex(filter_type)->Start()) {
1565-
return false;
1566-
}
1562+
node.indexes.emplace_back(GetBlockFilterIndex(filter_type));
15671563
}
15681564

15691565
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
15701566
g_coin_stats_index = std::make_unique<CoinStatsIndex>(interfaces::MakeChain(node), /*cache_size=*/0, false, fReindex);
1571-
if (!g_coin_stats_index->Start()) {
1572-
return false;
1573-
}
1567+
node.indexes.emplace_back(g_coin_stats_index.get());
15741568
}
15751569

1570+
// Now that all indexes are loaded, start them
1571+
StartIndexes(node);
1572+
15761573
// ********************************************************* Step 9: load wallet
15771574
for (const auto& client : node.chain_clients) {
15781575
if (!client->load()) {
@@ -1878,3 +1875,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18781875

18791876
return true;
18801877
}
1878+
1879+
bool StartIndexes(NodeContext& node)
1880+
{
1881+
for (auto index : node.indexes) if (!index->Start()) return false;
1882+
return true;
1883+
}

src/init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,7 @@ bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip
7373
*/
7474
void SetupServerArgs(ArgsManager& argsman);
7575

76+
/** Validates requirements to run the indexes and spawns each index initial sync thread */
77+
bool StartIndexes(node::NodeContext& node);
78+
7679
#endif // BITCOIN_INIT_H

src/node/context.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#include <vector>
1616

1717
class ArgsManager;
18-
class BanMan;
1918
class AddrMan;
19+
class BanMan;
20+
class BaseIndex;
2021
class CBlockPolicyEstimator;
2122
class CConnman;
2223
class CScheduler;
@@ -58,6 +59,7 @@ struct NodeContext {
5859
std::unique_ptr<ChainstateManager> chainman;
5960
std::unique_ptr<BanMan> banman;
6061
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
62+
std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct
6163
std::unique_ptr<interfaces::Chain> chain;
6264
//! List of all chain clients (wallet processes or other client) connected to node.
6365
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;

0 commit comments

Comments
 (0)