Merge bitcoin/bitcoin#36107: iwyu: Fix warnings in `src/init` and treat them as errors
What changed, and why it matters
This commit is a routine code-quality cleanup. It adjusts which C++ header files are included in several source files under src/init and tells the project's automated 'Include What You Use' (IWYU) checker to treat any remaining warnings in those files as errors. There is no change to how Bitcoin Core behaves, processes data, or handles the network, so it has no security impact on users.
No security action needed. Treat as normal build/CI hygiene.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit enforces IWYU (include-what-you-use) hygiene for src/init/.cpp. Changes are limited to adding/removing/reordering #include directives, adding IWYU pragma comments (associated, begin_keep/end_keep, keep), and updating the CI regex in ci/test/03_test_script.sh so that src/init/. is covered by the enforced-as-error set. One functional-looking change in src/init/common.cpp replaces
Changed components
src/init/basic.cppsrc/init/bitcoin-gui.cppsrc/init/bitcoin-node.cppsrc/init/bitcoin-qt.cppsrc/init/bitcoin-wallet.cppsrc/init/bitcoind.cppsrc/init/common.cppsrc/interfaces/init.hsrc/interfaces/ipc.hci/test/03_test_script.shInspect captured patch +26 / −8
### ci/test/03_test_script.sh
@@ -234,7 +234,7 @@ fi
if [[ "${RUN_IWYU}" == true ]]; then
# TODO: Consider enforcing IWYU across the entire codebase.
- FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|kernel|primitives|script|univalue/(lib|test)|util|zmq)/.*|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|rpc/mining|clientversion|core_io|signet|init)\.cpp'
+ FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|script|univalue/(lib|test)|util|zmq)/.*|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"
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"
### src/init/basic.cpp
@@ -2,9 +2,12 @@
// 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 <interfaces/init.h> // IWYU pragma: associated
+
#include <interfaces/ipc.h>
+#include <memory>
+
namespace init {
namespace {
class BitcoinBasicInit : public interfaces::Init
### src/init/bitcoin-gui.cpp
@@ -2,10 +2,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <interfaces/init.h> // IWYU pragma: associated
+
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
-#include <interfaces/init.h>
#include <interfaces/ipc.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
### src/init/bitcoin-node.cpp
@@ -2,11 +2,13 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <interfaces/init.h> // IWYU pragma: associated
+
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
-#include <interfaces/init.h>
#include <interfaces/ipc.h>
+#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/rpc.h>
#include <interfaces/wallet.h>
### src/init/bitcoin-qt.cpp
@@ -2,10 +2,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <interfaces/init.h> // IWYU pragma: associated
+
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
-#include <interfaces/init.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
### src/init/bitcoin-wallet.cpp
@@ -2,7 +2,7 @@
// 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 <interfaces/init.h> // IWYU pragma: associated
#include <memory>
### src/init/bitcoind.cpp
@@ -2,10 +2,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <interfaces/init.h> // IWYU pragma: associated
+
#include <init.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
-#include <interfaces/init.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
### src/init/common.cpp
@@ -4,6 +4,8 @@
#include <bitcoin-build-config.h> // IWYU pragma: keep
+#include <init/common.h>
+
#include <clientversion.h>
#include <common/args.h>
#include <logging.h>
@@ -17,7 +19,7 @@
#include <util/translation.h>
#include <algorithm>
-#include <filesystem>
+#include <ranges>
#include <string>
#include <vector>
### src/interfaces/init.h
@@ -5,14 +5,21 @@
#ifndef BITCOIN_INTERFACES_INIT_H
#define BITCOIN_INTERFACES_INIT_H
+// This header is associated with several source files, and IWYU
+// reaches different conclusions across them about whether these
+// headers should be included or their classes forward-declared.
+// Keep the includes so the result is the same for every file.
+// IWYU pragma: begin_keep
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <interfaces/rpc.h>
#include <interfaces/wallet.h>
+// IWYU pragma: end_keep
#include <memory>
+#include <stdexcept>
namespace node {
struct NodeContext;
### src/interfaces/ipc.h
@@ -9,6 +9,7 @@
#include <memory>
#include <string>
#include <typeindex>
+#include <utility>
namespace ipc {
struct Context;Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.