From fa01f38e53cfda4155d0ea09ca8b1291b7001fe8 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 28 Oct 2025 12:14:16 +0100 Subject: [PATCH] move-only: Move CBlockFileInfo to kernel namespace Also, move it to the blockstorage module, because it is only used inside that module. Can be reviewed with the git option --color-moved=dimmed-zebra --- src/chain.cpp | 6 ----- src/chain.h | 41 -------------------------------- src/node/blockstorage.cpp | 6 +++++ src/node/blockstorage.h | 42 +++++++++++++++++++++++++++++++++ src/test/blockmanager_tests.cpp | 1 + src/test/fuzz/block_index.cpp | 2 ++ src/test/fuzz/deserialize.cpp | 2 ++ 7 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 3dd22634110..94be71805f7 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -6,12 +6,6 @@ #include #include #include -#include - -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 2c86526520b..64c86357032 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 e1b54175dc2..20ace6668f5 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -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 cee0eb61ed6..e4d208c1c13 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 f06665d3055..679ba815645 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -17,6 +17,7 @@ #include #include +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 eef8c2efc80..5e7f789ca89 100644 --- a/src/test/fuzz/block_index.cpp +++ b/src/test/fuzz/block_index.cpp @@ -12,6 +12,8 @@ #include #include +using kernel::CBlockFileInfo; + namespace { const BasicTestingSetup* g_setup; diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index 05ca62b6fd0..97985ef0edb 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include +using kernel::CBlockFileInfo; using node::SnapshotMetadata; namespace {