Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.h
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
enum struct VoteStatus : uint8_t { | enum struct VoteStatus : uint8_t { | ||||
Invalid, | Invalid, | ||||
Rejected, | Rejected, | ||||
Accepted, | Accepted, | ||||
Finalized, | Finalized, | ||||
}; | }; | ||||
class BlockUpdate { | template <typename VoteItem> class VoteItemUpdate { | ||||
union { | VoteItem item; | ||||
CBlockIndex *pindex; | VoteStatus status; | ||||
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: | ||||
BlockUpdate(CBlockIndex *pindexIn, VoteStatus statusIn) : pindex(pindexIn) { | VoteItemUpdate(const VoteItem itemIn, VoteStatus statusIn) | ||||
raw |= static_cast<uint8_t>(statusIn); | : item(itemIn), status(statusIn) {} | ||||
} | |||||
VoteStatus getStatus() const { return VoteStatus(raw & MASK); } | const VoteStatus &getStatus() const { return status; } | ||||
CBlockIndex *getBlockIndex() { | VoteItem getVoteItem() { return item; } | ||||
return reinterpret_cast<CBlockIndex *>(raw & ~MASK); | const VoteItem getVoteItem() const { return item; } | ||||
} | |||||
const CBlockIndex *getBlockIndex() const { | |||||
return const_cast<BlockUpdate *>(this)->getBlockIndex(); | |||||
} | |||||
}; | }; | ||||
using BlockUpdate = VoteItemUpdate<CBlockIndex *>; | |||||
using BlockVoteMap = | using BlockVoteMap = | ||||
std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator>; | std::map<const CBlockIndex *, VoteRecord, CBlockIndexWorkComparator>; | ||||
using ProofVoteMap = std::map<const std::shared_ptr<Proof>, VoteRecord, | using ProofVoteMap = std::map<const std::shared_ptr<Proof>, VoteRecord, | ||||
ProofSharedPointerComparator>; | ProofSharedPointerComparator>; | ||||
struct query_timeout {}; | struct query_timeout {}; | ||||
namespace { | namespace { | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |