diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -237,6 +237,9 @@ //! blocks are received. int32_t nSequenceId; + //! (memory only) block header metadata + uint64_t nTimeReceived; + //! (memory only) Maximum nTime in the chain upto and including this block. unsigned int nTimeMax; @@ -258,6 +261,7 @@ nVersion = 0; hashMerkleRoot = uint256(); nTime = 0; + nTimeReceived = 0; nBits = 0; nNonce = 0; } @@ -270,6 +274,11 @@ nVersion = block.nVersion; hashMerkleRoot = block.hashMerkleRoot; nTime = block.nTime; + // Default to block time if nTimeReceived is never set, which + // in effect assumes that this block is honestly mined. + // Note that nTimeReceived isn't written to disk, so blocks read from + // disk will be assumed to be honestly mined. + nTimeReceived = block.nTime; nBits = block.nBits; nNonce = block.nNonce; } @@ -311,6 +320,8 @@ int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); } + int64_t GetHeaderTimeReceived() const { return nTimeReceived; } + enum { nMedianTimeSpan = 11 }; int64_t GetMedianTimePast() const {