Merge bitcoin/bitcoin#32297: bitcoin-cli: Add -ipcconnect option

4565cff72c bitcoin-gui: Implement missing Init::makeMining method (Ryan Ofsky)
fbea576c26 test: add interface_ipc_cli.py testing bitcoin-cli -ipcconnect (Ryan Ofsky)
0448a19b1b ipc: Improve -ipcconnect error checking (Ryan Ofsky)
8d614bfa47 bitcoin-cli: Add -ipcconnect option (Ryan Ofsky)
6a54834895 ipc: Expose an RPC interface over the -ipcbind socket (Ryan Ofsky)
df76891a3b refactor: Add ExecuteHTTPRPC function (Ryan Ofsky)
3cd1cd3ad3 ipc: Add MakeBasicInit function (Ryan Ofsky)

Pull request description:

  This implements an idea from sipa in https://github.com/bitcoin/bitcoin/issues/28722#issuecomment-2807026958 to allow `bitcoin-cli` to connect to the node via IPC instead of TCP, if the ENABLE_IPC cmake option is enabled and the node has been started with `-ipcbind`.

  This feature can be tested with:

  ```
  build/bin/bitcoin-node -regtest -ipcbind=unix -debug=ipc
  build/bin/bitcoin-cli -regtest -ipcconnect=unix -getinfo
  ```

  The -ipconnect parameter can also be omitted, since this change also makes `bitcoin-cli` prefer IPC over HTTP by default, and falling back to HTTP if an IPC connection can't be established.

  ---

  This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/issues/28722).

ACKs for top commit:
  achow101:
    ACK 4565cff72c
  pinheadmz:
    ACK 4565cff72c
  enirox001:
    Tested ACK 4565cff72c

Tree-SHA512: cb0dc521d82591e4eb2723a37ae60949309a206265e0ccfbee1f4d59b426b770426fafa1e842819a2fa27322ecdfcd226f31da70f91c2c31b8095e1380666f1f
This commit is contained in:
Ava Chow
2026-03-30 15:12:04 -07:00
25 changed files with 389 additions and 87 deletions

View File

@@ -16,4 +16,6 @@ The following interfaces are defined here:
* [`Ipc`](ipc.h) — used by multiprocess code to access `Init` interface across processes. Added in [#19160](https://github.com/bitcoin/bitcoin/pull/19160).
* [`Rpc`](rpc.h) — used by `bitcoin-cli` to be able to call RPC methods over a unix socket instead of TCP.
The interfaces above define boundaries between major components of bitcoin code (node, wallet, and gui), making it possible for them to run in [different processes](../../doc/multiprocess.md), and be tested, developed, and understood independently. These interfaces are not currently designed to be stable or to be used externally.

View File

@@ -9,6 +9,7 @@
#include <interfaces/echo.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/rpc.h>
#include <interfaces/wallet.h>
#include <memory>
@@ -36,6 +37,7 @@ public:
virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
virtual std::unique_ptr<Rpc> makeRpc() { return nullptr; }
virtual Ipc* ipc() { return nullptr; }
virtual bool canListenIpc() { return false; }
virtual const char* exeName() { return nullptr; }
@@ -55,6 +57,25 @@ std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);
//! Return implementation of Init interface for the gui process.
std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);
//! Return implementation of Init interface for a basic IPC client that doesn't
//! provide any IPC services itself.
//!
//! When an IPC client connects to a socket or spawns a process, it gets a pointer
//! to an Init object allowing it to create objects and threads on the remote
//! side of the IPC connection. But the client also needs to provide a local Init
//! object to allow the remote side of the connection to create objects and
//! threads on this side. This function just returns a basic Init object
//! allowing remote connections to only create local threads, not other objects
//! (because its Init::make* methods return null.)
//!
//! @param exe_name Current executable name, which is just passed to the IPC
//! system and used for logging.
//!
//! @param process_argv0 Optional string containing argv[0] value passed to
//! main(). This is passed to the IPC system and used to locate binaries by
//! relative path if subprocesses are spawned.
std::unique_ptr<Init> MakeBasicInit(const char* exe_name, const char* process_argv0="");
} // namespace interfaces
#endif // BITCOIN_INTERFACES_INIT_H

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <memory>
#include <string>
#include <typeindex>
namespace ipc {

31
src/interfaces/rpc.h Normal file
View File

@@ -0,0 +1,31 @@
// Copyright (c) 2025 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_RPC_H
#define BITCOIN_INTERFACES_RPC_H
#include <memory>
#include <string>
class UniValue;
namespace node {
struct NodeContext;
} // namespace node
namespace interfaces {
//! Interface giving clients ability to emulate HTTP RPC calls.
class Rpc
{
public:
virtual ~Rpc() = default;
virtual UniValue executeRpc(UniValue request, std::string url, std::string user) = 0;
};
//! Return implementation of Rpc interface.
std::unique_ptr<Rpc> MakeRpc(node::NodeContext& node);
} // namespace interfaces
#endif // BITCOIN_INTERFACES_RPC_H