mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-10 11:33:46 +02:00
Move init::SanityCheck to kernel::SanityCheck
This commit is contained in:
@@ -171,6 +171,7 @@ BITCOIN_CORE_H = \
|
|||||||
interfaces/node.h \
|
interfaces/node.h \
|
||||||
interfaces/wallet.h \
|
interfaces/wallet.h \
|
||||||
kernel/chainstatemanager_opts.h \
|
kernel/chainstatemanager_opts.h \
|
||||||
|
kernel/checks.h \
|
||||||
kernel/coinstats.h \
|
kernel/coinstats.h \
|
||||||
kernel/context.h \
|
kernel/context.h \
|
||||||
key.h \
|
key.h \
|
||||||
@@ -356,6 +357,7 @@ libbitcoin_node_a_SOURCES = \
|
|||||||
index/coinstatsindex.cpp \
|
index/coinstatsindex.cpp \
|
||||||
index/txindex.cpp \
|
index/txindex.cpp \
|
||||||
init.cpp \
|
init.cpp \
|
||||||
|
kernel/checks.cpp \
|
||||||
kernel/coinstats.cpp \
|
kernel/coinstats.cpp \
|
||||||
kernel/context.cpp \
|
kernel/context.cpp \
|
||||||
mapport.cpp \
|
mapport.cpp \
|
||||||
@@ -866,6 +868,7 @@ libbitcoinkernel_la_SOURCES = \
|
|||||||
flatfile.cpp \
|
flatfile.cpp \
|
||||||
fs.cpp \
|
fs.cpp \
|
||||||
hash.cpp \
|
hash.cpp \
|
||||||
|
kernel/checks.cpp \
|
||||||
kernel/coinstats.cpp \
|
kernel/coinstats.cpp \
|
||||||
kernel/context.cpp \
|
kernel/context.cpp \
|
||||||
key.cpp \
|
key.cpp \
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
//
|
//
|
||||||
// It is part of the libbitcoinkernel project.
|
// It is part of the libbitcoinkernel project.
|
||||||
|
|
||||||
|
#include <kernel/checks.h>
|
||||||
#include <kernel/context.h>
|
#include <kernel/context.h>
|
||||||
|
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <init/common.h>
|
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/chainstate.h>
|
#include <node/chainstate.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
@@ -52,6 +53,10 @@ int main(int argc, char* argv[])
|
|||||||
const CChainParams& chainparams = Params();
|
const CChainParams& chainparams = Params();
|
||||||
|
|
||||||
kernel::Context kernel_context{};
|
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));
|
||||||
|
|
||||||
// Necessary for CheckInputScripts (eventually called by ProcessNewBlock),
|
// Necessary for CheckInputScripts (eventually called by ProcessNewBlock),
|
||||||
// which will try the script cache first and fall back to actually
|
// which will try the script cache first and fall back to actually
|
||||||
|
@@ -190,7 +190,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.kernel = std::make_unique<kernel::Context>();
|
node.kernel = std::make_unique<kernel::Context>();
|
||||||
if (!AppInitSanityChecks())
|
if (!AppInitSanityChecks(*node.kernel))
|
||||||
{
|
{
|
||||||
// InitError will have been called with detailed error, which ends up on console
|
// InitError will have been called with detailed error, which ends up on console
|
||||||
return false;
|
return false;
|
||||||
|
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
|
|
||||||
|
#include <kernel/checks.h>
|
||||||
|
|
||||||
#include <addrman.h>
|
#include <addrman.h>
|
||||||
#include <banman.h>
|
#include <banman.h>
|
||||||
#include <blockfilter.h>
|
#include <blockfilter.h>
|
||||||
@@ -1089,10 +1091,10 @@ static bool LockDataDirectory(bool probeOnly)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppInitSanityChecks()
|
bool AppInitSanityChecks(const kernel::Context& kernel)
|
||||||
{
|
{
|
||||||
// ********************************************************* Step 4: sanity checks
|
// ********************************************************* Step 4: sanity checks
|
||||||
if (!init::SanityChecks()) {
|
if (!kernel::SanityChecks(kernel)) {
|
||||||
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
|
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
|
|||||||
* @note This can be done before daemonization. Do not call Shutdown() if this function fails.
|
* @note This can be done before daemonization. Do not call Shutdown() if this function fails.
|
||||||
* @pre Parameters should be parsed and config file should be read, AppInitParameterInteraction should have been called.
|
* @pre Parameters should be parsed and config file should be read, AppInitParameterInteraction should have been called.
|
||||||
*/
|
*/
|
||||||
bool AppInitSanityChecks();
|
bool AppInitSanityChecks(const kernel::Context& kernel);
|
||||||
/**
|
/**
|
||||||
* Lock bitcoin core data directory.
|
* Lock bitcoin core data directory.
|
||||||
* @note This should only be done after daemonization. Do not call Shutdown() if this function fails.
|
* @note This should only be done after daemonization. Do not call Shutdown() if this function fails.
|
||||||
|
@@ -8,10 +8,8 @@
|
|||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <key.h>
|
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/ui_interface.h>
|
#include <node/ui_interface.h>
|
||||||
#include <random.h>
|
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
@@ -22,23 +20,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace init {
|
namespace init {
|
||||||
bool SanityChecks()
|
|
||||||
{
|
|
||||||
if (!ECC_InitSanityCheck()) {
|
|
||||||
return InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Random_SanityCheck()) {
|
|
||||||
return InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ChronoSanityCheck()) {
|
|
||||||
return InitError(Untranslated("Clock epoch mismatch. Aborting."));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddLoggingArgs(ArgsManager& argsman)
|
void AddLoggingArgs(ArgsManager& argsman)
|
||||||
{
|
{
|
||||||
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
|
@@ -11,11 +11,6 @@
|
|||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
|
|
||||||
namespace init {
|
namespace init {
|
||||||
/**
|
|
||||||
* Ensure a usable environment with all
|
|
||||||
* necessary library support.
|
|
||||||
*/
|
|
||||||
bool SanityChecks();
|
|
||||||
void AddLoggingArgs(ArgsManager& args);
|
void AddLoggingArgs(ArgsManager& args);
|
||||||
void SetLoggingOptions(const ArgsManager& args);
|
void SetLoggingOptions(const ArgsManager& args);
|
||||||
void SetLoggingCategories(const ArgsManager& args);
|
void SetLoggingCategories(const ArgsManager& args);
|
||||||
|
33
src/kernel/checks.cpp
Normal file
33
src/kernel/checks.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (c) 2022 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <kernel/checks.h>
|
||||||
|
|
||||||
|
#include <key.h>
|
||||||
|
#include <node/ui_interface.h>
|
||||||
|
#include <random.h>
|
||||||
|
#include <util/time.h>
|
||||||
|
#include <util/translation.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace kernel {
|
||||||
|
|
||||||
|
bool SanityChecks(const Context&) {
|
||||||
|
if (!ECC_InitSanityCheck()) {
|
||||||
|
return InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Random_SanityCheck()) {
|
||||||
|
return InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ChronoSanityCheck()) {
|
||||||
|
return InitError(Untranslated("Clock epoch mismatch. Aborting."));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/kernel/checks.h
Normal file
19
src/kernel/checks.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (c) 2022 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_KERNEL_CHECKS_H
|
||||||
|
#define BITCOIN_KERNEL_CHECKS_H
|
||||||
|
|
||||||
|
namespace kernel {
|
||||||
|
|
||||||
|
struct Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure a usable environment with all necessary library support.
|
||||||
|
*/
|
||||||
|
bool SanityChecks(const Context&);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BITCOIN_KERNEL_CHECKS_H
|
@@ -94,7 +94,7 @@ public:
|
|||||||
if (!AppInitParameterInteraction(gArgs, /*use_syscall_sandbox=*/false)) return false;
|
if (!AppInitParameterInteraction(gArgs, /*use_syscall_sandbox=*/false)) return false;
|
||||||
|
|
||||||
m_context->kernel = std::make_unique<kernel::Context>();
|
m_context->kernel = std::make_unique<kernel::Context>();
|
||||||
if (!AppInitSanityChecks()) return false;
|
if (!AppInitSanityChecks(*m_context->kernel)) return false;
|
||||||
|
|
||||||
if (!AppInitLockDataDirectory()) return false;
|
if (!AppInitLockDataDirectory()) return false;
|
||||||
if (!AppInitInterfaces(*m_context)) return false;
|
if (!AppInitInterfaces(*m_context)) return false;
|
||||||
|
Reference in New Issue
Block a user