比特币源码阅读(leveldb-CBlockFileInfo)

CBlockFileInfo:包含存储block的文件的基本信息,具体的内容见下图

2018-08-07 16-10-53 的屏幕截图.png

src/chain.h

class CBlockFileInfo
{
public:
    unsigned int nBlocks;      //!< number of blocks stored in file 文件中存储的block个数
    unsigned int nSize;        //!< number of used bytes of block file 文件中block的size
    unsigned int nUndoSize;    //!< number of used bytes in the undo file //undofile中使用的byte
    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 文件中存储的区块的最晚时间

    ADD_SERIALIZE_METHODS;

    template 
    inline void SerializationOp(Stream& s, Operation ser_action) {
        READWRITE(VARINT(nBlocks));
        READWRITE(VARINT(nSize));
        READWRITE(VARINT(nUndoSize));
        READWRITE(VARINT(nHeightFirst));
        READWRITE(VARINT(nHeightLast));
        READWRITE(VARINT(nTimeFirst));
        READWRITE(VARINT(nTimeLast));
    }

     void SetNull() {
         nBlocks = 0;
         nSize = 0;
         nUndoSize = 0;
         nHeightFirst = 0;
         nHeightLast = 0;
         nTimeFirst = 0;
         nTimeLast = 0;
     }

     CBlockFileInfo() {
         SetNull();
     }

     std::string ToString() const;

     //为啥不更新nSize?
     /** 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;
     }
};

你可能感兴趣的:(比特币源码阅读(leveldb-CBlockFileInfo))