Changeset View
Changeset View
Standalone View
Standalone View
src/chain.h
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | enum BlockStatus : uint32_t { | ||||
BLOCK_FAILED_VALID = 32, | BLOCK_FAILED_VALID = 32, | ||||
//!< descends from failed block | //!< descends from failed block | ||||
BLOCK_FAILED_CHILD = 64, | BLOCK_FAILED_CHILD = 64, | ||||
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, | BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, | ||||
//!< excessive block | //!< excessive block | ||||
BLOCK_EXCESSIVE = 128, | BLOCK_EXCESSIVE = 128, | ||||
//!< excessive block or have data | |||||
BLOCK_EXCESSIVE_OR_STORED_DATA = BLOCK_EXCESSIVE | BLOCK_HAVE_DATA, | |||||
//!< mask for all the errors | //!< mask for all the errors | ||||
BLOCK_NOT_VALID_MASK = BLOCK_EXCESSIVE | BLOCK_FAILED_MASK | BLOCK_NOT_VALID_MASK = BLOCK_EXCESSIVE | BLOCK_FAILED_MASK | ||||
}; | }; | ||||
/** | /** | ||||
* The block chain is a tree shaped structure starting with the genesis block at | * The block chain is a tree shaped structure starting with the genesis block at | ||||
* the root, with each block potentially having multiple candidates to be the | * the root, with each block potentially having multiple candidates to be the | ||||
* next block. A blockindex may have multiple pprev pointing to it, but at most | * next block. A blockindex may have multiple pprev pointing to it, but at most | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | CBlockIndex(const CBlockHeader &block) { | ||||
hashMerkleRoot = block.hashMerkleRoot; | hashMerkleRoot = block.hashMerkleRoot; | ||||
nTime = block.nTime; | nTime = block.nTime; | ||||
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_EXCESSIVE_OR_STORED_DATA) { | ||||
ret.nFile = nFile; | ret.nFile = nFile; | ||||
ret.nPos = nDataPos; | ret.nPos = nDataPos; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
CDiskBlockPos GetUndoPos() const { | CDiskBlockPos GetUndoPos() const { | ||||
CDiskBlockPos ret; | CDiskBlockPos ret; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public: | ||||
//! level. | //! level. | ||||
bool IsValid(enum BlockStatus nUpTo = BLOCK_VALID_TRANSACTIONS) const { | bool IsValid(enum BlockStatus nUpTo = BLOCK_VALID_TRANSACTIONS) const { | ||||
// Only validity flags allowed. | // Only validity flags allowed. | ||||
assert(!(nUpTo & ~BLOCK_VALID_MASK)); | assert(!(nUpTo & ~BLOCK_VALID_MASK)); | ||||
if (nStatus & BLOCK_FAILED_MASK) return false; | if (nStatus & BLOCK_FAILED_MASK) return false; | ||||
return ((nStatus & BLOCK_VALID_MASK) >= nUpTo); | return ((nStatus & BLOCK_VALID_MASK) >= nUpTo); | ||||
} | } | ||||
//! Check whether this block index entry is excessive | |||||
bool IsExcessive() const { | |||||
if (nStatus & BLOCK_EXCESSIVE) return false; | |||||
return true; | |||||
deadalnix: The same logic can be done via:
return !(nStatus & BLOCK_EXCESSIVE)
But that seems backward… | |||||
} | |||||
//! Raise the validity level of this block index entry. | //! Raise the validity level of this block index entry. | ||||
//! Returns true if the validity was changed. | //! Returns true if the validity was changed. | ||||
bool RaiseValidity(enum BlockStatus nUpTo) { | bool RaiseValidity(enum BlockStatus nUpTo) { | ||||
// Only validity flags allowed. | // Only validity flags allowed. | ||||
assert(!(nUpTo & ~BLOCK_VALID_MASK)); | assert(!(nUpTo & ~BLOCK_VALID_MASK)); | ||||
if (nStatus & BLOCK_FAILED_MASK) return false; | if (nStatus & BLOCK_FAILED_MASK) return false; | ||||
if ((nStatus & BLOCK_VALID_MASK) < nUpTo) { | if ((nStatus & BLOCK_VALID_MASK) < nUpTo) { | ||||
nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo; | nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo; | ||||
Show All 35 Lines | public: | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
int nVersion = s.GetVersion(); | int nVersion = s.GetVersion(); | ||||
if (!(s.GetType() & SER_GETHASH)) READWRITE(VARINT(nVersion)); | if (!(s.GetType() & SER_GETHASH)) READWRITE(VARINT(nVersion)); | ||||
READWRITE(VARINT(nHeight)); | READWRITE(VARINT(nHeight)); | ||||
READWRITE(VARINT(nStatus)); | READWRITE(VARINT(nStatus)); | ||||
READWRITE(VARINT(nTx)); | READWRITE(VARINT(nTx)); | ||||
if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) | if ((nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) || | ||||
nStatus & BLOCK_EXCESSIVE) | |||||
READWRITE(VARINT(nFile)); | READWRITE(VARINT(nFile)); | ||||
if (nStatus & BLOCK_HAVE_DATA) READWRITE(VARINT(nDataPos)); | if (nStatus & BLOCK_EXCESSIVE_OR_STORED_DATA) | ||||
READWRITE(VARINT(nDataPos)); | |||||
if (nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(nUndoPos)); | if (nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(nUndoPos)); | ||||
// block header | // block header | ||||
READWRITE(this->nVersion); | READWRITE(this->nVersion); | ||||
READWRITE(hashPrev); | READWRITE(hashPrev); | ||||
READWRITE(hashMerkleRoot); | READWRITE(hashMerkleRoot); | ||||
READWRITE(nTime); | READWRITE(nTime); | ||||
READWRITE(nBits); | READWRITE(nBits); | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |
The same logic can be done via:
But that seems backward to me. If the excessive flag is set, then should that indicate that tej block is excessive rather than it isn't ?