Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(round); | READWRITE(round); | ||||
READWRITE(invs); | READWRITE(invs); | ||||
} | } | ||||
}; | }; | ||||
class AvalancheBlockUpdate { | class AvalancheBlockUpdate { | ||||
union { | union { | ||||
CBlockIndex *pindex; | CBlockIndex *pindex; | ||||
size_t raw; | uintptr_t raw; | ||||
}; | }; | ||||
static const size_t STATUS_BITS = 2; | |||||
static const uintptr_t MASK = (1 << STATUS_BITS) - 1; | |||||
static_assert( | |||||
alignof(CBlockIndex) >= (1 << STATUS_BITS), | |||||
"CBlockIndex alignement doesn't allow for Status to be stored."); | |||||
public: | public: | ||||
enum Status : uint8_t { | enum Status : uint8_t { | ||||
Invalid, | Invalid, | ||||
Rejected, | Rejected, | ||||
Accepted, | Accepted, | ||||
Finalized, | Finalized, | ||||
}; | }; | ||||
AvalancheBlockUpdate(CBlockIndex *pindexIn, Status statusIn) | AvalancheBlockUpdate(CBlockIndex *pindexIn, Status statusIn) | ||||
: pindex(pindexIn) { | : pindex(pindexIn) { | ||||
raw |= statusIn; | raw |= statusIn; | ||||
} | } | ||||
Status getStatus() const { return Status(raw & 0x03); } | Status getStatus() const { return Status(raw & MASK); } | ||||
CBlockIndex *getBlockIndex() { | CBlockIndex *getBlockIndex() { | ||||
return reinterpret_cast<CBlockIndex *>(raw & -size_t(0x04)); | return reinterpret_cast<CBlockIndex *>(raw & ~MASK); | ||||
} | } | ||||
const CBlockIndex *getBlockIndex() const { | const CBlockIndex *getBlockIndex() const { | ||||
return const_cast<AvalancheBlockUpdate *>(this)->getBlockIndex(); | return const_cast<AvalancheBlockUpdate *>(this)->getBlockIndex(); | ||||
} | } | ||||
}; | }; | ||||
typedef std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator> | typedef std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator> | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |