aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-05-25 14:31:54 -0400
committerCarl Dong <contact@carldong.me>2022-06-02 11:40:03 -0400
commitfed085a1a4cd2787202752b6a0d98e42dce97f09 (patch)
treef5f85da84e9aee2a1e7fd6ac52edf70dfa90fcbd /src/kernel
parent7d03feef8156ef37a4efa01dc591467bc7d957bf (diff)
downloadbitcoin-fed085a1a4cd2787202752b6a0d98e42dce97f09.tar.xz
init: Initialize globals with kernel::Context's life
...instead of explicitly calling init::{Set,Unset}Globals. Cool thing about this is that in both the testing and bitcoin-chainstate codepaths, we no longer need to explicitly unset globals. The kernel::Context goes out of scope and the globals are unset "automatically". Also construct kernel::Context outside of AppInitSanityChecks()
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/context.cpp33
-rw-r--r--src/kernel/context.h11
2 files changed, 44 insertions, 0 deletions
diff --git a/src/kernel/context.cpp b/src/kernel/context.cpp
new file mode 100644
index 0000000000..15413c1840
--- /dev/null
+++ b/src/kernel/context.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/context.h>
+
+#include <crypto/sha256.h>
+#include <key.h>
+#include <logging.h>
+#include <pubkey.h>
+#include <random.h>
+
+#include <string>
+
+
+namespace kernel {
+
+Context::Context()
+{
+ std::string sha256_algo = SHA256AutoDetect();
+ LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
+ RandomInit();
+ ECC_Start();
+ ecc_verify_handle.reset(new ECCVerifyHandle());
+}
+
+Context::~Context()
+{
+ ecc_verify_handle.reset();
+ ECC_Stop();
+}
+
+} // namespace kernel
diff --git a/src/kernel/context.h b/src/kernel/context.h
index e304dcb006..0a08511564 100644
--- a/src/kernel/context.h
+++ b/src/kernel/context.h
@@ -5,6 +5,10 @@
#ifndef BITCOIN_KERNEL_CONTEXT_H
#define BITCOIN_KERNEL_CONTEXT_H
+#include <memory>
+
+class ECCVerifyHandle;
+
namespace kernel {
//! Context struct holding the kernel library's logically global state, and
//! passed to external libbitcoin_kernel functions which need access to this
@@ -14,6 +18,13 @@ namespace kernel {
//! State stored directly in this struct should be simple. More complex state
//! should be stored to std::unique_ptr members pointing to opaque types.
struct Context {
+ std::unique_ptr<ECCVerifyHandle> ecc_verify_handle;
+
+ //! Declare default constructor and destructor that are not inline, so code
+ //! instantiating the kernel::Context struct doesn't need to #include class
+ //! definitions for all the unique_ptr members.
+ Context();
+ ~Context();
};
} // namespace kernel