Skip to content

Commit 8ecb681

Browse files
committed
Introduce Mining interface
Start out with a single method isTestChain() that's used by the getblocktemplate RPC.
1 parent 9c5cdf0 commit 8ecb681

File tree

14 files changed

+85
-3
lines changed

14 files changed

+85
-3
lines changed

doc/developer-notes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,9 @@ independent (node, wallet, GUI), are defined in
14571457
there are [`interfaces::Chain`](../src/interfaces/chain.h), used by wallet to
14581458
access the node's latest chain state,
14591459
[`interfaces::Node`](../src/interfaces/node.h), used by the GUI to control the
1460-
node, and [`interfaces::Wallet`](../src/interfaces/wallet.h), used by the GUI
1461-
to control an individual wallet. There are also more specialized interface
1460+
node, [`interfaces::Wallet`](../src/interfaces/wallet.h), used by the GUI
1461+
to control an individual wallet and [`interfaces::Mining`](../src/interfaces/mining.h),
1462+
used by RPC to generate block templates. There are also more specialized interface
14621463
types like [`interfaces::Handler`](../src/interfaces/handler.h)
14631464
[`interfaces::ChainClient`](../src/interfaces/chain.h) passed to and from
14641465
various interface methods.

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ BITCOIN_CORE_H = \
177177
interfaces/handler.h \
178178
interfaces/init.h \
179179
interfaces/ipc.h \
180+
interfaces/mining.h \
180181
interfaces/node.h \
181182
interfaces/wallet.h \
182183
kernel/blockmanager_opts.h \

src/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <init/common.h>
3232
#include <interfaces/chain.h>
3333
#include <interfaces/init.h>
34+
#include <interfaces/mining.h>
3435
#include <interfaces/node.h>
3536
#include <kernel/context.h>
3637
#include <key.h>
@@ -1117,6 +1118,7 @@ bool AppInitLockDataDirectory()
11171118
bool AppInitInterfaces(NodeContext& node)
11181119
{
11191120
node.chain = node.init->makeChain();
1121+
node.mining = node.init->makeMining();
11201122
return true;
11211123
}
11221124

src/init/bitcoin-node.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class BitcoinNodeInit : public interfaces::Init
3030
}
3131
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
3232
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
33+
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
3334
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
3435
{
3536
return MakeWalletLoader(chain, *Assert(m_node.args));

src/init/bitcoin-qt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
9+
#include <interfaces/mining.h>
910
#include <interfaces/node.h>
1011
#include <interfaces/wallet.h>
1112
#include <node/context.h>
@@ -25,6 +26,7 @@ class BitcoinQtInit : public interfaces::Init
2526
}
2627
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
2728
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
29+
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
2830
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
2931
{
3032
return MakeWalletLoader(chain, *Assert(m_node.args));

src/init/bitcoind.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <interfaces/chain.h>
77
#include <interfaces/echo.h>
88
#include <interfaces/init.h>
9+
#include <interfaces/mining.h>
910
#include <interfaces/node.h>
1011
#include <interfaces/wallet.h>
1112
#include <node/context.h>
@@ -27,6 +28,7 @@ class BitcoindInit : public interfaces::Init
2728
}
2829
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
2930
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
31+
std::unique_ptr<interfaces::Mining> makeMining() override { return interfaces::MakeMining(m_node); }
3032
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
3133
{
3234
return MakeWalletLoader(chain, *Assert(m_node.args));

src/interfaces/init.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <interfaces/chain.h>
99
#include <interfaces/echo.h>
10+
#include <interfaces/mining.h>
1011
#include <interfaces/node.h>
1112
#include <interfaces/wallet.h>
1213

@@ -32,6 +33,7 @@ class Init
3233
virtual ~Init() = default;
3334
virtual std::unique_ptr<Node> makeNode() { return nullptr; }
3435
virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
36+
virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
3537
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
3638
virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
3739
virtual Ipc* ipc() { return nullptr; }

src/interfaces/mining.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2024 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_INTERFACES_MINING_H
6+
#define BITCOIN_INTERFACES_MINING_H
7+
8+
namespace node {
9+
struct NodeContext;
10+
} // namespace node
11+
12+
namespace interfaces {
13+
14+
//! Interface giving clients (RPC, Stratum v2 Template Provider in the future)
15+
//! ability to create block templates.
16+
17+
class Mining
18+
{
19+
public:
20+
virtual ~Mining() {}
21+
22+
//! If this chain is exclusively used for testing
23+
virtual bool isTestChain() = 0;
24+
25+
//! Get internal node context. Useful for RPC and testing,
26+
//! but not accessible across processes.
27+
virtual node::NodeContext* context() { return nullptr; }
28+
};
29+
30+
//! Return implementation of Mining interface.
31+
std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
32+
33+
} // namespace interfaces
34+
35+
#endif // BITCOIN_INTERFACES_MINING_H

src/node/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <addrman.h>
88
#include <banman.h>
99
#include <interfaces/chain.h>
10+
#include <interfaces/mining.h>
1011
#include <kernel/context.h>
1112
#include <key.h>
1213
#include <net.h>

src/node/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class PeerManager;
2727
namespace interfaces {
2828
class Chain;
2929
class ChainClient;
30+
class Mining;
3031
class Init;
3132
class WalletLoader;
3233
} // namespace interfaces
@@ -74,6 +75,7 @@ struct NodeContext {
7475
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
7576
//! Reference to chain client that should used to load or create wallets
7677
//! opened by the gui.
78+
std::unique_ptr<interfaces::Mining> mining;
7779
interfaces::WalletLoader* wallet_loader{nullptr};
7880
std::unique_ptr<CScheduler> scheduler;
7981
std::function<void()> rpc_interruption_point = [] {};

0 commit comments

Comments
 (0)