diff options
Diffstat (limited to 'src/bitcoin-chainstate.cpp')
-rw-r--r-- | src/bitcoin-chainstate.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index ab805ac1ec..fc3f91d492 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -11,11 +11,15 @@ // // It is part of the libbitcoinkernel project. +#include <kernel/checks.h> +#include <kernel/context.h> +#include <kernel/validation_cache_sizes.h> + #include <chainparams.h> #include <consensus/validation.h> #include <core_io.h> -#include <init/common.h> #include <node/blockstorage.h> +#include <node/caches.h> #include <node/chainstate.h> #include <scheduler.h> #include <script/sigcache.h> @@ -24,6 +28,7 @@ #include <validation.h> #include <validationinterface.h> +#include <cassert> #include <filesystem> #include <functional> #include <iosfwd> @@ -49,13 +54,18 @@ int main(int argc, char* argv[]) SelectParams(CBaseChainParams::MAIN); const CChainParams& chainparams = Params(); - init::SetGlobals(); // ECC_Start, etc. + kernel::Context kernel_context{}; + // We can't use a goto here, but we can use an assert since none of the + // things instantiated so far requires running the epilogue to be torn down + // properly + assert(!kernel::SanityChecks(kernel_context).has_value()); // Necessary for CheckInputScripts (eventually called by ProcessNewBlock), // which will try the script cache first and fall back to actually // performing the check with the signature cache. - InitSignatureCache(); - InitScriptExecutionCache(); + kernel::ValidationCacheSizes validation_cache_sizes{}; + Assert(InitSignatureCache(validation_cache_sizes.signature_cache_bytes)); + Assert(InitScriptExecutionCache(validation_cache_sizes.script_execution_cache_bytes)); // SETUP: Scheduling and Background Signals @@ -70,32 +80,25 @@ int main(int argc, char* argv[]) // SETUP: Chainstate - ChainstateManager chainman{chainparams}; + const ChainstateManager::Options chainman_opts{ + .chainparams = chainparams, + .adjusted_time_callback = static_cast<int64_t (*)()>(GetTime), + }; + ChainstateManager chainman{chainman_opts}; - auto rv = node::LoadChainstate(false, - std::ref(chainman), - nullptr, - false, - chainparams.GetConsensus(), - false, - 2 << 20, - 2 << 22, - (450 << 20) - (2 << 20) - (2 << 22), - false, - false, - []() { return false; }); - if (rv.has_value()) { + node::CacheSizes cache_sizes; + cache_sizes.block_tree_db = 2 << 20; + cache_sizes.coins_db = 2 << 22; + cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22); + node::ChainstateLoadOptions options; + options.check_interrupt = [] { return false; }; + auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options); + if (status != node::ChainstateLoadStatus::SUCCESS) { std::cerr << "Failed to load Chain state from your datadir." << std::endl; goto epilogue; } else { - auto maybe_verify_error = node::VerifyLoadedChainstate(std::ref(chainman), - false, - false, - chainparams.GetConsensus(), - DEFAULT_CHECKBLOCKS, - DEFAULT_CHECKLEVEL, - /*get_unix_time_seconds=*/static_cast<int64_t (*)()>(GetTime)); - if (maybe_verify_error.has_value()) { + std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options); + if (status != node::ChainstateLoadStatus::SUCCESS) { std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl; goto epilogue; } @@ -253,6 +256,4 @@ epilogue: } } GetMainSignals().UnregisterBackgroundSignalScheduler(); - - init::UnsetGlobals(); } |