Skip to content

Commit 41eba5b

Browse files
committed
kernel: Remove key module from kernel library
The key module's functionality is not used by the kernel library, but currently kernel users are still required to initialize the key module's `secp256k1_context_sign` global as part of the `kernel::Context` through `ECC_Start`.
1 parent a08d2b3 commit 41eba5b

14 files changed

+31
-21
lines changed

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ libbitcoinkernel_la_SOURCES = \
945945
kernel/disconnected_transactions.cpp \
946946
kernel/mempool_persist.cpp \
947947
kernel/mempool_removal_reason.cpp \
948-
key.cpp \
949948
logging.cpp \
950949
node/blockstorage.cpp \
951950
node/chainstate.cpp \

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <script/sigcache.h>
2727
#include <util/chaintype.h>
2828
#include <util/fs.h>
29+
#include <util/signalinterrupt.h>
2930
#include <util/task_runner.h>
3031
#include <validation.h>
3132
#include <validationinterface.h>

src/bitcoind.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
#include <init.h>
1515
#include <interfaces/chain.h>
1616
#include <interfaces/init.h>
17+
#include <kernel/context.h>
1718
#include <node/context.h>
1819
#include <node/interface_ui.h>
1920
#include <noui.h>
2021
#include <util/check.h>
2122
#include <util/exception.h>
23+
#include <util/signalinterrupt.h>
2224
#include <util/strencodings.h>
2325
#include <util/syserror.h>
2426
#include <util/threadnames.h>
@@ -180,6 +182,7 @@ static bool AppInit(NodeContext& node)
180182
}
181183

182184
node.kernel = std::make_unique<kernel::Context>();
185+
node.ecc_context = std::make_unique<ECC_Context>();
183186
if (!AppInitSanityChecks(*node.kernel))
184187
{
185188
// InitError will have been called with detailed error, which ends up on console

src/init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <interfaces/chain.h>
3333
#include <interfaces/init.h>
3434
#include <interfaces/node.h>
35+
#include <kernel/context.h>
36+
#include <key.h>
3537
#include <logging.h>
3638
#include <mapport.h>
3739
#include <net.h>
@@ -75,6 +77,7 @@
7577
#include <util/fs_helpers.h>
7678
#include <util/moneystr.h>
7779
#include <util/result.h>
80+
#include <util/signalinterrupt.h>
7881
#include <util/strencodings.h>
7982
#include <util/string.h>
8083
#include <util/syserror.h>
@@ -371,6 +374,7 @@ void Shutdown(NodeContext& node)
371374
node.chainman.reset();
372375
node.validation_signals.reset();
373376
node.scheduler.reset();
377+
node.ecc_context.reset();
374378
node.kernel.reset();
375379

376380
RemovePidFile(*node.args);
@@ -1084,6 +1088,10 @@ bool AppInitSanityChecks(const kernel::Context& kernel)
10841088
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
10851089
}
10861090

1091+
if (!ECC_InitSanityCheck()) {
1092+
return InitError(strprintf(_("Elliptic curve cryptography sanity check failure. %s is shutting down."), PACKAGE_NAME));
1093+
}
1094+
10871095
// Probe the data directory lock to give an early error message, if possible
10881096
// We cannot hold the data directory lock here, as the forking for daemon() hasn't yet happened,
10891097
// and a fork will cause weird behavior to it.

src/kernel/checks.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include <kernel/checks.h>
66

7-
#include <key.h>
87
#include <random.h>
8+
#include <util/result.h>
99
#include <util/translation.h>
1010

