Skip to content

Commit c409339

Browse files
fanquakeknst
authored andcommitted
Merge bitcoin#22219: multiprocess: Start using init makeNode, makeChain, etc methods
e4709c7 Start using init makeNode, makeChain, etc methods (Russell Yanofsky) Pull request description: Use `interfaces::Init::make*` methods instead of `interfaces::Make*` functions, so interfaces can be constructed differently in different executable without having to change any code. (So for example `bitcoin-gui` can make an `interfaces::Node` pointer that communicates with a `bitcoin-node` subprocess, while `bitcoin-qt` can make an `interfaces::Node` pointer that controls node code in the same process.) --- This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). The commit was first part of larger PR bitcoin#10102. ACKs for top commit: jamesob: reACK bitcoin@e4709c7 achow101: ACK e4709c7 benthecarman: utACK e4709c7 Tree-SHA512: 580c1979dbb2ef444157c8e53041e70d15ddeee77e5cbdb34f70b6d228cc2d2fe3843825f172da84e506200c58f7e0932f7cd4c006bb5058c1f4e43259394834
1 parent 87a1890 commit c409339

20 files changed

+73
-34
lines changed

src/Makefile.qt.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ bitcoin_qt_libtoolflags = $(AM_LIBTOOLFLAGS) --tag CXX
416416

417417
qt_dash_qt_CPPFLAGS = $(bitcoin_qt_cppflags)
418418
qt_dash_qt_CXXFLAGS = $(bitcoin_qt_cxxflags)
419-
qt_dash_qt_SOURCES = $(bitcoin_qt_sources)
419+
qt_dash_qt_SOURCES = $(bitcoin_qt_sources) init/bitcoind.cpp
420420
qt_dash_qt_LDADD = $(bitcoin_qt_ldadd)
421421
qt_dash_qt_LDFLAGS = $(bitcoin_qt_ldflags)
422422
qt_dash_qt_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)
423423

424424
dash_gui_CPPFLAGS = $(bitcoin_qt_cppflags)
425425
dash_gui_CXXFLAGS = $(bitcoin_qt_cxxflags)
426-
dash_gui_SOURCES = $(bitcoin_qt_sources)
426+
dash_gui_SOURCES = $(bitcoin_qt_sources) init/bitcoind.cpp
427427
dash_gui_LDADD = $(bitcoin_qt_ldadd)
428428
dash_gui_LDFLAGS = $(bitcoin_qt_ldflags)
429429
dash_gui_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)

src/Makefile.qttest.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ qt_test_test_dash_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_
3333
$(QT_INCLUDES) $(QT_TEST_INCLUDES)
3434

3535
qt_test_test_dash_qt_SOURCES = \
36+
init/bitcoind.cpp \
3637
qt/test/apptests.cpp \
3738
qt/test/optiontests.cpp \
3839
qt/test/rpcnestedtests.cpp \

src/dummywallet.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#include <util/system.h>
77
#include <walletinitinterface.h>
88

9+
class ArgsManager;
910
class CWallet;
1011

1112
namespace interfaces {
1213
class Chain;
1314
class Handler;
1415
class Wallet;
16+
class WalletClient;
1517
}
1618

1719
class DummyWalletInit : public WalletInitInterface {
@@ -80,4 +82,9 @@ std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet, const
8082
throw std::logic_error("Wallet function called in non-wallet build.");
8183
}
8284

85+
std::unique_ptr<WalletClient> MakeWalletLoader(Chain& chain, ArgsManager& args)
86+
{
87+
throw std::logic_error("Wallet function called in non-wallet build.");
88+
}
89+
8390
} // namespace interfaces

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <index/blockfilterindex.h>
3030
#include <index/coinstatsindex.h>
3131
#include <index/txindex.h>
32+
#include <interfaces/init.h>
3233
#include <interfaces/node.h>
3334
#include <mapport.h>
3435
#include <node/miner.h>
@@ -1431,7 +1432,7 @@ bool AppInitLockDataDirectory()
14311432

14321433
bool AppInitInterfaces(NodeContext& node)
14331434
{
1434-
node.chain = interfaces::MakeChain(node);
1435+
node.chain = node.init->makeChain();
14351436
return true;
14361437
}
14371438

src/init/bitcoin-node.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <interfaces/chain.h>
56
#include <interfaces/echo.h>
67
#include <interfaces/init.h>
78
#include <interfaces/ipc.h>
9+
#include <interfaces/node.h>
10+
#include <interfaces/wallet.h>
811
#include <node/context.h>
912
#include <util/system.h>
1013

@@ -24,6 +27,12 @@ class BitcoinNodeInit : public interfaces::Init
2427
m_node.args = &gArgs;
2528
m_node.init = this;
2629
}
30+
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
31+
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
32+
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, const std::unique_ptr<interfaces::CoinJoin::Loader>& loader) override
33+
{
34+
return MakeWalletLoader(chain, loader, *Assert(m_node.args));
35+
}
2736
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
2837
interfaces::Ipc* ipc() override { return m_ipc.get(); }
2938
NodeContext& m_node;

src/init/bitcoind.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <interfaces/chain.h>
6+
#include <interfaces/echo.h>
57
#include <interfaces/init.h>
8+
#include <interfaces/node.h>
9+
#include <interfaces/wallet.h>
610
#include <node/context.h>
711
#include <util/system.h>
812

@@ -18,6 +22,13 @@ class BitcoindInit : public interfaces::Init
1822
m_node.args = &gArgs;
1923
m_node.init = this;
2024
}
25+
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
26+
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
27+
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain, const std::unique_ptr<interfaces::CoinJoin::Loader>& loader) override
28+
{
29+
return MakeWalletLoader(chain, loader, *Assert(m_node.args));
30+
}
31+
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
2132
NodeContext& m_node;
2233
};
2334
} // namespace

src/interfaces/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace interfaces {
1212
std::unique_ptr<Node> Init::makeNode() { return {}; }
1313
std::unique_ptr<Chain> Init::makeChain() { return {}; }
14-
std::unique_ptr<WalletLoader> Init::makeWalletLoader(Chain& chain) { return {}; }
14+
std::unique_ptr<WalletLoader> Init::makeWalletLoader(Chain& chain, const std::unique_ptr<CoinJoin::Loader>&) { return {}; }
1515
std::unique_ptr<Echo> Init::makeEcho() { return {}; }
1616
Ipc* Init::ipc() { return nullptr; }
1717
} // namespace interfaces

src/interfaces/init.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class Ipc;
1616
class Node;
1717
class WalletLoader;
1818

19+
namespace CoinJoin
20+
{
21+
class Loader;
22+
}
23+
1924
//! Initial interface created when a process is first started, and used to give
2025
//! and get access to other interfaces (Node, Chain, Wallet, etc).
2126
//!
@@ -29,7 +34,7 @@ class Init
2934
virtual ~Init() = default;
3035
virtual std::unique_ptr<Node> makeNode();
3136
virtual std::unique_ptr<Chain> makeChain();
32-
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain);
37+
virtual std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain&, const std::unique_ptr<CoinJoin::Loader>&);
3338
virtual std::unique_ptr<Echo> makeEcho();
3439
virtual Ipc* ipc();
3540
};

src/interfaces/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class Node
362362
};
363363

364364
//! Return implementation of Node interface.
365-
std::unique_ptr<Node> MakeNode(NodeContext* context = nullptr);
365+
std::unique_ptr<Node> MakeNode(NodeContext& context);
366366

367367
//! Block tip (could be a header or not, depends on the subscribed signal).
368368
struct BlockTip {

src/node/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class NodeImpl : public Node
305305
MasternodeSyncImpl m_masternodeSync;
306306
CoinJoinOptionsImpl m_coinjoin;
307307

308-
explicit NodeImpl(NodeContext* context) { setContext(context); }
308+
explicit NodeImpl(NodeContext& context) { setContext(&context); }
309309
void initLogging() override { InitLogging(*Assert(m_context->args)); }
310310
void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
311311
bilingual_str getWarnings() override { return GetWarnings(true); }
@@ -1026,6 +1026,6 @@ class ChainImpl : public Chain
10261026
} // namespace node
10271027

10281028
namespace interfaces {
1029-
std::unique_ptr<Node> MakeNode(NodeContext* context) { return std::make_unique<node::NodeImpl>(context); }
1029+
std::unique_ptr<Node> MakeNode(NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
10301030
std::unique_ptr<Chain> MakeChain(NodeContext& node) { return std::make_unique<node::ChainImpl>(node); }
10311031
} // namespace interfaces

0 commit comments

Comments
 (0)