MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / btck_chainstate_manager_create

Function btck_chainstate_manager_create

src/kernel/bitcoinkernel.cpp:1036–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1034}
1035
1036btck_ChainstateManager* btck_chainstate_manager_create(
1037 const btck_ChainstateManagerOptions* chainman_opts)
1038{
1039 auto& opts{btck_ChainstateManagerOptions::get(chainman_opts)};
1040 std::unique_ptr<ChainstateManager> chainman;
1041 try {
1042 LOCK(opts.m_mutex);
1043 chainman = std::make_unique<ChainstateManager>(*opts.m_context->m_interrupt, opts.m_chainman_options, opts.m_blockman_options);
1044 } catch (const std::exception& e) {
1045 LogError("Failed to create chainstate manager: %s", e.what());
1046 return nullptr;
1047 }
1048
1049 try {
1050 const auto chainstate_load_opts{WITH_LOCK(opts.m_mutex, return opts.m_chainstate_load_options)};
1051
1052 kernel::CacheSizes cache_sizes{DEFAULT_KERNEL_CACHE};
1053 auto [status, chainstate_err]{node::LoadChainstate(*chainman, cache_sizes, chainstate_load_opts)};
1054 if (status != node::ChainstateLoadStatus::SUCCESS) {
1055 LogError("Failed to load chain state from your data directory: %s", chainstate_err.original);
1056 return nullptr;
1057 }
1058 std::tie(status, chainstate_err) = node::VerifyLoadedChainstate(*chainman, chainstate_load_opts);
1059 if (status != node::ChainstateLoadStatus::SUCCESS) {
1060 LogError("Failed to verify loaded chain state from your datadir: %s", chainstate_err.original);
1061 return nullptr;
1062 }
1063 if (auto result = chainman->ActivateBestChains(); !result) {
1064 LogError("%s", util::ErrorString(result).original);
1065 return nullptr;
1066 }
1067 } catch (const std::exception& e) {
1068 LogError("Failed to load chainstate: %s", e.what());
1069 return nullptr;
1070 }
1071
1072 return btck_ChainstateManager::create(std::move(chainman), opts.m_context);
1073}
1074
1075const btck_BlockTreeEntry* btck_chainstate_manager_get_block_tree_entry_by_hash(const btck_ChainstateManager* chainman, const btck_BlockHash* block_hash)
1076{

Callers 1

ChainManMethod · 0.85

Calls 6

getFunction · 0.85
LoadChainstateFunction · 0.85
VerifyLoadedChainstateFunction · 0.85
ErrorStringFunction · 0.85
ActivateBestChainsMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected