aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-05-27 16:47:05 -0400
committerCarl Dong <contact@carldong.me>2022-06-02 11:42:12 -0400
commit265d6393bf9ef52e7ef7de97ca9c031da82a5ad1 (patch)
tree5fd6e341d903e3b78c7ad25c090d08fbcf9a6034
parentfed085a1a4cd2787202752b6a0d98e42dce97f09 (diff)
Move init::SanityCheck to kernel::SanityCheck
-rw-r--r--src/Makefile.am3
-rw-r--r--src/bitcoin-chainstate.cpp7
-rw-r--r--src/bitcoind.cpp2
-rw-r--r--src/init.cpp6
-rw-r--r--src/init.h2
-rw-r--r--src/init/common.cpp19
-rw-r--r--src/init/common.h5
-rw-r--r--src/kernel/checks.cpp33
-rw-r--r--src/kernel/checks.h19
-rw-r--r--src/node/interfaces.cpp2
10 files changed, 68 insertions, 30 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 765947f035..ba0e9ac736 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -171,6 +171,7 @@ BITCOIN_CORE_H = \
interfaces/node.h \
interfaces/wallet.h \
kernel/chainstatemanager_opts.h \
+ kernel/checks.h \
kernel/coinstats.h \
kernel/context.h \
key.h \
@@ -356,6 +357,7 @@ libbitcoin_node_a_SOURCES = \
index/coinstatsindex.cpp \
index/txindex.cpp \
init.cpp \
+ kernel/checks.cpp \
kernel/coinstats.cpp \
kernel/context.cpp \
mapport.cpp \
@@ -866,6 +868,7 @@ libbitcoinkernel_la_SOURCES = \
flatfile.cpp \
fs.cpp \
hash.cpp \
+ kernel/checks.cpp \
kernel/coinstats.cpp \
kernel/context.cpp \
key.cpp \
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp
index 6749ed5918..3f2b298c1f 100644
--- a/src/bitcoin-chainstate.cpp
+++ b/src/bitcoin-chainstate.cpp
@@ -11,12 +11,12 @@
//
// It is part of the libbitcoinkernel project.
+#include <kernel/checks.h>
#include <kernel/context.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <core_io.h>
-#include <init/common.h>
#include <node/blockstorage.h>
#include <node/chainstate.h>
#include <scheduler.h>
@@ -26,6 +26,7 @@
#include <validation.h>
#include <validationinterface.h>
+#include <cassert>
#include <filesystem>
#include <functional>
#include <iosfwd>
@@ -52,6 +53,10 @@ int main(int argc, char* argv[])
const CChainParams& chainparams = Params();
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),
// which will try the script cache first and fall back to actually
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index 0cf9ad49dc..92e73d7c2a 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -190,7 +190,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
}
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
return false;
diff --git a/src/init.cpp b/src/init.cpp
index aaabbd9af6..108f5c99d3 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -9,6 +9,8 @@
#include <init.h>
+#include <kernel/checks.h>
+
#include <addrman.h>
#include <banman.h>
#include <blockfilter.h>
@@ -1089,10 +1091,10 @@ static bool LockDataDirectory(bool probeOnly)
return true;
}
-bool AppInitSanityChecks()
+bool AppInitSanityChecks(const kernel::Context& kernel)
{
// ********************************************************* Step 4: sanity checks
- if (!init::SanityChecks()) {
+ if (!kernel::SanityChecks(kernel)) {
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
}
diff --git a/src/init.h b/src/init.h
index 4251fa33ae..e8e6a55eba 100644
--- a/src/init.h
+++ b/src/init.h
@@ -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.
* @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.
* @note This should only be done after daemonization. Do not call Shutdown() if this function fails.
diff --git a/src/init/common.cpp b/src/init/common.cpp
index e5dc097bc3..d4e45454d2 100644
--- a/src/init/common.cpp
+++ b/src/init/common.cpp
@@ -8,10 +8,8 @@
#include <clientversion.h>
#include <fs.h>
-#include <key.h>
#include <logging.h>
#include <node/ui_interface.h>
-#include <random.h>
#include <tinyformat.h>
#include <util/system.h>
#include <util/time.h>
@@ -22,23 +20,6 @@
#include <vector>
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)
{
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);
diff --git a/src/init/common.h b/src/init/common.h
index bbd5771840..2c7f485908 100644
--- a/src/init/common.h
+++ b/src/init/common.h
@@ -11,11 +11,6 @@
class ArgsManager;
namespace init {
-/**
- * Ensure a usable environment with all
- * necessary library support.
- */
-bool SanityChecks();
void AddLoggingArgs(ArgsManager& args);
void SetLoggingOptions(const ArgsManager& args);
void SetLoggingCategories(const ArgsManager& args);
diff --git a/src/kernel/checks.cpp b/src/kernel/checks.cpp
new file mode 100644
index 0000000000..a25617bea5
--- /dev/null
+++ b/src/kernel/checks.cpp
@@ -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;
+}
+
+}
diff --git a/src/kernel/checks.h b/src/kernel/checks.h
new file mode 100644
index 0000000000..786281fa2c
--- /dev/null
+++ b/src/kernel/checks.h
@@ -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
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 40defd5bab..7752fb0f65 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -94,7 +94,7 @@ public:
if (!AppInitParameterInteraction(gArgs, /*use_syscall_sandbox=*/false)) return false;
m_context->kernel = std::make_unique<kernel::Context>();
- if (!AppInitSanityChecks()) return false;
+ if (!AppInitSanityChecks(*m_context->kernel)) return false;
if (!AppInitLockDataDirectory()) return false;
if (!AppInitInterfaces(*m_context)) return false;