Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocess bitcoin #7

Open
wants to merge 23 commits into
base: bitcoin-fresheyes-master-10102
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0be3913
serialization: Support for multiple parameters
ryanofsky Nov 22, 2023
422bd2d
test: add ipc test to test multiprocess type conversion code
ryanofsky Nov 20, 2023
de13c17
serialization: Drop unnecessary ParamsStream references
ryanofsky Nov 22, 2023
c9dad8d
multiprocess: Add type conversion code for serializable types
ryanofsky Nov 20, 2023
9e9dfce
serialization: Reverse ParamsStream constructor order
ryanofsky Nov 22, 2023
afce182
multiprocess: Add type conversion code for UniValue types
ryanofsky Nov 20, 2023
ffc1e9f
serialization: Accept multiple parameters in ParamsStream constructor
ryanofsky Nov 22, 2023
ca82b45
Merge remote-tracking branch 'origin/pull/28921/head'
ryanofsky Jan 11, 2024
d27c337
Merge remote-tracking branch 'origin/pull/28929/head'
ryanofsky Jan 11, 2024
ee4b913
doc: multiprocess documentation improvements
ryanofsky Jan 11, 2024
df27e30
Increase feature_block.py and feature_taproot.py timeouts
ryanofsky Dec 5, 2017
cbc5e36
Add util::Result workaround to be compatible with libmultiprocess
ryanofsky Aug 24, 2022
3427e7e
Add capnp serialization code for bitcoin types
ryanofsky Dec 5, 2017
b6516c4
Add capnp wrapper for Handler interface
ryanofsky Dec 5, 2017
5cf30e5
Add capnp wrapper for Chain interface
ryanofsky Dec 5, 2017
b5fd425
Add capnp wrapper for Wallet interface
ryanofsky Nov 28, 2023
329b34c
Add capnp wrapper for Node interface
ryanofsky Dec 5, 2017
dde2a22
Make bitcoin-gui spawn a bitcoin-node process
ryanofsky Dec 5, 2017
f3349a2
Make bitcoin-node spawn a bitcoin-wallet process
ryanofsky Dec 5, 2017
6ea638c
multiprocess: Add debug.log .wallet/.gui suffixes
ryanofsky Aug 30, 2021
622acd0
doc: Multiprocess misc doc and comment updates
ryanofsky Dec 5, 2017
755ca62
combine_logs: Handle multiprocess wallet log files
ryanofsky Dec 5, 2017
56ef459
Update libmultiprocess library
ryanofsky Jan 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_msvc/test_bitcoin/test_bitcoin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<ClCompile Include="..\..\src\test\*_properties.cpp" />
<ClCompile Include="..\..\src\test\*_tests.cpp" />
<ClCompile Include="..\..\src\test\*_tests.cpp" Exclude="..\..\src\test\ipc_tests.cpp" />
<ClCompile Include="..\..\src\test\gen\*_gen.cpp" />
<ClCompile Include="..\..\src\test\main.cpp" />
<ClCompile Include="..\..\src\test\util\*.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion contrib/devtools/circular-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# define functions and variables declared in corresponding .h files is
# incorrect.
HEADER_MODULE_PATHS = [
'interfaces/'
'ipc/'
]

def module_name(path):
Expand Down
4 changes: 2 additions & 2 deletions depends/packages/native_libmultiprocess.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package=native_libmultiprocess
$(package)_version=414542f81e0997354b45b8ade13ca144a3e35ff1
$(package)_version=2cbbd09d8b9972a8f5c68b510c0dae9a9f7a22da
$(package)_download_path=https://github.com/chaincodelabs/libmultiprocess/archive
$(package)_file_name=$($(package)_version).tar.gz
$(package)_sha256_hash=8542dbaf8c4fce8fd7af6929f5dc9b34dffa51c43e9ee360e93ee0f34b180bc2
$(package)_sha256_hash=a86416908cc4d27a41c58d846ca854730b1c56bd7a58d823348969e300a10014
$(package)_dependencies=native_capnp

define $(package)_config_cmds
Expand Down
2 changes: 1 addition & 1 deletion doc/build-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ See [dependencies.md](dependencies.md) for a complete overview.
To install, run the following from your terminal:

``` bash
brew install automake libtool boost pkg-config libevent
brew install automake libtool boost pkg-config libevent capnp
```

### 4. Clone Bitcoin repository
Expand Down
2 changes: 1 addition & 1 deletion doc/build-unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ To build without GUI pass `--without-gui`.

