kernel: Move BlockInfo to a kernel file
What changed, and why it matters
This is a routine code reorganization change. It moves a data structure called BlockInfo from one internal header file to another so that lower-level 'kernel' modules do not need to include a higher-level interface header. There is no user-facing behavior change and no security fix.
No security action needed. Treat as normal refactoring/merge if code review passes.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the interfaces::BlockInfo struct out of src/interfaces/chain.h and into src/kernel/chain.h. It updates includes accordingly: src/kernel/chain.cpp now includes <kernel/chain.h> first and drops <interfaces/chain.h>, while src/interfaces/chain.h includes <kernel/chain.h> and removes the struct definition. src/index/base.cpp drops its <kernel/chain.h> include because it still includes <interfaces/chain.h>, which re-exports the type. CI’s IWYU enforcement list is expanded to include kernel/chain.cpp. The change is purely architectural, aimed at preserving the kernel/non-kernel library layering.
Changed components
src/interfaces/chain.hsrc/kernel/chain.hsrc/kernel/chain.cppsrc/index/base.cppci/test/03_test_script.shInspect captured patch +26 / −22
diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh
index 7f8fad71..d29de80c 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 425f9f7e..7f77d13a 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -9,7 +9,6 @@
#include <dbwrapper.h>
#include <interfaces/chain.h>
#include <interfaces/types.h>
-#include <kernel/chain.h>
#include <kernel/types.h>
#include <logging.h>
#include <node/abort.h>
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index 686da67b..e6847b9b 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -7,6 +7,7 @@
#include <blockfilter.h>
#include <common/settings.h>
+#include <kernel/chain.h> // IWYU pragma: export
#include <node/types.h>
#include <primitives/transaction.h>
#include <util/result.h>
@@ -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 da515a05..0a33e9a1 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 <chain.h>
-#include <interfaces/chain.h>
#include <kernel/chain.h>
+
+#include <chain.h>
+#include <kernel/cs_main.h>
#include <kernel/types.h>
#include <sync.h>
#include <uint256.h>
diff --git a/src/kernel/chain.h b/src/kernel/chain.h
index 9675bb0f..5afa51f4 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<iostream>
+#include <attributes.h>
+
+#include <iostream>
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 {
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.