Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.h
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
namespace avalanche { | namespace avalanche { | ||||
class Delegation; | class Delegation; | ||||
class PeerManager; | class PeerManager; | ||||
class Proof; | class Proof; | ||||
struct VoteRecord; | struct VoteRecord; | ||||
enum struct VoteStatus : uint8_t { | |||||
Invalid, | |||||
Rejected, | |||||
Accepted, | |||||
Finalized, | |||||
}; | |||||
class BlockUpdate { | class BlockUpdate { | ||||
union { | union { | ||||
CBlockIndex *pindex; | CBlockIndex *pindex; | ||||
uintptr_t raw; | uintptr_t raw; | ||||
}; | }; | ||||
static const size_t STATUS_BITS = 2; | static const size_t STATUS_BITS = 2; | ||||
static const uintptr_t MASK = (1 << STATUS_BITS) - 1; | static const uintptr_t MASK = (1 << STATUS_BITS) - 1; | ||||
static_assert( | static_assert( | ||||
alignof(CBlockIndex) >= (1 << STATUS_BITS), | alignof(CBlockIndex) >= (1 << STATUS_BITS), | ||||
"CBlockIndex alignement doesn't allow for Status to be stored."); | "CBlockIndex alignement doesn't allow for Status to be stored."); | ||||
public: | public: | ||||
enum Status : uint8_t { | BlockUpdate(CBlockIndex *pindexIn, VoteStatus statusIn) : pindex(pindexIn) { | ||||
Invalid, | raw |= static_cast<uint8_t>(statusIn); | ||||
Rejected, | |||||
Accepted, | |||||
Finalized, | |||||
}; | |||||
BlockUpdate(CBlockIndex *pindexIn, Status statusIn) : pindex(pindexIn) { | |||||
raw |= statusIn; | |||||
} | } | ||||
Status getStatus() const { return Status(raw & MASK); } | VoteStatus getStatus() const { return VoteStatus(raw & MASK); } | ||||
CBlockIndex *getBlockIndex() { | CBlockIndex *getBlockIndex() { | ||||
return reinterpret_cast<CBlockIndex *>(raw & ~MASK); | return reinterpret_cast<CBlockIndex *>(raw & ~MASK); | ||||
} | } | ||||
const CBlockIndex *getBlockIndex() const { | const CBlockIndex *getBlockIndex() const { | ||||
return const_cast<BlockUpdate *>(this)->getBlockIndex(); | return const_cast<BlockUpdate *>(this)->getBlockIndex(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |