Skip to content

Commit 528e081

Browse files
committed
Merge bitcoin/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 #10102. ACKs for top commit: jamesob: reACK bitcoin/bitcoin@e4709c7 achow101: ACK e4709c7 benthecarman: utACK e4709c7 Tree-SHA512: 580c1979dbb2ef444157c8e53041e70d15ddeee77e5cbdb34f70b6d228cc2d2fe3843825f172da84e506200c58f7e0932f7cd4c006bb5058c1f4e43259394834
2 parents 2161a05 + e4709c7 commit 528e081

File tree

17 files changed

+63
-22
lines changed

17 files changed

+63
-22
lines changed

build_msvc/bitcoin-qt/bitcoin-qt.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<ClCompile Include="..\..\src\qt\main.cpp" />
12+
<ClCompile Include="..\..\src\init\bitcoind.cpp" />
1213
<ResourceCompile Include="..\..\src\qt\res\bitcoin-qt-res.rc" />
1314
</ItemGroup>
1415
<ItemGroup>

build_msvc/test_bitcoin-qt/test_bitcoin-qt.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
99
</PropertyGroup>
1010
<ItemGroup>
11+
<ClCompile Include="..\..\src\init\bitcoind.cpp" />
1112
<ClCompile Include="..\..\src\test\util\setup_common.cpp" />
1213
<ClCompile Include="..\..\src\qt\test\addressbooktests.cpp" />
1314
<ClCompile Include="..\..\src\qt\test\apptests.cpp" />

src/Makefile.qt.include

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

339339
qt_bitcoin_qt_CPPFLAGS = $(bitcoin_qt_cppflags)
340340
qt_bitcoin_qt_CXXFLAGS = $(bitcoin_qt_cxxflags)
341-
qt_bitcoin_qt_SOURCES = $(bitcoin_qt_sources)
341+
qt_bitcoin_qt_SOURCES = $(bitcoin_qt_sources) init/bitcoind.cpp
342342
qt_bitcoin_qt_LDADD = $(bitcoin_qt_ldadd)
343343
qt_bitcoin_qt_LDFLAGS = $(bitcoin_qt_ldflags)
344344
qt_bitcoin_qt_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)
345345

346346
bitcoin_gui_CPPFLAGS = $(bitcoin_qt_cppflags)
347347
bitcoin_gui_CXXFLAGS = $(bitcoin_qt_cxxflags)
348-
bitcoin_gui_SOURCES = $(bitcoin_qt_sources)
348+
bitcoin_gui_SOURCES = $(bitcoin_qt_sources) init/bitcoind.cpp
349349
bitcoin_gui_LDADD = $(bitcoin_qt_ldadd)
350350
bitcoin_gui_LDFLAGS = $(bitcoin_qt_ldflags)
351351
bitcoin_gui_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)

src/Makefile.qttest.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ qt_test_test_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_
2828
$(QT_INCLUDES) $(QT_TEST_INCLUDES)
2929

3030
qt_test_test_bitcoin_qt_SOURCES = \
31+
init/bitcoind.cpp \
3132
qt/test/apptests.cpp \
3233
qt/test/rpcnestedtests.cpp \
3334
qt/test/test_main.cpp \

src/dummywallet.cpp

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

8+
class ArgsManager;
89
class CWallet;
910

1011
namespace interfaces {
1112
class Chain;
1213
class Handler;
1314
class Wallet;
15+
class WalletClient;
1416
}
1517

1618
class DummyWalletInit : public WalletInitInterface {
@@ -64,4 +66,9 @@ std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet)
6466
throw std::logic_error("Wallet function called in non-wallet build.");
6567
}
6668

69+
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args)
70+
{
71+
throw std::logic_error("Wallet function called in non-wallet build.");
72+
}
73+
6774
} // namespace interfaces

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <index/txindex.h>
2727
#include <init/common.h>
2828
#include <interfaces/chain.h>
29+
#include <interfaces/init.h>
2930
#include <interfaces/node.h>
3031
#include <mapport.h>
3132
#include <miner.h>
@@ -1063,7 +1064,7 @@ bool AppInitLockDataDirectory()
10631064

10641065
bool AppInitInterfaces(NodeContext& node)
10651066
{
1066-
node.chain = interfaces::MakeChain(node);
1067+
node.chain = node.init->makeChain();
10671068
// Create client interfaces for wallets that are supposed to be loaded
10681069
// according to -wallet and -disablewallet options. This only constructs
10691070
// the interfaces, it doesn't load wallet data. Wallets actually get loaded

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::WalletClient> makeWalletClient(interfaces::Chain& chain) override
33+
{
34+
return MakeWalletClient(chain, *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::WalletClient> makeWalletClient(interfaces::Chain& chain) override
28+
{
29+
return MakeWalletClient(chain, *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/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Node
230230
};
231231

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

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

src/node/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class NodeImpl : public Node
7272
private:
7373
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
7474
public:
75-
explicit NodeImpl(NodeContext* context) { setContext(context); }
75+
explicit NodeImpl(NodeContext& context) { setContext(&context); }
7676
void initLogging() override { InitLogging(*Assert(m_context->args)); }
7777
void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
7878
bilingual_str getWarnings() override { return GetWarnings(true); }
@@ -710,6 +710,6 @@ class ChainImpl : public Chain
710710
} // namespace node
711711

712712
namespace interfaces {
713-
std::unique_ptr<Node> MakeNode(NodeContext* context) { return std::make_unique<node::NodeImpl>(context); }
713+
std::unique_ptr<Node> MakeNode(NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
714714
std::unique_ptr<Chain> MakeChain(NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
715715
} // namespace interfaces

0 commit comments

Comments
 (0)