77
88#include < kernel/cs_main.h>
99#include < serialize.h>
10- #include < streams.h>
1110#include < sync.h>
1211#include < util/fs.h>
1312
@@ -30,8 +29,6 @@ class SignalInterrupt;
3029
3130namespace kernel {
3231
33- class CBlockFileInfo ;
34-
3532// Checksums are calculated from the serialized value and its position in the
3633// file. This protects against out of order data and allows the same checksum
3734// from the log file record to be used for the actual data files.
@@ -81,6 +78,50 @@ class BlockTreeStoreError : public std::runtime_error
8178 explicit BlockTreeStoreError (const std::string& msg) : std::runtime_error(msg) {}
8279};
8380
81+ class CBlockFileInfo
82+ {
83+ public:
84+ uint32_t nBlocks{}; // !< number of blocks stored in file
85+ uint32_t nSize{}; // !< number of used bytes of block file
86+ uint32_t nUndoSize{}; // !< number of used bytes in the undo file
87+ uint32_t nHeightFirst{}; // !< lowest height of block in file
88+ uint32_t nHeightLast{}; // !< highest height of block in file
89+ uint64_t nTimeFirst{}; // !< earliest time of block in file
90+ uint64_t nTimeLast{}; // !< latest time of block in file
91+
92+ // Note: The SERIALIZE_METHODS here use VARINT encoding for compatibility with
93+ // the legacy leveldb block tree db, used during migration in CreateAndMigrateBlockTree.
94+ // BlockFileInfoWrapper uses fixed-width encoding for the new flat file storage.
95+ SERIALIZE_METHODS (CBlockFileInfo, obj)
96+ {
97+ READWRITE (VARINT (obj.nBlocks ));
98+ READWRITE (VARINT (obj.nSize ));
99+ READWRITE (VARINT (obj.nUndoSize ));
100+ READWRITE (VARINT (obj.nHeightFirst ));
101+ READWRITE (VARINT (obj.nHeightLast ));
102+ READWRITE (VARINT (obj.nTimeFirst ));
103+ READWRITE (VARINT (obj.nTimeLast ));
104+ }
105+
106+ CBlockFileInfo () = default ;
107+
108+ std::string ToString () const ;
109+
110+ /* * update statistics (does not update nSize) */
111+ void AddBlock (unsigned int nHeightIn, uint64_t nTimeIn)
112+ {
113+ if (nBlocks == 0 || nHeightFirst > nHeightIn)
114+ nHeightFirst = nHeightIn;
115+ if (nBlocks == 0 || nTimeFirst > nTimeIn)
116+ nTimeFirst = nTimeIn;
117+ nBlocks++;
118+ if (nHeightIn > nHeightLast)
119+ nHeightLast = nHeightIn;
120+ if (nTimeIn > nTimeLast)
121+ nTimeLast = nTimeIn;
122+ }
123+ };
124+
84125class BlockTreeStore
85126{
86127public:
0 commit comments