refactor: Fix includes in `index` directory
What changed, and why it matters
This commit is a routine code cleanup that adjusts which header files are included in the `index` directory of Bitcoin Core. It does not change program behavior, fix a bug, or address a security issue. It simply makes the include lists more precise so the code compiles cleanly with include-what-you-use tooling.
No security action needed. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors #include directives across src/index/base.{h,cpp}, src/index/blockfilterindex.{h,cpp}, src/index/coinstatsindex.{h,cpp}, and src/index/txindex.{h,cpp}. It removes unused includes, adds forward declarations where possible, and adds directly used headers. It also updates contrib/devtools/iwyu/bitcoin.core.imp with three cstdio symbol mappings for SEEK_CUR, SEEK_END, and SEEK_SET. There are no functional code changes, no bug fixes, and no security-relevant modifications.
Changed components
src/index/base.cppsrc/index/base.hsrc/index/blockfilterindex.cppsrc/index/blockfilterindex.hsrc/index/coinstatsindex.cppsrc/index/coinstatsindex.hsrc/index/txindex.cppsrc/index/txindex.hcontrib/devtools/iwyu/bitcoin.core.impInspect captured patch +138 / −23
diff --git a/contrib/devtools/iwyu/bitcoin.core.imp b/contrib/devtools/iwyu/bitcoin.core.imp
index 789abcda..c3195e51 100644
--- a/contrib/devtools/iwyu/bitcoin.core.imp
+++ b/contrib/devtools/iwyu/bitcoin.core.imp
@@ -8,4 +8,9 @@
# libc symbols.
{ "symbol": ["AT_HWCAP", "private", "<sys/auxv.h>", "public"] },
{ "symbol": ["AT_HWCAP2", "private", "<sys/auxv.h>", "public"] },
+
+ # Fixed in https://github.com/include-what-you-use/include-what-you-use/pull/1706.
+ { "symbol": ["SEEK_CUR", "private", "<cstdio>", "public"] },
+ { "symbol": ["SEEK_END", "private", "<cstdio>", "public"] },
+ { "symbol": ["SEEK_SET", "private", "<cstdio>", "public"] },
]
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 82259ac0..b547a13c 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -2,10 +2,13 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <chainparams.h>
-#include <common/args.h>
#include <index/base.h>
+
+#include <chain.h>
+#include <common/args.h>
+#include <dbwrapper.h>
#include <interfaces/chain.h>
+#include <interfaces/types.h>
#include <kernel/chain.h>
#include <logging.h>
#include <node/abort.h>
@@ -13,20 +16,31 @@
#include <node/context.h>
#include <node/database_args.h>
#include <node/interface_ui.h>
+#include <primitives/block.h>
+#include <sync.h>
#include <tinyformat.h>
+#include <uint256.h>
#include <undo.h>
+#include <util/fs.h>
#include <util/string.h>
#include <util/thread.h>
+#include <util/threadinterrupt.h>
+#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
+#include <validationinterface.h>
-#include <chrono>
+#include <cassert>
+#include <compare>
+#include <cstdint>
#include <memory>
#include <optional>
+#include <span>
#include <stdexcept>
#include <string>
#include <thread>
#include <utility>
+#include <vector>
constexpr uint8_t DB_BEST_BLOCK{'B'};
diff --git a/src/index/base.h b/src/index/base.h
index 4131b06c..5a6f0a40 100644
--- a/src/index/base.h
+++ b/src/index/base.h
@@ -5,29 +5,41 @@
#ifndef BITCOIN_INDEX_BASE_H
#define BITCOIN_INDEX_BASE_H
+#include <attributes.h>
#include <dbwrapper.h>
#include <interfaces/chain.h>
-#include <interfaces/types.h>
-#include <util/string.h>
+#include <kernel/cs_main.h>
+#include <threadsafety.h>
+#include <uint256.h>
+#include <util/fs.h>
#include <util/threadinterrupt.h>
#include <validationinterface.h>
+#include <atomic>
+#include <cstddef>
+#include <memory>
+#include <optional>
#include <string>
+#include <thread>
class CBlock;
class CBlockIndex;
class Chainstate;
-class ChainstateManager;
-namespace interfaces {
-class Chain;
-} // namespace interfaces
+struct CBlockLocator;
struct IndexSummary {
std::string name;
bool synced{false};
int best_block_height{0};
uint256 best_block_hash;
};
+namespace interfaces {
+struct BlockRef;
+}
+namespace util {
+template <unsigned int num_params>
+struct ConstevalFormatString;
+}
/**
* Base class for indices of blockchain data. This implements
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index 2ccae3a2..e47e47c1 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -2,19 +2,39 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <map>
+#include <index/blockfilterindex.h>
-#include <clientversion.h>
+#include <blockfilter.h>
+#include <chain.h>
#include <common/args.h>
#include <dbwrapper.h>
+#include <flatfile.h>
#include <hash.h>
-#include <index/blockfilterindex.h>
+#include <index/base.h>
+#include <interfaces/chain.h>
+#include <interfaces/types.h>
#include <logging.h>
-#include <node/blockstorage.h>
-#include <undo.h>
-#include <util/fs_helpers.h>
+#include <serialize.h>
+#include <streams.h>
+#include <sync.h>
+#include <uint256.h>
+#include <util/check.h>
+#include <util/fs.h>
+#include <util/hasher.h>
#include <util/syserror.h>
+#include <cerrno>
+#include <exception>
+#include <ios>
+#include <map>
+#include <optional>
+#include <span>
+#include <stdexcept>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
/* The index database stores three items for each block: the disk location of the encoded filter,
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
* height, and those belonging to blocks that have been reorganized out of the active chain are
diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h
index 983cf322..b1ebd55f 100644
--- a/src/index/blockfilterindex.h
+++ b/src/index/blockfilterindex.h
@@ -6,13 +6,24 @@
#define BITCOIN_INDEX_BLOCKFILTERINDEX_H
#include <attributes.h>
-#include <blockfilter.h>
-#include <chain.h>
#include <flatfile.h>
#include <index/base.h>
+#include <interfaces/chain.h>
+#include <sync.h>
+#include <uint256.h>
#include <util/hasher.h>
+#include <cstddef>
+#include <cstdint>
+#include <functional>
+#include <memory>
+#include <optional>
#include <unordered_map>
+#include <vector>
+
+class BlockFilter;
+class CBlockIndex;
+enum class BlockFilterType : uint8_t;
static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp
index af798e29..f247a1d0 100644
--- a/src/index/coinstatsindex.cpp
+++ b/src/index/coinstatsindex.cpp
@@ -2,20 +2,39 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <index/coinstatsindex.h>
+
#include <arith_uint256.h>
+#include <chain.h>
#include <chainparams.h>
#include <coins.h>
#include <common/args.h>
+#include <consensus/amount.h>
#include <crypto/muhash.h>
-#include <index/coinstatsindex.h>
+#include <dbwrapper.h>
+#include <index/base.h>
+#include <interfaces/chain.h>
+#include <interfaces/types.h>
#include <kernel/coinstats.h>
#include <logging.h>
-#include <node/blockstorage.h>
+#include <primitives/block.h>
+#include <primitives/transaction.h>
+#include <script/script.h>
#include <serialize.h>
-#include <txdb.h>
+#include <uint256.h>
#include <undo.h>
+#include <util/check.h>
+#include <util/fs.h>
#include <validation.h>
+#include <compare>
+#include <ios>
+#include <limits>
+#include <span>
+#include <string>
+#include <utility>
+#include <vector>
+
using kernel::ApplyCoinHash;
using kernel::CCoinsStats;
using kernel::GetBogoSize;
diff --git a/src/index/coinstatsindex.h b/src/index/coinstatsindex.h
index 7e48f4c4..ce953146 100644
--- a/src/index/coinstatsindex.h
+++ b/src/index/coinstatsindex.h
@@ -6,11 +6,18 @@
#define BITCOIN_INDEX_COINSTATSINDEX_H
#include <arith_uint256.h>
+#include <consensus/amount.h>
#include <crypto/muhash.h>
#include <index/base.h>
+#include <interfaces/chain.h>
+#include <uint256.h>
+
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <optional>
class CBlockIndex;
-class CDBBatch;
namespace kernel {
struct CCoinsStats;
}
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
index 11dd856e..63aa484c 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -4,14 +4,32 @@
#include <index/txindex.h>
-#include <clientversion.h>
#include <common/args.h>
+#include <dbwrapper.h>
+#include <flatfile.h>
+#include <index/base.h>
#include <index/disktxpos.h>
+#include <interfaces/chain.h>
#include <logging.h>
#include <node/blockstorage.h>
-#include <primitives/transaction_identifier.h>
+#include <primitives/block.h>
+#include <primitives/transaction.h>
+#include <serialize.h>
+#include <streams.h>
+#include <uint256.h>
+#include <util/fs.h>
#include <validation.h>
+#include <cassert>
+#include <cstdint>
+#include <cstdio>
+#include <exception>
+#include <iterator>
+#include <span>
+#include <string>
+#include <utility>
+#include <vector>
+
constexpr uint8_t DB_TXINDEX{'t'};
std::unique_ptr<TxIndex> g_txindex;
diff --git a/src/index/txindex.h b/src/index/txindex.h
index f8236c92..889b6612 100644
--- a/src/index/txindex.h
+++ b/src/index/txindex.h
@@ -6,6 +6,15 @@
#define BITCOIN_INDEX_TXINDEX_H
#include <index/base.h>
+#include <primitives/transaction.h>
+
+#include <cstddef>
+#include <memory>
+
+class uint256;
+namespace interfaces {
+class Chain;
+}
static constexpr bool DEFAULT_TXINDEX{false};
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.