From d3a479cb077d9a9a4451dc4ecb43fe0daf94f172 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sun, 1 Jun 2025 19:39:12 +0200 Subject: [PATCH] kernel: Move BlockInfo to a kernel file This should avoid having to include interfaces/chain.h from a kernel module. interfaces/chain.h in turn includes a bunch of non-kernel headers, that break the desired library topology and might introduce entanglement regressions. --- ci/test/03_test_script.sh | 2 +- src/index/base.cpp | 1 - src/interfaces/chain.h | 17 +---------------- src/kernel/chain.cpp | 5 +++-- src/kernel/chain.h | 23 +++++++++++++++++++++-- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index 7f8fad71408..d29de80c3e4 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -209,7 +209,7 @@ if [ "${RUN_TIDY}" = "true" ]; then fi # TODO: Consider enforcing IWYU across the entire codebase. - FILES_WITH_ENFORCED_IWYU="/src/((crypto|index)/.*\\.cpp|node/blockstorage.cpp|node/utxo_snapshot.cpp|core_read.cpp|signet.cpp)" + FILES_WITH_ENFORCED_IWYU="/src/((crypto|index)/.*\\.cpp|node/blockstorage.cpp|node/utxo_snapshot.cpp|core_read.cpp|signet.cpp|kernel/chain.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" diff --git a/src/index/base.cpp b/src/index/base.cpp index 425f9f7eb18..7f77d13a574 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 686da67bfd2..e6847b9b161 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -7,6 +7,7 @@ #include #include +#include // IWYU pragma: export #include #include #include @@ -78,22 +79,6 @@ public: mutable bool found = false; }; -//! Block data sent with blockConnected, blockDisconnected notifications. -struct BlockInfo { - const uint256& hash; - const uint256* prev_hash = nullptr; - int height = -1; - int file_number = -1; - unsigned data_pos = 0; - const CBlock* data = nullptr; - const CBlockUndo* undo_data = nullptr; - // The maximum time in the chain up to and including this block. - // A timestamp that can only move forward. - unsigned int chain_time_max{0}; - - BlockInfo(const uint256& hash LIFETIMEBOUND) : hash(hash) {} -}; - //! The action to be taken after updating a settings value. //! WRITE indicates that the updated value must be written to disk, //! while SKIP_WRITE indicates that the change will be kept in memory-only diff --git a/src/kernel/chain.cpp b/src/kernel/chain.cpp index da515a05f36..0a33e9a1f71 100644 --- a/src/kernel/chain.cpp +++ b/src/kernel/chain.cpp @@ -2,9 +2,10 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include -#include #include + +#include +#include #include #include #include diff --git a/src/kernel/chain.h b/src/kernel/chain.h index 9675bb0f547..5afa51f4dda 100644 --- a/src/kernel/chain.h +++ b/src/kernel/chain.h @@ -5,12 +5,31 @@ #ifndef BITCOIN_KERNEL_CHAIN_H #define BITCOIN_KERNEL_CHAIN_H -#include +#include + +#include class CBlock; class CBlockIndex; +class CBlockUndo; +class uint256; + namespace interfaces { -struct BlockInfo; +//! Block data sent with blockConnected, blockDisconnected notifications. +struct BlockInfo { + const uint256& hash; + const uint256* prev_hash = nullptr; + int height = -1; + int file_number = -1; + unsigned data_pos = 0; + const CBlock* data = nullptr; + const CBlockUndo* undo_data = nullptr; + // The maximum time in the chain up to and including this block. + // A timestamp that can only move forward. + unsigned int chain_time_max{0}; + + BlockInfo(const uint256& hash LIFETIMEBOUND) : hash(hash) {} +}; } // namespace interfaces namespace kernel {