refactor: index, decouple 'Init' from 'Start'

So indexes can be initialized without spawning
the sync thread.

This makes asynchronous indexes startup
possible in the following commits.
This commit is contained in:
furszy
2023-05-17 00:55:09 -03:00
parent 225e213110
commit 430e7027a1
7 changed files with 35 additions and 23 deletions

View File

@@ -1567,8 +1567,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
node.indexes.emplace_back(g_coin_stats_index.get());
}
// Init indexes
for (auto index : node.indexes) if (!index->Init()) return false;
// Now that all indexes are loaded, start them
StartIndexes(node);
if (!StartIndexBackgroundSync(node)) return false;
// ********************************************************* Step 9: load wallet
for (const auto& client : node.chain_clients) {
@@ -1876,8 +1879,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
return true;
}
bool StartIndexes(NodeContext& node)
bool StartIndexBackgroundSync(NodeContext& node)
{
for (auto index : node.indexes) if (!index->Start()) return false;
for (auto index : node.indexes) if (!index->StartBackgroundSync()) return false;
return true;
}