Changeset View
Changeset View
Standalone View
Standalone View
src/chain.h
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | enum BlockStatusEnum : uint32_t { | ||||
// Undo data available in rev*.dat | // Undo data available in rev*.dat | ||||
BLOCK_HAVE_UNDO = 16, | BLOCK_HAVE_UNDO = 16, | ||||
BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO, | BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO, | ||||
// The block is invalid. | // The block is invalid. | ||||
BLOCK_FAILED_VALID = 32, | BLOCK_FAILED_VALID = 32, | ||||
// The block has an invalid parent. | // The block has an invalid parent. | ||||
BLOCK_FAILED_CHILD = 64, | BLOCK_FAILED_CHILD = 64, | ||||
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, | BLOCK_INVALID_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, | ||||
}; | }; | ||||
struct BlockStatus { | struct BlockStatus { | ||||
private: | private: | ||||
uint32_t status; | uint32_t status; | ||||
explicit BlockStatus(uint32_t nStatusIn) : status(nStatusIn) {} | explicit BlockStatus(uint32_t nStatusIn) : status(nStatusIn) {} | ||||
Show All 15 Lines | public: | ||||
} | } | ||||
bool hasUndo() const { return status & BLOCK_HAVE_UNDO; } | bool hasUndo() const { return status & BLOCK_HAVE_UNDO; } | ||||
BlockStatus withUndo(bool hasUndo = true) const { | BlockStatus withUndo(bool hasUndo = true) const { | ||||
return BlockStatus((status & ~BLOCK_HAVE_UNDO) | | return BlockStatus((status & ~BLOCK_HAVE_UNDO) | | ||||
(hasUndo ? BLOCK_HAVE_UNDO : BLOCK_HAVE_NOTHING)); | (hasUndo ? BLOCK_HAVE_UNDO : BLOCK_HAVE_NOTHING)); | ||||
} | } | ||||
bool hasFailed() const { return status & BLOCK_FAILED_VALID; } | |||||
BlockStatus withFailed(bool hasFailed = true) const { | |||||
return BlockStatus( | |||||
(status & ~BLOCK_FAILED_VALID) | | |||||
(hasFailed ? BLOCK_FAILED_VALID : BLOCK_HAVE_NOTHING)); | |||||
} | |||||
bool hasFailedParent() const { return status & BLOCK_FAILED_CHILD; } | |||||
BlockStatus withFailedParent(bool hasFailedParent = true) const { | |||||
return BlockStatus( | |||||
(status & ~BLOCK_FAILED_CHILD) | | |||||
(hasFailedParent ? BLOCK_FAILED_CHILD : BLOCK_HAVE_NOTHING)); | |||||
} | |||||
/** | /** | ||||
* Check whether this block index entry is valid up to the passed validity | * Check whether this block index entry is valid up to the passed validity | ||||
* level. | * level. | ||||
*/ | */ | ||||
bool isValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const { | bool isValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const { | ||||
if (status & BLOCK_FAILED_MASK) { | if (isInvalid()) { | ||||
return false; | return false; | ||||
} | } | ||||
return getValidity() >= nUpTo; | return getValidity() >= nUpTo; | ||||
} | } | ||||
bool isInvalid() const { return status & BLOCK_INVALID_MASK; } | |||||
BlockStatus withClearedFailureFlags() const { | |||||
return withFailed(false).withFailedParent(false); | |||||
} | |||||
// To transition from this and the plain old intereger. | // To transition from this and the plain old intereger. | ||||
// TODO: delete. | // TODO: delete. | ||||
uint32_t operator&(uint32_t rhs) const { return status & rhs; } | uint32_t operator&(uint32_t rhs) const { return status & rhs; } | ||||
BlockStatus &operator&=(uint32_t rhs) { | BlockStatus &operator&=(uint32_t rhs) { | ||||
this->status &= rhs; | this->status &= rhs; | ||||
return *this; | return *this; | ||||
} | } | ||||
BlockStatus &operator|=(uint32_t rhs) { | BlockStatus &operator|=(uint32_t rhs) { | ||||
this->status |= rhs; | this->status |= rhs; | ||||
return *this; | return *this; | ||||
} | } | ||||
operator bool() const { return status != 0; } | operator bool() const { return status != 0; } | ||||
operator uint32_t() const { return status; } | operator uint32_t() const { return status; } | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | public: | ||||
bool IsValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const { | bool IsValid(enum BlockValidity nUpTo = BlockValidity::TRANSACTIONS) const { | ||||
return nStatus.isValid(nUpTo); | return nStatus.isValid(nUpTo); | ||||
} | } | ||||
//! 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 BlockValidity nUpTo) { | bool RaiseValidity(enum BlockValidity nUpTo) { | ||||
// Only validity flags allowed. | // Only validity flags allowed. | ||||
if (nStatus & BLOCK_FAILED_MASK) { | if (nStatus.isInvalid()) { | ||||
return false; | return false; | ||||
} | } | ||||
if (BlockValidity(nStatus & BLOCK_VALID_MASK) >= nUpTo) { | if (nStatus.getValidity() >= nUpTo) { | ||||
return false; | return false; | ||||
} | } | ||||
nStatus = nStatus.withValidity(nUpTo); | nStatus = nStatus.withValidity(nUpTo); | ||||
return true; | return true; | ||||
} | } | ||||
//! Build the skiplist pointer for this entry. | //! Build the skiplist pointer for this entry. | ||||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |