-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#19160: multiprocess: Add basic spawn and IPC su…
…pport 84934bf multiprocess: Add echoipc RPC method and test (Russell Yanofsky) 7d76cf6 multiprocess: Add comments and documentation (Russell Yanofsky) ddf7ecc multiprocess: Add bitcoin-node process spawning support (Russell Yanofsky) 10afdf0 multiprocess: Add Ipc interface implementation (Russell Yanofsky) 745c9ce multiprocess: Add Ipc and Init interface definitions (Russell Yanofsky) 5d62d7f Update libmultiprocess library (Russell Yanofsky) Pull request description: This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). --- This PR adds basic process spawning and IPC method call support to `bitcoin-node` executables built with `--enable-multiprocess`[*]. These changes are used in bitcoin/bitcoin#10102 to let node, gui, and wallet functionality run in different processes, and extended in bitcoin/bitcoin#19460 and bitcoin/bitcoin#19461 after that to allow gui and wallet processes to be started and stopped independently and connect to the node over a socket. These changes can also be used to implement new functionality outside the `bitcoin-node` process like external indexes or pluggable transports (bitcoin/bitcoin#18988). The `Ipc::spawnProcess` and `Ipc::serveProcess` methods added here are entry points for spawning a child process and serving a parent process, and being able to make bidirectional, multithreaded method calls between the processes. A simple example of this is implemented in commit "Add echoipc RPC method and test." Changes in this PR aside from the echo test were originally part of #10102, but have been split and moved here for easier review, and so they can be used for other applications like external plugins. Additional notes about this PR can be found at https://bitcoincore.reviews/19160 [*] Note: the `--enable-multiprocess` feature is still experimental, and not enabled by default, and not yet supported on windows. More information can be found in [doc/multiprocess.md](https://github.com/bitcoin/bitcoin/blob/master/doc/multiprocess.md) ACKs for top commit: fjahr: re-ACK 84934bf ariard: ACK 84934bf. Changes since last ACK fixes the silent merge conflict about `EnsureAnyNodeContext()`. Rebuilt and checked again debug command `echoipc`. Tree-SHA512: 52a948b5e18a26d7d7a09b83003eaae9b1ed2981978c36c959fe9a55abf70ae6a627c4ff913a3428be17400a3dace30c58b5057fa75c319662c3be98f19810c6
- Loading branch information
Showing
30 changed files
with
805 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2021 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 <interfaces/echo.h> | ||
#include <interfaces/init.h> | ||
#include <interfaces/ipc.h> | ||
#include <node/context.h> | ||
|
||
#include <memory> | ||
|
||
namespace init { | ||
namespace { | ||
const char* EXE_NAME = "bitcoin-node"; | ||
|
||
class BitcoinNodeInit : public interfaces::Init | ||
{ | ||
public: | ||
BitcoinNodeInit(NodeContext& node, const char* arg0) | ||
: m_node(node), | ||
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) | ||
{ | ||
m_node.init = this; | ||
} | ||
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); } | ||
interfaces::Ipc* ipc() override { return m_ipc.get(); } | ||
NodeContext& m_node; | ||
std::unique_ptr<interfaces::Ipc> m_ipc; | ||
}; | ||
} // namespace | ||
} // namespace init | ||
|
||
namespace interfaces { | ||
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status) | ||
{ | ||
auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : ""); | ||
// Check if bitcoin-node is being invoked as an IPC server. If so, then | ||
// bypass normal execution and just respond to requests over the IPC | ||
// channel and return null. | ||
if (init->m_ipc->startSpawnedProcess(argc, argv, exit_status)) { | ||
return nullptr; | ||
} | ||
return init; | ||
} | ||
} // namespace interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2021 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 <interfaces/init.h> | ||
#include <node/context.h> | ||
|
||
#include <memory> | ||
|
||
namespace init { | ||
namespace { | ||
class BitcoindInit : public interfaces::Init | ||
{ | ||
public: | ||
BitcoindInit(NodeContext& node) : m_node(node) | ||
{ | ||
m_node.init = this; | ||
} | ||
NodeContext& m_node; | ||
}; | ||
} // namespace | ||
} // namespace init | ||
|
||
namespace interfaces { | ||
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status) | ||
{ | ||
return std::make_unique<init::BitcoindInit>(node); | ||
} | ||
} // namespace interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2021 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 <interfaces/echo.h> | ||
|
||
#include <memory> | ||
|
||
namespace interfaces { | ||
namespace { | ||
class EchoImpl : public Echo | ||
{ | ||
public: | ||
std::string echo(const std::string& echo) override { return echo; } | ||
}; | ||
} // namespace | ||
std::unique_ptr<Echo> MakeEcho() { return std::make_unique<EchoImpl>(); } | ||
} // namespace interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2021 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_INTERFACES_ECHO_H | ||
#define BITCOIN_INTERFACES_ECHO_H | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace interfaces { | ||
//! Simple string echoing interface for testing. | ||
class Echo | ||
{ | ||
public: | ||
virtual ~Echo() {} | ||
|
||
//! Echo provided string. | ||
virtual std::string echo(const std::string& echo) = 0; | ||
}; | ||
|
||
//! Return implementation of Echo interface. | ||
std::unique_ptr<Echo> MakeEcho(); | ||
} // namespace interfaces | ||
|
||
#endif // BITCOIN_INTERFACES_ECHO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2021 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 <interfaces/chain.h> | ||
#include <interfaces/echo.h> | ||
#include <interfaces/init.h> | ||
#include <interfaces/node.h> | ||
#include <interfaces/wallet.h> | ||
|
||
namespace interfaces { | ||
std::unique_ptr<Node> Init::makeNode() { return {}; } | ||
std::unique_ptr<Chain> Init::makeChain() { return {}; } | ||
std::unique_ptr<WalletClient> Init::makeWalletClient(Chain& chain) { return {}; } | ||
std::unique_ptr<Echo> Init::makeEcho() { return {}; } | ||
Ipc* Init::ipc() { return nullptr; } | ||
} // namespace interfaces |
Oops, something went wrong.