Changeset View
Changeset View
Standalone View
Standalone View
src/chain.h
Show All 24 Lines | |||||
/** | /** | ||||
* Timestamp window used as a grace period by code that compares external | * Timestamp window used as a grace period by code that compares external | ||||
* timestamps (such as timestamps passed to RPCs, or wallet key creation times) | * timestamps (such as timestamps passed to RPCs, or wallet key creation times) | ||||
* to block timestamps. This should be set at least as high as | * to block timestamps. This should be set at least as high as | ||||
* MAX_FUTURE_BLOCK_TIME. | * MAX_FUTURE_BLOCK_TIME. | ||||
*/ | */ | ||||
static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; | static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; | ||||
/** | |||||
* This threshold is used to determine tie-breaks between competing blocks | |||||
* at the same height. A selfishly-mined block will likely have a larger | |||||
* header timestamp to received time difference. This threshold is the margin | |||||
* of error that a header may have to still be considered honest when compared | |||||
* to another block. | |||||
*/ | |||||
static const int64_t SELFISH_MINER_HEADER_RECEIVE_TIME_THRESHOLD = 10; | |||||
class CBlockFileInfo { | class CBlockFileInfo { | ||||
public: | public: | ||||
//!< number of blocks stored in file | //!< number of blocks stored in file | ||||
unsigned int nBlocks; | unsigned int nBlocks; | ||||
//!< number of used bytes of block file | //!< number of used bytes of block file | ||||
unsigned int nSize; | unsigned int nSize; | ||||
//!< number of used bytes in the undo file | //!< number of used bytes in the undo file | ||||
unsigned int nUndoSize; | unsigned int nUndoSize; | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | public: | ||||
//! block header | //! block header | ||||
int32_t nVersion; | int32_t nVersion; | ||||
uint256 hashMerkleRoot; | uint256 hashMerkleRoot; | ||||
uint32_t nTime; | uint32_t nTime; | ||||
uint32_t nBits; | uint32_t nBits; | ||||
uint32_t nNonce; | uint32_t nNonce; | ||||
//! (memory only) block header metadata | |||||
uint64_t nTimeReceived; | |||||
deadalnix: This should be in the CBlockIndex. | |||||
jasonbcoxAuthorUnsubmitted Done Inline Actionsjasonbcox: ;)
{F122943} | |||||
deadalnixUnsubmitted Done Inline Actionsalright, I'm crazy XD deadalnix: alright, I'm crazy XD | |||||
//! (memory only) Sequential id assigned to distinguish order in which | //! (memory only) Sequential id assigned to distinguish order in which | ||||
//! blocks are received. | //! blocks are received. | ||||
int32_t nSequenceId; | int32_t nSequenceId; | ||||
//! (memory only) Maximum nTime in the chain upto and including this block. | //! (memory only) Maximum nTime in the chain upto and including this block. | ||||
unsigned int nTimeMax; | unsigned int nTimeMax; | ||||
void SetNull() { | void SetNull() { | ||||
Show All 9 Lines | void SetNull() { | ||||
nChainTx = 0; | nChainTx = 0; | ||||
nStatus = 0; | nStatus = 0; | ||||
nSequenceId = 0; | nSequenceId = 0; | ||||
nTimeMax = 0; | nTimeMax = 0; | ||||
nVersion = 0; | nVersion = 0; | ||||
hashMerkleRoot = uint256(); | hashMerkleRoot = uint256(); | ||||
nTime = 0; | nTime = 0; | ||||
nTimeReceived = 0; | |||||
nBits = 0; | nBits = 0; | ||||
nNonce = 0; | nNonce = 0; | ||||
} | } | ||||
CBlockIndex() { SetNull(); } | CBlockIndex() { SetNull(); } | ||||
CBlockIndex(const CBlockHeader &block) { | CBlockIndex(const CBlockHeader &block) { | ||||
SetNull(); | SetNull(); | ||||
nVersion = block.nVersion; | nVersion = block.nVersion; | ||||
hashMerkleRoot = block.hashMerkleRoot; | hashMerkleRoot = block.hashMerkleRoot; | ||||
nTime = block.nTime; | nTime = block.nTime; | ||||
nTimeReceived = block.nTimeReceived; | |||||
nBits = block.nBits; | nBits = block.nBits; | ||||
nNonce = block.nNonce; | nNonce = block.nNonce; | ||||
} | } | ||||
CDiskBlockPos GetBlockPos() const { | CDiskBlockPos GetBlockPos() const { | ||||
CDiskBlockPos ret; | CDiskBlockPos ret; | ||||
if (nStatus & BLOCK_HAVE_DATA) { | if (nStatus & BLOCK_HAVE_DATA) { | ||||
ret.nFile = nFile; | ret.nFile = nFile; | ||||
Show All 14 Lines | public: | ||||
CBlockHeader GetBlockHeader() const { | CBlockHeader GetBlockHeader() const { | ||||
CBlockHeader block; | CBlockHeader block; | ||||
block.nVersion = nVersion; | block.nVersion = nVersion; | ||||
if (pprev) { | if (pprev) { | ||||
block.hashPrevBlock = pprev->GetBlockHash(); | block.hashPrevBlock = pprev->GetBlockHash(); | ||||
} | } | ||||
block.hashMerkleRoot = hashMerkleRoot; | block.hashMerkleRoot = hashMerkleRoot; | ||||
block.nTime = nTime; | block.nTime = nTime; | ||||
block.nTimeReceived = nTimeReceived; | |||||
block.nBits = nBits; | block.nBits = nBits; | ||||
block.nNonce = nNonce; | block.nNonce = nNonce; | ||||
return block; | return block; | ||||
} | } | ||||
uint256 GetBlockHash() const { return *phashBlock; } | uint256 GetBlockHash() const { return *phashBlock; } | ||||
int64_t GetBlockTime() const { return int64_t(nTime); } | int64_t GetBlockTime() const { return int64_t(nTime); } | ||||
int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); } | int64_t GetBlockTimeMax() const { return int64_t(nTimeMax); } | ||||
int64_t GetHeaderTimeReceived() const { | |||||
return nTimeReceived ? nTimeReceived : GetBlockTime(); | |||||
} | |||||
enum { nMedianTimeSpan = 11 }; | enum { nMedianTimeSpan = 11 }; | ||||
int64_t GetMedianTimePast() const { | int64_t GetMedianTimePast() const { | ||||
int64_t pmedian[nMedianTimeSpan]; | int64_t pmedian[nMedianTimeSpan]; | ||||
int64_t *pbegin = &pmedian[nMedianTimeSpan]; | int64_t *pbegin = &pmedian[nMedianTimeSpan]; | ||||
int64_t *pend = &pmedian[nMedianTimeSpan]; | int64_t *pend = &pmedian[nMedianTimeSpan]; | ||||
const CBlockIndex *pindex = this; | const CBlockIndex *pindex = this; | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |
This should be in the CBlockIndex.