move-only: Move CBlockFileInfo to kernel namespace
What changed, and why it matters
This commit is a pure code reorganization: it moves the CBlockFileInfo class from one header file (chain.h) to another (node/blockstorage.h) and places it under the kernel namespace. No behavior, logic, or security properties of the code change. It is not a security fix and does not introduce a vulnerability.
No security action needed. Treat as ordinary refactoring during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a move-only refactor of CBlockFileInfo into the kernel namespace and the blockstorage module. The class definition, serialization code, ToString() implementation, and AddBlock() method are relocated verbatim. Test and fuzz files are updated only to add using declarations. There are no functional modifications.
Changed components
src/chain.hsrc/chain.cppsrc/node/blockstorage.hsrc/node/blockstorage.cppsrc/test/blockmanager_tests.cppsrc/test/fuzz/block_index.cppsrc/test/fuzz/deserialize.cppInspect captured patch +53 / −47
diff --git a/src/chain.cpp b/src/chain.cpp
index 3dd22634..94be7180 100644
--- a/src/chain.cpp
+++ b/src/chain.cpp
@@ -6,12 +6,6 @@
#include <chain.h>
#include <tinyformat.h>
#include <util/check.h>
-#include <util/time.h>
-
-std::string CBlockFileInfo::ToString() const
-{
- return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
-}
std::string CBlockIndex::ToString() const
{
diff --git a/src/chain.h b/src/chain.h
index 2c865265..64c86357 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -47,47 +47,6 @@ static constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1;
*/
static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60;
-class CBlockFileInfo
-{
-public:
- unsigned int nBlocks{}; //!< number of blocks stored in file
- unsigned int nSize{}; //!< number of used bytes of block file
- unsigned int nUndoSize{}; //!< number of used bytes in the undo file
- unsigned int nHeightFirst{}; //!< lowest height of block in file
- unsigned int nHeightLast{}; //!< highest height of block in file
- uint64_t nTimeFirst{}; //!< earliest time of block in file
- uint64_t nTimeLast{}; //!< latest time of block in file
-
- SERIALIZE_METHODS(CBlockFileInfo, obj)
- {
- READWRITE(VARINT(obj.nBlocks));
- READWRITE(VARINT(obj.nSize));
- READWRITE(VARINT(obj.nUndoSize));
- READWRITE(VARINT(obj.nHeightFirst));
- READWRITE(VARINT(obj.nHeightLast));
- READWRITE(VARINT(obj.nTimeFirst));
- READWRITE(VARINT(obj.nTimeLast));
- }
-
- CBlockFileInfo() = default;
-
- std::string ToString() const;
-
- /** update statistics (does not update nSize) */
- void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
- {
- if (nBlocks == 0 || nHeightFirst > nHeightIn)
- nHeightFirst = nHeightIn;
- if (nBlocks == 0 || nTimeFirst > nTimeIn)
- nTimeFirst = nTimeIn;
- nBlocks++;
- if (nHeightIn > nHeightLast)
- nHeightLast = nHeightIn;
- if (nTimeIn > nTimeLast)
- nTimeLast = nTimeIn;
- }
-};
-
enum BlockStatus : uint32_t {
//! Unused.
BLOCK_VALID_UNKNOWN = 0,
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index e1b54175..20ace666 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -35,6 +35,7 @@
#include <util/signalinterrupt.h>
#include <util/strencodings.h>
#include <util/syserror.h>
+#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
@@ -151,6 +152,11 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s
return true;
}
+
+std::string CBlockFileInfo::ToString() const
+{
+ return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
+}
} // namespace kernel
namespace node {
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index cee0eb61..e4d208c1 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -47,6 +47,47 @@ class SignalInterrupt;
} // namespace util
namespace kernel {
+class CBlockFileInfo
+{
+public:
+ unsigned int nBlocks{}; //!< number of blocks stored in file
+ unsigned int nSize{}; //!< number of used bytes of block file
+ unsigned int nUndoSize{}; //!< number of used bytes in the undo file
+ unsigned int nHeightFirst{}; //!< lowest height of block in file
+ unsigned int nHeightLast{}; //!< highest height of block in file
+ uint64_t nTimeFirst{}; //!< earliest time of block in file
+ uint64_t nTimeLast{}; //!< latest time of block in file
+
+ SERIALIZE_METHODS(CBlockFileInfo, obj)
+ {
+ READWRITE(VARINT(obj.nBlocks));
+ READWRITE(VARINT(obj.nSize));
+ READWRITE(VARINT(obj.nUndoSize));
+ READWRITE(VARINT(obj.nHeightFirst));
+ READWRITE(VARINT(obj.nHeightLast));
+ READWRITE(VARINT(obj.nTimeFirst));
+ READWRITE(VARINT(obj.nTimeLast));
+ }
+
+ CBlockFileInfo() = default;
+
+ std::string ToString() const;
+
+ /** update statistics (does not update nSize) */
+ void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
+ {
+ if (nBlocks == 0 || nHeightFirst > nHeightIn)
+ nHeightFirst = nHeightIn;
+ if (nBlocks == 0 || nTimeFirst > nTimeIn)
+ nTimeFirst = nTimeIn;
+ nBlocks++;
+ if (nHeightIn > nHeightLast)
+ nHeightLast = nHeightIn;
+ if (nTimeIn > nTimeLast)
+ nTimeLast = nTimeIn;
+ }
+};
+
/** Access to the block database (blocks/index/) */
class BlockTreeDB : public CDBWrapper
{
@@ -65,6 +106,7 @@ public:
} // namespace kernel
namespace node {
+using kernel::CBlockFileInfo;
using kernel::BlockTreeDB;
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp
index f06665d3..679ba815 100644
--- a/src/test/blockmanager_tests.cpp
+++ b/src/test/blockmanager_tests.cpp
@@ -17,6 +17,7 @@
#include <test/util/logging.h>
#include <test/util/setup_common.h>
+using kernel::CBlockFileInfo;
using node::STORAGE_HEADER_BYTES;
using node::BlockManager;
using node::KernelNotifications;
diff --git a/src/test/fuzz/block_index.cpp b/src/test/fuzz/block_index.cpp
index eef8c2ef..5e7f789c 100644
--- a/src/test/fuzz/block_index.cpp
+++ b/src/test/fuzz/block_index.cpp
@@ -12,6 +12,8 @@
#include <txdb.h>
#include <validation.h>
+using kernel::CBlockFileInfo;
+
namespace {
const BasicTestingSetup* g_setup;
diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp
index 05ca62b6..97985ef0 100644
--- a/src/test/fuzz/deserialize.cpp
+++ b/src/test/fuzz/deserialize.cpp
@@ -17,6 +17,7 @@
#include <net.h>
#include <netbase.h>
#include <netgroup.h>
+#include <node/blockstorage.h>
#include <node/utxo_snapshot.h>
#include <primitives/block.h>
#include <protocol.h>
@@ -34,6 +35,7 @@
#include <optional>
#include <stdexcept>
+using kernel::CBlockFileInfo;
using node::SnapshotMetadata;
namespace {
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.