1111
#include <memory>
@@ -14,10 +14,6 @@ namespace kernel {
1414

1515
util::Result<void> SanityChecks(const Context&)
1616
{
17-
if (!ECC_InitSanityCheck()) {
18-
return util::Error{Untranslated("Elliptic curve cryptography sanity check failure. Aborting.")};
19-
}
20-
2117
if (!Random_SanityCheck()) {
2218
return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
2319
}

src/kernel/context.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include <kernel/context.h>
66

77
#include <crypto/sha256.h>
8-
#include <key.h>
98
#include <logging.h>
10-
#include <pubkey.h>
119
#include <random.h>
1210

1311
#include <string>
@@ -19,12 +17,7 @@ Context::Context()
1917
std::string sha256_algo = SHA256AutoDetect();
2018
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
2119
RandomInit();
22-
ECC_Start();
2320
}
2421

25-
Context::~Context()
26-
{
27-
ECC_Stop();
28-
}
2922

3023
} // namespace kernel

src/kernel/context.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#ifndef BITCOIN_KERNEL_CONTEXT_H
66
#define BITCOIN_KERNEL_CONTEXT_H
77

8-
#include <util/signalinterrupt.h>
9-
10-
#include <memory>
11-
128
namespace kernel {
139
//! Context struct holding the kernel library's logically global state, and
1410
//! passed to external libbitcoin_kernel functions which need access to this
@@ -19,7 +15,6 @@ namespace kernel {
1915
//! should be stored to std::unique_ptr members pointing to opaque types.
2016
struct Context {
2117
Context();
22-
~Context();
2318
};
2419
} // namespace kernel
2520

src/node/context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <banman.h>
99
#include <interfaces/chain.h>
1010
#include <kernel/context.h>
11+
#include <key.h>
1112
#include <net.h>
1213
#include <net_processing.h>
1314
#include <netgroup.h>
@@ -16,6 +17,7 @@
1617
#include <scheduler.h>
1718
#include <txmempool.h>
1819
#include <validation.h>
20+
#include <validationinterface.h>
1921

2022
namespace node {
2123
NodeContext::NodeContext() = default;

src/node/context.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
#ifndef BITCOIN_NODE_CONTEXT_H
66
#define BITCOIN_NODE_CONTEXT_H
77

8-
#include <kernel/context.h>
9-
108
#include <atomic>
11-
#include <cassert>
129
#include <cstdlib>
1310
#include <functional>
1411
#include <memory>
@@ -24,6 +21,7 @@ class ValidationSignals;
2421
class CScheduler;
2522
class CTxMemPool;
2623
class ChainstateManager;
24+
class ECC_Context;
2725
class NetGroupManager;
2826
class PeerManager;
2927
namespace interfaces {
@@ -32,6 +30,12 @@ class ChainClient;
3230
class Init;
3331
class WalletLoader;
3432
} // namespace interfaces
33+
namespace kernel {
34+
struct Context;
35+
}
36+
namespace util {
37+
class SignalInterrupt;
38+
}
3539

3640
namespace node {
3741
class KernelNotifications;
@@ -49,6 +53,7 @@ class KernelNotifications;
4953
struct NodeContext {
5054
//! libbitcoin_kernel context
5155
std::unique_ptr<kernel::Context> kernel;
56+
std::unique_ptr<ECC_Context> ecc_context;
5257
//! Init interface for initializing current process and connecting to other processes.
5358
interfaces::Init* init{nullptr};
5459
//! Interrupt object used to track whether node shutdown was requested.

src/node/interfaces.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <interfaces/node.h>
1818
#include <interfaces/wallet.h>
1919
#include <kernel/chain.h>
20+
#include <kernel/context.h>
2021
#include <kernel/mempool_entry.h>
2122
#include <logging.h>
2223
#include <mapport.h>
@@ -99,6 +100,7 @@ class NodeImpl : public Node
99100
if (!AppInitParameterInteraction(args())) return false;
100101

101102
m_context->kernel = std::make_unique<kernel::Context>();
103+
m_context->ecc_context = std::make_unique<ECC_Context>();
102104
if (!AppInitSanityChecks(*m_context->kernel)) return false;
103105

104106
if (!AppInitLockDataDirectory()) return false;

0 commit comments

Comments
 (0)