ci, iwyu: Fix warnings in `src/primitives` 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/primitives and tells the automated 'Include What You Use' (IWYU) checker to treat those files as strictly checked. There is no change to program logic, no bug fix, and no security-relevant behavior.
No security action needed. This is a normal CI/code-hygiene change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds/removes standard-library and project header includes in src/primitives/block.cpp, block.h, transaction.cpp, transaction.h, and transaction_identifier.h to satisfy IWYU recommendations. It also updates ci/test/03_test_script.sh to include src/primitives/*.cpp in the set of files where IWYU warnings are treated as errors and to also check the corresponding headers. No functional code is modified.
Changed components
src/primitives/block.cppsrc/primitives/block.hsrc/primitives/transaction.cppsrc/primitives/transaction.hsrc/primitives/transaction_identifier.hci/test/03_test_script.shInspect captured patch +18 / −5
diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh
index 050d9e6a..7f605fb0 100755
--- a/ci/test/03_test_script.sh
+++ b/ci/test/03_test_script.sh
@@ -215,7 +215,7 @@ fi
if [[ "${RUN_IWYU}" == true ]]; then
# TODO: Consider enforcing IWYU across the entire codebase.
- FILES_WITH_ENFORCED_IWYU="/src/((crypto|index|kernel)/.*\\.cpp|node/blockstorage.cpp|node/utxo_snapshot.cpp|core_io.cpp|signet.cpp)"
+ FILES_WITH_ENFORCED_IWYU="/src/((crypto|index|kernel|primitives)/.*\\.cpp|node/blockstorage.cpp|node/utxo_snapshot.cpp|core_io.cpp|signet.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"
@@ -227,6 +227,7 @@ if [[ "${RUN_IWYU}" == true ]]; then
-p "${BASE_BUILD_DIR}" "${MAKEJOBS}" \
-- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \
-Xiwyu --max_line_length=160 \
+ -Xiwyu --check_also="*/primitives/*.h" \
2>&1 | tee /tmp/iwyu_ci.out
python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
git diff -U0 | ./contrib/devtools/clang-format-diff.py -binary="clang-format-${TIDY_LLVM_V}" -p1 -i -v
diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp
index c390de38..dfeed295 100644
--- a/src/primitives/block.cpp
+++ b/src/primitives/block.cpp
@@ -8,6 +8,10 @@
#include <hash.h>
#include <tinyformat.h>
+#include <memory>
+#include <span>
+#include <sstream>
+
uint256 CBlockHeader::GetHash() const
{
return (HashWriter{} << *this).GetHash();
diff --git a/src/primitives/block.h b/src/primitives/block.h
index 3c22c0f6..8ca4fb48 100644
--- a/src/primitives/block.h
+++ b/src/primitives/block.h
@@ -11,6 +11,11 @@
#include <uint256.h>
#include <util/time.h>
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp
index c8bbd9f8..5d7cd529 100644
--- a/src/primitives/transaction.cpp
+++ b/src/primitives/transaction.cpp
@@ -12,10 +12,10 @@
#include <script/script.h>
#include <serialize.h>
#include <tinyformat.h>
-#include <uint256.h>
#include <algorithm>
#include <cassert>
+#include <span>
#include <stdexcept>
std::string COutPoint::ToString() const
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 2ccdb4e4..54d0c919 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -11,8 +11,8 @@
#include <primitives/transaction_identifier.h> // IWYU pragma: export
#include <script/script.h>
#include <serialize.h>
-#include <uint256.h>
+#include <compare>
#include <cstddef>
#include <cstdint>
#include <ios>
diff --git a/src/primitives/transaction_identifier.h b/src/primitives/transaction_identifier.h
index 921f82c6..9b518d7d 100644
--- a/src/primitives/transaction_identifier.h
+++ b/src/primitives/transaction_identifier.h
@@ -9,9 +9,12 @@
#include <uint256.h>
#include <util/types.h>
-#include <compare>
-#include <concepts>
+#include <cstddef>
+#include <optional>
+#include <string>
+#include <string_view>
#include <tuple>
+#include <type_traits>
#include <variant>
/** transaction_identifier represents the two canonical transaction identifier
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.