Skip to content

Commit 5d1377b

Browse files
committed
build: multiprocess autotools changes
autoconf and automake changes to support multiprocess gui/node/wallet execution. This adds a new --enable-multiprocess flag, and build configuration code to detect libraries needed for multiprocess support. The --enable-multiprocess flag builds new bitcoin-node and bitcoin-gui executables, which are updated in bitcoin/bitcoin#10102 to communicate across processes. But for now they are functionally equivalent to existing bitcoind and bitcoin-qt executables.
1 parent 8da1e43 commit 5d1377b

File tree

5 files changed

+160
-41
lines changed

5 files changed

+160
-41
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
src/bitcoin
66
src/bitcoind
77
src/bitcoin-cli
8+
src/bitcoin-gui
9+
src/bitcoin-node
810
src/bitcoin-tx
911
src/bitcoin-wallet
1012
src/test/fuzz

configure.ac

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ if test x$enable_bip70 != xno; then
242242
AC_MSG_ERROR([BIP70 is no longer supported!])
243243
fi
244244

245+
AC_ARG_WITH([libmultiprocess],
246+
[AS_HELP_STRING([--with-libmultiprocess=yes|no|auto],
247+
[Build with libmultiprocess library. (default: auto, i.e. detect with pkg-config)])],
248+
[with_libmultiprocess=$withval],
249+
[with_libmultiprocess=auto])
250+
251+
AC_ARG_WITH([mpgen],
252+
[AS_HELP_STRING([--with-mpgen=yes|no|auto|PREFIX],
253+
[Build with libmultiprocess codegen tool. Useful to specify different libmultiprocess host system library and build system codegen tool prefixes when cross-compiling (default is host system libmultiprocess prefix)])],
254+
[with_mpgen=$withval],
255+
[with_mpgen=auto])
256+
257+
AC_ARG_ENABLE([multiprocess],
258+
[AS_HELP_STRING([--enable-multiprocess],
259+
[build multiprocess bitcoin-node, bitcoin-wallet, and bitcoin-gui executables in addition to monolithic bitcoind and bitcoin-qt executables. Requires libmultiprocess library. Experimental (default is no)])],
260+
[enable_multiprocess=$enableval],
261+
[enable_multiprocess=no])
262+
245263
AC_ARG_ENABLE(man,
246264
[AS_HELP_STRING([--disable-man],
247265
[do not install man pages (default is to install)])],,
@@ -1426,6 +1444,50 @@ AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
14261444
AC_SUBST(UNIVALUE_CFLAGS)
14271445
AC_SUBST(UNIVALUE_LIBS)
14281446

1447+
dnl libmultiprocess library check
1448+
1449+
libmultiprocess_found=no
1450+
if test "x$with_libmultiprocess" = xyes || test "x$with_libmultiprocess" = xauto; then
1451+
if test "x$use_pkgconfig" = xyes; then
1452+
m4_ifdef([PKG_CHECK_MODULES], [PKG_CHECK_MODULES([LIBMULTIPROCESS], [libmultiprocess], [
1453+
libmultiprocess_found=yes;
1454+
libmultiprocess_prefix=`$PKG_CONFIG --variable=prefix libmultiprocess`;
1455+
], [true])])
1456+
fi
1457+
elif test "x$with_libmultiprocess" != xno; then
1458+
AC_MSG_ERROR([--with-libmultiprocess=$with_libmultiprocess value is not yes, auto, or no])
1459+
fi
1460+
AC_SUBST(LIBMULTIPROCESS_CFLAGS)
1461+
AC_SUBST(LIBMULTIPROCESS_LIBS)
1462+
1463+
dnl Enable multiprocess check
1464+
1465+
if test "x$enable_multiprocess" = xyes; then
1466+
if test "x$libmultiprocess_found" != xyes; then
1467+
AC_MSG_ERROR([--enable-multiprocess=yes option specified but libmultiprocess library was not found. May need to install libmultiprocess library, or specify install path with PKG_CONFIG_PATH environment variable. Running 'pkg-config --debug libmultiprocess' may be helpful for debugging.])
1468+
fi
1469+
build_multiprocess=yes
1470+
elif test "x$enable_multiprocess" = xauto; then
1471+
build_multiprocess=$libmultiprocess_found
1472+
else
1473+
build_multiprocess=no
1474+
fi
1475+
1476+
AM_CONDITIONAL([BUILD_MULTIPROCESS],[test "x$build_multiprocess" = xyes])
1477+
AM_CONDITIONAL([BUILD_BITCOIN_NODE], [test "x$build_multiprocess" = xyes])
1478+
AM_CONDITIONAL([BUILD_BITCOIN_GUI], [test "x$build_multiprocess" = xyes])
1479+
1480+
dnl codegen tools check
1481+
1482+
if test x$build_multiprocess != xno; then
1483+
if test "x$with_mpgen" = xyes || test "x$with_mpgen" = xauto; then
1484+
MPGEN_PREFIX="$libmultiprocess_prefix"
1485+
elif test "x$with_mpgen" != xno; then
1486+
MPGEN_PREFIX="$with_mpgen";
1487+
fi
1488+
AC_SUBST(MPGEN_PREFIX)
1489+
fi
1490+
14291491
AC_MSG_CHECKING([whether to build bitcoind])
14301492
AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
14311493
AC_MSG_RESULT($build_bitcoind)
@@ -1704,6 +1766,7 @@ esac
17041766

17051767
echo
17061768
echo "Options used to compile and link:"
1769+
echo " multiprocess = $build_multiprocess"
17071770
echo " with wallet = $enable_wallet"
17081771
echo " with gui / qt = $bitcoin_enable_qt"
17091772
if test x$bitcoin_enable_qt != xno; then

doc/multiprocess.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Multiprocess Bitcoin
2+
3+
On unix systems, the `--enable-multiprocess` build option can be passed to `./configure` to build new `bitcoin-node`, `bitcoin-wallet`, and `bitcoin-gui` executables alongside existing `bitcoind` and `bitcoin-qt` executables.
4+
5+
`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.
6+
7+
## Next steps
8+
9+
Specific next steps after [#10102](https://github.com/bitcoin/bitcoin/pull/10102) will be:
10+
11+
- [ ] Adding `-ipcbind` and `-ipcconnect` options to `bitcoin-node`, `bitcoin-wallet`, and `bitcoin-gui` executables so they can listen and connect to TCP ports and unix socket paths. This will allow separate processes to be started and stopped any time and connect to each other.
12+
- [ ] Adding `-server` and `-rpcbind` options to the `bitcoin-wallet` executable so wallet processes can handle RPC requests directly without going through the node.
13+
- [ ] Supporting windows, not just unix systems. The existing socket code is already cross-platform, so the only windows-specific code that needs to be written is code spawning a process and passing a socket descriptor. This can be implemented with `CreateProcess` and `WSADuplicateSocket`. Example: https://memset.wordpress.com/2010/10/13/win32-api-passing-socket-with-ipc-method/.
14+
- [ ] Adding sandbox features, restricting subprocess access to resources and data. See [https://eklitzke.org/multiprocess-bitcoin](https://eklitzke.org/multiprocess-bitcoin).
15+
16+
## Debugging
17+
18+
After [#10102](https://github.com/bitcoin/bitcoin/pull/10102), the `-debug=ipc` command line option can be used to see requests and responses between processes.
19+
20+
## Installation
21+
22+
The multiprocess feature requires [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) as dependencies. A simple way to get starting using it without installing these dependencies manually is to use the [depends system](../depends) with the `MULTIPROCESS=1` [dependency option](../depends#dependency-options) passed to make:
23+
24+
```
25+
cd <BITCOIN_SOURCE_DIRECTORY>
26+
make -C depends NO_QT=1 MULTIPROCESS=1
27+
./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu
28+
make
29+
src/bitcoin-node -regtest -printtoconsole -debug=ipc
30+
BITCOIND=bitcoin-node test/functional/test_runner.py
31+
```
32+
33+
The configure script will pick up settings and library locations from the depends directory, so there is no need to pass `--enable-multiprocess` as a separate flag when using the depends system (it's controlled by the `MULTIPROCESS=1` option).
34+
35+
Alternately, you can install [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) packages on your system, and just run `./configure --enable-multiprocess` without using the depends system. The configure script will be able to locate the installed packages via [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/). See [Installation](https://github.com/chaincodelabs/libmultiprocess#installation) section of the libmultiprocess readme for install steps. See [build-unix.md](build-unix.md) and [build-osx.md](build-osx.md) for information about installing dependencies in general.

src/Makefile.am

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ if BUILD_BITCOIND
8585
bin_PROGRAMS += bitcoind
8686
endif
8787

88+
if BUILD_BITCOIN_NODE
89+
bin_PROGRAMS += bitcoin-node
90+
endif
91+
8892
if BUILD_BITCOIN_CLI
8993
bin_PROGRAMS += bitcoin-cli
9094
endif
@@ -547,22 +551,21 @@ libbitcoin_cli_a_SOURCES = \
547551
nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
548552
#
549553

550-
# bitcoind binary #
551-
bitcoind_SOURCES = bitcoind.cpp
552-
bitcoind_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
553-
bitcoind_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
554-
bitcoind_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
554+
# bitcoind & bitcoin-node binaries #
555+
bitcoin_daemon_sources = bitcoind.cpp
556+
bitcoin_bin_cppflags = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
557+
bitcoin_bin_cxxflags = $(AM_CXXFLAGS) $(PIE_FLAGS)
558+
bitcoin_bin_ldflags = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
555559

556560
if TARGET_WINDOWS
557-
bitcoind_SOURCES += bitcoind-res.rc
561+
bitcoin_daemon_sources += bitcoind-res.rc
558562
endif
559563

560-
bitcoind_LDADD = \
561-
$(LIBBITCOIN_SERVER) \
564+
bitcoin_bin_ldadd = \
562565
$(LIBBITCOIN_WALLET) \
563566
$(LIBBITCOIN_COMMON) \
564-
$(LIBUNIVALUE) \
565567
$(LIBBITCOIN_UTIL) \
568+
$(LIBUNIVALUE) \
566569
$(LIBBITCOIN_ZMQ) \
567570
$(LIBBITCOIN_CONSENSUS) \
568571
$(LIBBITCOIN_CRYPTO) \
@@ -571,7 +574,19 @@ bitcoind_LDADD = \
571574
$(LIBMEMENV) \
572575
$(LIBSECP256K1)
573576

574-
bitcoind_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS)
577+
bitcoin_bin_ldadd += $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS)
578+
579+
bitcoind_SOURCES = $(bitcoin_daemon_sources)
580+
bitcoind_CPPFLAGS = $(bitcoin_bin_cppflags)
581+
bitcoind_CXXFLAGS = $(bitcoin_bin_cxxflags)
582+
bitcoind_LDFLAGS = $(bitcoin_bin_ldflags)
583+
bitcoind_LDADD = $(LIBBITCOIN_SERVER) $(bitcoin_bin_ldadd)
584+
585+
bitcoin_node_SOURCES = $(bitcoin_daemon_sources)
586+
bitcoin_node_CPPFLAGS = $(bitcoin_bin_cppflags)
587+
bitcoin_node_CXXFLAGS = $(bitcoin_bin_cxxflags)
588+
bitcoin_node_LDFLAGS = $(bitcoin_bin_ldflags)
589+
bitcoin_node_LDADD = $(LIBBITCOIN_SERVER) $(bitcoin_bin_ldadd)
575590

576591
# bitcoin-cli binary #
577592
bitcoin_cli_SOURCES = bitcoin-cli.cpp
@@ -615,29 +630,14 @@ bitcoin_tx_LDADD += $(BOOST_LIBS)
615630

616631
# bitcoin-wallet binary #
617632
bitcoin_wallet_SOURCES = bitcoin-wallet.cpp
618-
bitcoin_wallet_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
619-
bitcoin_wallet_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
620-
bitcoin_wallet_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
633+
bitcoin_wallet_CPPFLAGS = $(bitcoin_bin_cppflags)
634+
bitcoin_wallet_CXXFLAGS = $(bitcoin_bin_cxxflags)
635+
bitcoin_wallet_LDFLAGS = $(bitcoin_bin_ldflags)
636+
bitcoin_wallet_LDADD = $(LIBBITCOIN_WALLET_TOOL) $(bitcoin_bin_ldadd)
621637

622638
if TARGET_WINDOWS
623639
bitcoin_wallet_SOURCES += bitcoin-wallet-res.rc
624640
endif
625-
626-
bitcoin_wallet_LDADD = \
627-
$(LIBBITCOIN_WALLET_TOOL) \
628-
$(LIBBITCOIN_WALLET) \
629-
$(LIBBITCOIN_COMMON) \
630-
$(LIBBITCOIN_CONSENSUS) \
631-
$(LIBBITCOIN_UTIL) \
632-
$(LIBBITCOIN_CRYPTO) \
633-
$(LIBBITCOIN_ZMQ) \
634-
$(LIBLEVELDB) \
635-
$(LIBLEVELDB_SSE42) \
636-
$(LIBMEMENV) \
637-
$(LIBSECP256K1) \
638-
$(LIBUNIVALUE)
639-
640-
bitcoin_wallet_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(MINIUPNPC_LIBS) $(ZMQ_LIBS)
641641
#
642642

643643
# bitcoinconsensus library #

src/Makefile.qt.include

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
bin_PROGRAMS += qt/bitcoin-qt
6+
7+
if BUILD_BITCOIN_GUI
8+
bin_PROGRAMS += bitcoin-gui
9+
endif
10+
611
EXTRA_LIBRARIES += qt/libbitcoinqt.a
712

813
# bitcoin qt core #
@@ -294,29 +299,43 @@ QT_FORMS_H=$(join $(dir $(QT_FORMS_UI)),$(addprefix ui_, $(notdir $(QT_FORMS_UI:
294299
# Most files will depend on the forms and moc files as includes. Generate them
295300
# before anything else.
296301
$(QT_MOC): $(QT_FORMS_H)
297-
$(qt_libbitcoinqt_a_OBJECTS) $(qt_bitcoin_qt_OBJECTS) : | $(QT_MOC)
302+
$(qt_libbitcoinqt_a_OBJECTS) $(qt_bitcoin_qt_OBJECTS) $(bitcoin_gui_OBJECTS) : | $(QT_MOC)
298303

299-
# bitcoin-qt binary #
300-
qt_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
304+
# bitcoin-qt and bitcoin-gui binaries #
305+
bitcoin_qt_cppflags = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
301306
$(QT_INCLUDES) $(QR_CFLAGS)
302-
qt_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
307+
bitcoin_qt_cxxflags = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
303308

304-
qt_bitcoin_qt_SOURCES = qt/main.cpp
309+
bitcoin_qt_sources = qt/main.cpp
305310
if TARGET_WINDOWS
306-
qt_bitcoin_qt_SOURCES += $(BITCOIN_RC)
311+
bitcoin_qt_sources += $(BITCOIN_RC)
307312
endif
308-
qt_bitcoin_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER)
313+
bitcoin_qt_ldadd = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER)
309314
if ENABLE_WALLET
310-
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_UTIL) $(LIBBITCOIN_WALLET)
315+
bitcoin_qt_ldadd += $(LIBBITCOIN_UTIL) $(LIBBITCOIN_WALLET)
311316
endif
312317
if ENABLE_ZMQ
313-
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
318+
bitcoin_qt_ldadd += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
314319
endif
315-
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
320+
bitcoin_qt_ldadd += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
316321
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
317322
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
318-
qt_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
319-
qt_bitcoin_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX
323+
bitcoin_qt_ldflags = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
324+
bitcoin_qt_libtoolflags = $(AM_LIBTOOLFLAGS) --tag CXX
325+
326+
qt_bitcoin_qt_CPPFLAGS = $(bitcoin_qt_cppflags)
327+
qt_bitcoin_qt_CXXFLAGS = $(bitcoin_qt_cxxflags)
328+
qt_bitcoin_qt_SOURCES = $(bitcoin_qt_sources)
329+
qt_bitcoin_qt_LDADD = $(bitcoin_qt_ldadd)
330+
qt_bitcoin_qt_LDFLAGS = $(bitcoin_qt_ldflags)
331+
qt_bitcoin_qt_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)
332+
333+
bitcoin_gui_CPPFLAGS = $(bitcoin_qt_cppflags)
334+
bitcoin_gui_CXXFLAGS = $(bitcoin_qt_cxxflags)
335+
bitcoin_gui_SOURCES = $(bitcoin_qt_sources)
336+
bitcoin_gui_LDADD = $(bitcoin_qt_ldadd)
337+
bitcoin_gui_LDFLAGS = $(bitcoin_qt_ldflags)
338+
bitcoin_gui_LIBTOOLFLAGS = $(bitcoin_qt_libtoolflags)
320339

321340
#locale/foo.ts -> locale/foo.qm
322341
QT_QM=$(QT_TS:.ts=.qm)

0 commit comments

Comments
 (0)