To build with Qt 5 you need the following:

sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools
sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libcapnp-dev capnproto

Additionally, to support Wayland protocol for modern desktop environments:

Expand Down
4 changes: 4 additions & 0 deletions doc/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ You can find installation instructions in the `build-*.md` file for your platfor
| --- | --- | --- | --- | --- |
| [Berkeley DB](../depends/packages/bdb.mk) (legacy wallet) | [link](https://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html) | 4.8.30 | 4.8.x | No |
| [SQLite](../depends/packages/sqlite.mk) | [link](https://sqlite.org) | [3.38.5](https://github.com/bitcoin/bitcoin/pull/25378) | [3.7.17](https://github.com/bitcoin/bitcoin/pull/19077) | No |

### Multiprocess support
| Dependency | Releases | Version used | Minimum required | Runtime |
| [Cap'n Proto](../depends/packages/capnp.mk) | [link](https://capnproto.org) | [0.6.1](https://capnproto.org/install.html) | 0.5.3 | Yes |
8 changes: 4 additions & 4 deletions doc/design/multiprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ This section describes the major components of the Inter-Process Communication (
- In the generated code, we have C++ client subclasses that inherit from the abstract classes in [`src/interfaces/`](../../src/interfaces/). These subclasses are the workhorses of the IPC mechanism.
- They implement all the methods of the interface, marshalling arguments into a structured format, sending them as requests to the IPC server via a UNIX socket, and handling the responses.
- These subclasses effectively mask the complexity of IPC, presenting a familiar C++ interface to developers.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests. The Cap'n Proto client classes are low-level, with non-blocking methods that use asynchronous I/O and pass request and response objects, while mpgen client subclasses provide normal C++ methods that block while executing and convert between request/response objects and arguments/return values.

### C++ Server Classes in Generated Code
- On the server side, corresponding generated C++ classes receive IPC requests. These server classes are responsible for unmarshalling method arguments, invoking the corresponding methods in the local [`src/interfaces/`](../../src/interfaces/) objects, and creating the IPC response.
Expand Down Expand Up @@ -142,7 +142,7 @@ In the current design, class names, method names, and parameter names are duplic

An alternate approach could use custom [C++ Attributes](https://en.cppreference.com/w/cpp/language/attributes) embedded in interface declarations to automatically generate `.capnp` files from C++ headers. This has not been pursued because parsing C++ headers is more complicated than parsing Cap’n Proto interface definitions, especially portably on multiple platforms.

In the meantime, the developer guide [Internal interface guidelines](developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.
In the meantime, the developer guide [Internal interface guidelines](../developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.

### Interface Stability

Expand Down Expand Up @@ -197,7 +197,7 @@ sequenceDiagram
- Upon receiving the request, the Cap'n Proto dispatching code in the `bitcoin-node` process calls the `getBlockHash` method of the `Chain` [server class](#c-server-classes-in-generated-code).
- The server class is automatically generated by the `mpgen` tool from the [`chain.capnp`](https://github.com/ryanofsky/bitcoin/blob/pr/ipc/src/ipc/capnp/chain.capnp) file in [`src/ipc/capnp/`](../../src/ipc/capnp/).
- The `getBlockHash` method of the generated `Chain` server subclass in `bitcoin-wallet` receives a Cap’n Proto request object with the `height` parameter, and calls the `getBlockHash` method on its local `Chain` object with the provided `height`.
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process,
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process.

5. **Response and Return**
- The `getBlockHash` method of the generated `Chain` client subclass in `bitcoin-wallet` which sent the request now receives the response.
Expand Down Expand Up @@ -232,7 +232,7 @@ This modularization represents an advancement in Bitcoin Core's architecture, of

- **Cap’n Proto struct**: A structured data format used in Cap’n Proto, similar to structs in C++, for organizing and transporting data across different processes.

- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))
- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin Core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))

- **IPC (inter-process communication)**: Mechanisms that enable processes to exchange requests and data.

Expand Down
10 changes: 9 additions & 1 deletion doc/multiprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ The multiprocess feature requires [Cap'n Proto](https://capnproto.org/) and [lib
```
cd <BITCOIN_SOURCE_DIRECTORY>
make -C depends NO_QT=1 MULTIPROCESS=1
CONFIG_SITE=$PWD/depends/x86_64-pc-linux-gnu/share/config.site ./configure
# Set host platform to output of gcc -dumpmachine or clang -dumpmachine or check the depends/ directory for the generated subdirectory name
HOST_PLATFORM="x86_64-pc-linux-gnu"
CONFIG_SITE="$PWD/depends/$HOST_PLATFORM/share/config.site" ./configure
make
src/bitcoin-node -regtest -printtoconsole -debug=ipc
BITCOIND=bitcoin-node test/functional/test_runner.py
Expand All @@ -32,3 +34,9 @@ Alternately, you can install [Cap'n Proto](https://capnproto.org/) and [libmulti
`bitcoin-node` is a drop-in replacement for `bitcoind`, and `bitcoin-gui` is a drop-in replacement for `bitcoin-qt`, and there are no differences in use or external behavior between the new and old executables. But internally after [#10102](https://github.com/bitcoin/bitcoin/pull/10102), `bitcoin-gui` will spawn a `bitcoin-node` process to run P2P and RPC code, communicating with it across a socket pair, and `bitcoin-node` will spawn `bitcoin-wallet` to run wallet code, also communicating over a socket pair. This will let node, wallet, and GUI code run in separate address spaces for better isolation, and allow future improvements like being able to start and stop components independently on different machines and environments.
[#19460](https://github.com/bitcoin/bitcoin/pull/19460) also adds a new `bitcoin-node` `-ipcbind` option and an `bitcoind-wallet` `-ipcconnect` option to allow new wallet processes to connect to an existing node process.
And [#19461](https://github.com/bitcoin/bitcoin/pull/19461) adds a new `bitcoin-gui` `-ipcconnect` option to allow new GUI processes to connect to an existing node process.

## Known issues

- Unexpected socket disconnects aren't handled cleanly many places. Interface calls that used to never throw can now throw exceptions if a socket is disconnected (typically because a process on the other side of the connection has crashed or been killed), leading to errors.

- Internally spawned bitcoin-node and bitcoin-wallet processes don't currently install signal handlers and so won't shut down cleanly if terminated with [CTRL-C](https://github.com/bitcoin/bitcoin/pull/10102#issuecomment-595353238). Shutting down with `bitcoin-cli stop` should still shut down cleanly, and is a suggested alternative.
44 changes: 33 additions & 11 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ libbitcoin_node_a_SOURCES = \
node/context.cpp \
node/database_args.cpp \
node/eviction.cpp \
node/interface_ui.cpp \
node/interfaces.cpp \
node/kernel_notifications.cpp \
node/mempool_args.cpp \
Expand Down Expand Up @@ -690,6 +689,7 @@ libbitcoin_common_a_SOURCES = \
netaddress.cpp \
netbase.cpp \
net_permissions.cpp \
node/interface_ui.cpp \
outputtype.cpp \
policy/feerate.cpp \
policy/policy.cpp \
Expand Down Expand Up @@ -804,7 +804,7 @@ bitcoin_node_SOURCES = $(bitcoin_daemon_sources) init/bitcoin-node.cpp
bitcoin_node_CPPFLAGS = $(bitcoin_bin_cppflags)
bitcoin_node_CXXFLAGS = $(bitcoin_bin_cxxflags)
bitcoin_node_LDFLAGS = $(bitcoin_bin_ldflags)
bitcoin_node_LDADD = $(LIBBITCOIN_NODE) $(bitcoin_bin_ldadd) $(LIBBITCOIN_IPC) $(LIBMULTIPROCESS_LIBS)
bitcoin_node_LDADD = $(LIBBITCOIN_NODE) $(bitcoin_bin_ldadd) $(LIBBITCOIN_IPC) $(LIBMULTIPROCESS_LIBS) $(LIBBITCOIN_WALLET)

# bitcoin-cli binary #
bitcoin_cli_SOURCES = bitcoin-cli.cpp
Expand Down Expand Up @@ -847,21 +847,24 @@ bitcoin_tx_LDADD = \

# bitcoin-wallet binary #
bitcoin_wallet_SOURCES = bitcoin-wallet.cpp
if BUILD_MULTIPROCESS
bitcoin_wallet_SOURCES += init/bitcoin-wallet-ipc.cpp
# FIX: Dependency on kernel should be dropped. See BitcoinWalletInit constructor comment.
bitcoin_wallet_SOURCES += kernel/context.cpp
else
bitcoin_wallet_SOURCES += init/bitcoin-wallet.cpp
endif
bitcoin_wallet_CPPFLAGS = $(bitcoin_bin_cppflags)
bitcoin_wallet_CXXFLAGS = $(bitcoin_bin_cxxflags)
bitcoin_wallet_LDFLAGS = $(bitcoin_bin_ldflags)
bitcoin_wallet_LDADD = \
$(LIBBITCOIN_WALLET_TOOL) \
$(LIBBITCOIN_WALLET) \
$(bitcoin_bin_ldadd) \
$(LIBBITCOIN_IPC) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBUNIVALUE) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBSECP256K1) \
$(BDB_LIBS) \
$(SQLITE_LIBS)
$(LIBBITCOIN_UTIL) \
$(LIBMULTIPROCESS_LIBS)

if TARGET_WINDOWS
bitcoin_wallet_SOURCES += bitcoin-wallet-res.rc
Expand Down Expand Up @@ -1078,29 +1081,48 @@ if HARDEN
endif

libbitcoin_ipc_mpgen_input = \
ipc/capnp/chain.capnp \
ipc/capnp/common.capnp \
ipc/capnp/echo.capnp \
ipc/capnp/init.capnp
ipc/capnp/handler.capnp \
ipc/capnp/init.capnp \
ipc/capnp/node.capnp \
ipc/capnp/wallet.capnp
EXTRA_DIST += $(libbitcoin_ipc_mpgen_input)
%.capnp:

# Explicitly list dependencies on generated headers as described in
# https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html#Recording-Dependencies-manually
ipc/capnp/libbitcoin_ipc_a-chain.$(OBJEXT): $(libbitcoin_ipc_mpgen_input:=.h)
ipc/capnp/libbitcoin_ipc_a-common.$(OBJEXT): $(libbitcoin_ipc_mpgen_input:=.h)
ipc/capnp/libbitcoin_ipc_a-protocol.$(OBJEXT): $(libbitcoin_ipc_mpgen_input:=.h)

if BUILD_MULTIPROCESS
LIBBITCOIN_IPC=libbitcoin_ipc.a
libbitcoin_ipc_a_SOURCES = \
ipc/capnp/chain.cpp \
ipc/capnp/chain-types.h \
ipc/capnp/common.cpp \
ipc/capnp/common.h \
ipc/capnp/common-types.h \
ipc/capnp/context.h \
ipc/capnp/init-types.h \
ipc/capnp/init.cpp \
ipc/capnp/node-types.h \
ipc/capnp/node.cpp \
ipc/capnp/node.h \
ipc/capnp/protocol.cpp \
ipc/capnp/protocol.h \
ipc/capnp/wallet-types.h \
ipc/capnp/wallet.cpp \
ipc/capnp/wallet.h \
ipc/context.h \
ipc/exception.h \
ipc/interfaces.cpp \
ipc/process.cpp \
ipc/process.h \
ipc/protocol.h
libbitcoin_ipc_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_ipc_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DLIBMULTIPROCESS_IPC
libbitcoin_ipc_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(LIBMULTIPROCESS_CFLAGS)

include $(MPGEN_PREFIX)/include/mpgen.mk
Expand Down
36 changes: 36 additions & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,49 @@ BITCOIN_TEST_SUITE += \
wallet/test/init_test_fixture.h
endif # ENABLE_WALLET

if BUILD_MULTIPROCESS
# Add boost ipc_tests definition to BITCOIN_TESTS
BITCOIN_TESTS += test/ipc_tests.cpp

# Build ipc_test code in a separate library so it can be compiled with custom
# LIBMULTIPROCESS_CFLAGS without those flags affecting other tests
LIBBITCOIN_IPC_TEST=libbitcoin_ipc_test.a
EXTRA_LIBRARIES += $(LIBBITCOIN_IPC_TEST)
libbitcoin_ipc_test_a_SOURCES = \
test/ipc_test.cpp \
test/ipc_test.h
libbitcoin_ipc_test_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_ipc_test_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(LIBMULTIPROCESS_CFLAGS)

# Generate various .c++/.h files from the ipc_test.capnp file
include $(MPGEN_PREFIX)/include/mpgen.mk
EXTRA_DIST += test/ipc_test.capnp
libbitcoin_ipc_test_mpgen_output = \
test/ipc_test.capnp.c++ \
test/ipc_test.capnp.h \
test/ipc_test.capnp.proxy-client.c++ \
test/ipc_test.capnp.proxy-server.c++ \
test/ipc_test.capnp.proxy-types.c++ \
test/ipc_test.capnp.proxy-types.h \
test/ipc_test.capnp.proxy.h
nodist_libbitcoin_ipc_test_a_SOURCES = $(libbitcoin_ipc_test_mpgen_output)
CLEANFILES += $(libbitcoin_ipc_test_mpgen_output)
endif

# Explicitly list dependencies on generated headers as described in
# https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html#Recording-Dependencies-manually
test/libbitcoin_ipc_test_a-ipc_test.$(OBJEXT): test/ipc_test.capnp.h

test_test_bitcoin_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(BOOST_CPPFLAGS) $(EVENT_CFLAGS)
test_test_bitcoin_LDADD = $(LIBTEST_UTIL)
if ENABLE_WALLET
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
test_test_bitcoin_CPPFLAGS += $(BDB_CPPFLAGS)
endif
if BUILD_MULTIPROCESS
test_test_bitcoin_LDADD += $(LIBBITCOIN_IPC_TEST) $(LIBMULTIPROCESS_LIBS)
endif

test_test_bitcoin_LDADD += $(LIBBITCOIN_NODE) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \
$(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(MINISKETCH_LIBS)
Expand Down
4 changes: 2 additions & 2 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void AddrManImpl::Serialize(Stream& s_) const
*/

// Always serialize in the latest version (FILE_FORMAT).
ParamsStream s{CAddress::V2_DISK, s_};
ParamsStream s{s_, CAddress::V2_DISK};

s << static_cast<uint8_t>(FILE_FORMAT);

Expand Down Expand Up @@ -236,7 +236,7 @@ void AddrManImpl::Unserialize(Stream& s_)
s_ >> Using<CustomUintFormatter<1>>(format);

const auto ser_params = (format >= Format::V3_BIP155 ? CAddress::V2_DISK : CAddress::V1_DISK);
ParamsStream s{ser_params, s_};
ParamsStream s{s_, ser_params};

uint8_t compat;
s >> compat;
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <tuple>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = nullptr;
UrlDecodeFn* const URL_DECODE = urlDecode;

static void SetupWalletToolArgs(ArgsManager& argsman)
{
Expand Down
4 changes: 3 additions & 1 deletion src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
#include <node/context.h>
#include <node/interface_ui.h>
#include <noui.h>
Expand Down Expand Up @@ -172,7 +173,8 @@ static bool AppInit(NodeContext& node)
// -server defaults to true for bitcoind but not for the GUI so do this here
args.SoftSetBoolArg("-server", true);
// Set this early so that parameter interactions go to console
InitLogging(args);
interfaces::Ipc* ipc = node.init->ipc();
InitLogging(args, ipc ? ipc->logSuffix() : nullptr);
InitParameterInteraction(args);
if (!AppInitBasicSetup(args, node.exit_status)) {
// InitError will have been called with detailed error, which ends up on console
Expand Down
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ void InitParameterInteraction(ArgsManager& args)
* Note that this is called very early in the process lifetime, so you should be
* careful about what global state you rely on here.
*/
void InitLogging(const ArgsManager& args)
void InitLogging(const ArgsManager& args, const char* log_suffix)
{
init::SetLoggingOptions(args);
init::SetLoggingOptions(args, log_suffix);
init::LogPackageVersion();
}

Expand Down
2 changes: 1 addition & 1 deletion src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool ShutdownRequested(node::NodeContext& node);
void Interrupt(node::NodeContext& node);
void Shutdown(node::NodeContext& node);
//!Initialize the logging infrastructure
void InitLogging(const ArgsManager& args);
void InitLogging(const ArgsManager& args, const char* log_suffix);
//!Parameter interaction: change current parameters depending on various rules
void InitParameterInteraction(ArgsManager& args);

Expand Down
24 changes: 8 additions & 16 deletions src/init/bitcoin-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,30 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <node/context.h>
#include <util/check.h>

#include <memory>

namespace ipc {
namespace capnp {
void SetupNodeClient(ipc::Context& context);
} // namespace capnp
} // namespace ipc

namespace init {
namespace {
const char* EXE_NAME = "bitcoin-gui";

class BitcoinGuiInit : public interfaces::Init
{
public:
BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{
InitContext(m_node);
m_node.init = this;
}
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }
std::unique_ptr<interfaces::Chain> makeChain() override { return interfaces::MakeChain(m_node); }
std::unique_ptr<interfaces::WalletLoader> makeWalletLoader(interfaces::Chain& chain) override
BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, ".gui", arg0, *this))
{
return MakeWalletLoader(chain, *Assert(m_node.args));
ipc::capnp::SetupNodeClient(m_ipc->context());
}
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
node::NodeContext m_node;
std::unique_ptr<interfaces::Ipc> m_ipc;
};
} // namespace
Expand Down
Loading
Loading