From 5a69d9457b1d351d64d3c8a12378bffbffb1a7ee Mon Sep 17 00:00:00 2001 From: josibake Date: Thu, 11 Jun 2026 06:05:40 +0100 Subject: [PATCH 1/3] ipc: replace libmultiprocess runtime with native capnp --- CMakeLists.txt | 8 +- ci/test/03_test_script.sh | 8 + src/CMakeLists.txt | 4 - src/bench/block_assemble.cpp | 2 +- src/bitcoin.cpp | 34 +- src/init.cpp | 16 +- src/interfaces/ipc.h | 14 - src/interfaces/mining.h | 97 +- src/ipc/CMakeLists.txt | 49 +- src/ipc/capnp/common-types.h | 106 +- src/ipc/capnp/common.capnp | 5 +- src/ipc/capnp/echo-types.h | 12 - src/ipc/capnp/echo.capnp | 9 +- src/ipc/capnp/init-types.h | 11 - src/ipc/capnp/init.capnp | 15 +- src/ipc/capnp/mining-types.h | 20 - src/ipc/capnp/mining.capnp | 99 +- src/ipc/capnp/mining.cpp | 11 - src/ipc/capnp/protocol.cpp | 1530 +++++++++++++++++++++++++-- src/ipc/interfaces.cpp | 45 +- src/ipc/process.cpp | 94 +- src/ipc/protocol.h | 5 - src/ipc/test/CMakeLists.txt | 4 +- src/ipc/test/ipc_test.capnp | 23 - src/ipc/test/ipc_test.cpp | 465 ++++++-- src/ipc/test/ipc_test.h | 18 +- src/ipc/test/ipc_test_types.h | 12 - src/ipc/test/ipc_tests.cpp | 4 +- src/node/interfaces.cpp | 448 ++++++-- src/node/miner.cpp | 117 +- src/node/miner.h | 19 +- src/test/fuzz/package_eval.cpp | 4 +- src/test/fuzz/tx_pool.cpp | 4 +- src/test/miner_tests.cpp | 409 ++++--- src/test/peerman_tests.cpp | 3 +- src/test/testnet4_miner_tests.cpp | 9 +- src/test/util/mining.cpp | 87 +- src/test/util/mining.h | 43 +- src/test/util/setup_common.cpp | 3 +- src/test/validation_block_tests.cpp | 6 +- 40 files changed, 2858 insertions(+), 1014 deletions(-) delete mode 100644 src/ipc/capnp/echo-types.h delete mode 100644 src/ipc/capnp/init-types.h delete mode 100644 src/ipc/capnp/mining-types.h delete mode 100644 src/ipc/capnp/mining.cpp delete mode 100644 src/ipc/test/ipc_test.capnp delete mode 100644 src/ipc/test/ipc_test_types.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a56a4db40547..ba7dd35f1989 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,13 +121,7 @@ if(WITH_USDT) find_package(USDT MODULE REQUIRED) endif() -option(WITH_EXTERNAL_LIBMULTIPROCESS "Build with external libmultiprocess library instead of with local git subtree. This is not normally recommended, but can be useful for developing libmultiprocess itself." OFF) -if(WITH_EXTERNAL_LIBMULTIPROCESS) - find_package(Libmultiprocess REQUIRED COMPONENTS Lib) - find_package(LibmultiprocessNative REQUIRED COMPONENTS Bin - NAMES Libmultiprocess - ) -endif() +find_package(CapnProto REQUIRED) option(BUILD_BENCH "Build bench_bitcoin executable." OFF) option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF) diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index 837e661a9cc9..3774674a049e 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -196,6 +196,14 @@ if [ "${RUN_TIDY}" = "true" ]; then fi if [[ "${RUN_IWYU}" == true ]]; then + mkdir -p "${BASE_BUILD_DIR}/src/node/data" + cmake -DRAW_SOURCE_PATH="${BASE_ROOT_DIR}/src/node/data/ip_asn.dat" \ + -DHEADER_PATH="${BASE_BUILD_DIR}/src/node/data/ip_asn.dat.h" \ + -DRAW_NAMESPACE=node::data \ + -P "${BASE_ROOT_DIR}/cmake/script/GenerateHeaderFromRaw.cmake" + # shellcheck disable=SC2086 + cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target bitcoin_ipc + # TODO: Consider enforcing IWYU across the entire codebase. FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|script|univalue/(lib|test)|util)/.*|bench/(block_assemble|connectblock)|common/license_info|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|rpc/mining|clientversion|core_io|signet|init)\\.cpp)" jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5feb9959341..c1bdab596d77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,10 +19,6 @@ include(../cmake/crc32c.cmake) include(../cmake/leveldb.cmake) include(../cmake/minisketch.cmake) add_subdirectory(univalue) -if (NOT WITH_EXTERNAL_LIBMULTIPROCESS) - include(../cmake/libmultiprocess.cmake) - add_libmultiprocess(ipc/libmultiprocess) -endif() include(../cmake/secp256k1.cmake) add_secp256k1(secp256k1) diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 191357fa6621..13113833345e 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -26,7 +26,7 @@ using node::BlockCreateOptions; static void AssembleBlock(benchmark::Bench& bench) { - const auto test_setup = MakeNoLogFileContext(); + auto test_setup = MakeNoLogFileContext(); CScriptWitness witness; witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE); diff --git a/src/bitcoin.cpp b/src/bitcoin.cpp index 4b36a03a1406..4da4f35dd748 100644 --- a/src/bitcoin.cpp +++ b/src/bitcoin.cpp @@ -8,14 +8,14 @@ #include #include #include -#include +#include #include +#include #include #include #include #include -#include #include const TranslateFn G_TRANSLATION_FUN{nullptr}; @@ -23,7 +23,7 @@ const TranslateFn G_TRANSLATION_FUN{nullptr}; static constexpr auto HELP_USAGE = R"(Usage: %s [OPTIONS] COMMAND... Options: - -m, --multiprocess Run multiprocess binary bitcoin-node. + -m, --ipc-server Run IPC server binary bitcoin-node. -M, --monolithic Run monolithic binary bitcoind. (Default behavior) -v, --version Show version information -h, --help Show full help message @@ -47,7 +47,7 @@ Run '%s help' to see additional commands (e.g. for testing and debugging). )"; struct CommandLine { - std::optional use_multiprocess; + std::optional use_ipc_server; bool show_version{false}; bool show_help{false}; std::string_view command; @@ -118,10 +118,10 @@ CommandLine ParseCommandLine(int argc, char* argv[]) std::string_view arg = argv[i]; if (!cmd.command.empty()) { cmd.args.emplace_back(argv[i]); - } else if (arg == "-m" || arg == "--multiprocess") { - cmd.use_multiprocess = true; + } else if (arg == "-m" || arg == "--ipc-server") { + cmd.use_ipc_server = true; } else if (arg == "-M" || arg == "--monolithic") { - cmd.use_multiprocess = false; + cmd.use_ipc_server = false; } else if (arg == "-v" || arg == "--version") { cmd.show_version = true; } else if (arg == "-h" || arg == "--help" || arg == "help") { @@ -139,7 +139,7 @@ bool UseMultiprocess(const CommandLine& cmd) { // If -m or -M options were explicitly specified, there is no need to // further parse arguments to determine which to use. - if (cmd.use_multiprocess) return *cmd.use_multiprocess; + if (cmd.use_ipc_server) return *cmd.use_ipc_server; ArgsManager args; args.SetDefaultFlags(ArgsManager::ALLOW_ANY); @@ -154,8 +154,8 @@ bool UseMultiprocess(const CommandLine& cmd) } args.SelectConfigNetwork(args.GetChainTypeString()); - // If any -ipc* options are set these need to be processed by a - // multiprocess-capable binary. + // If any -ipc* options are set these need to be processed by the + // IPC-capable server binary. return args.IsArgSet("-ipcbind") || args.IsArgSet("-ipcconnect") || args.IsArgSet("-ipcfd"); } @@ -187,7 +187,7 @@ static void ExecCommand(const std::vector& args, std::string_view w auto try_exec = [&](fs::path exe_path, bool allow_notfound = true) { std::string exe_path_str{fs::PathToString(exe_path)}; exec_args[0] = exe_path_str.c_str(); - if (util::ExecVp(exec_args[0], (char*const*)exec_args.data()) == -1) { + if (util::ExecVp(exec_args[0], (char* const*)exec_args.data()) == -1) { if (allow_notfound && errno == ENOENT) return false; throw std::system_error(errno, std::system_category(), strprintf("execvp failed to execute '%s'", exec_args[0])); } @@ -217,11 +217,11 @@ static void ExecCommand(const std::vector& args, std::string_view w // in libexec/ (wrapper_dir.filename() == "bin" && try_exec(wrapper_dir.parent_path() / "libexec" / arg0.filename())) || #ifdef WIN32 - // Otherwise check the "daemon" subdirectory in a windows install. - (!wrapper_dir.empty() && try_exec(wrapper_dir / "daemon" / arg0.filename())) || + // Otherwise check the "daemon" subdirectory in a windows install. + (!wrapper_dir.empty() && try_exec(wrapper_dir / "daemon" / arg0.filename())) || #endif - // Otherwise look for target executable next to current wrapper - (!wrapper_dir.empty() && try_exec(wrapper_dir / arg0.filename(), fallback_os_search)) || - // Otherwise just look on the system path. - (fallback_os_search && try_exec(arg0.filename(), false)); + // Otherwise look for target executable next to current wrapper + (!wrapper_dir.empty() && try_exec(wrapper_dir / arg0.filename(), fallback_os_search)) || + // Otherwise just look on the system path. + (fallback_os_search && try_exec(arg0.filename(), false)); } diff --git a/src/init.cpp b/src/init.cpp index 19cbc46c53ef..67dbd06d0d77 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -7,8 +7,6 @@ #include -#include - #include #include #include @@ -16,24 +14,25 @@ #include #include #include +#include #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include #include #include -#include #include #include #include +#include #include #include #include @@ -66,6 +65,7 @@ #include #include #include +#include #include #include