refactor: Add ChainstateManager::ActivateBestChains() method

Deduplicate code looping over chainstate objects and calling
ActivateBestChain() and avoid need for code outside ChainstateManager to use
the GetAll() method.
This commit is contained in:
Ryan Ofsky
2024-05-30 14:52:28 -04:00
parent 491d827d52
commit 6a572dbda9
4 changed files with 26 additions and 27 deletions

View File

@@ -982,13 +982,9 @@ btck_ChainstateManager* btck_chainstate_manager_create(
LogError("Failed to verify loaded chain state from your datadir: %s", chainstate_err.original);
return nullptr;
}
for (Chainstate* chainstate : WITH_LOCK(chainman->GetMutex(), return chainman->GetAll())) {
BlockValidationState state;
if (!chainstate->ActivateBestChain(state, nullptr)) {
LogError("Failed to connect best block: %s", state.ToString());
return nullptr;
}
if (auto result = chainman->ActivateBestChains(); !result) {
LogError("%s", util::ErrorString(result).original);
return nullptr;
}
} catch (const std::exception& e) {
LogError("Failed to load chainstate: %s", e.what());