Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
static const NodeId NO_NODE = -1; | static const NodeId NO_NODE = -1; | ||||
} | } | ||||
/** | /** | ||||
* Vote history. | * Vote history. | ||||
*/ | */ | ||||
struct VoteRecord { | struct VoteRecord { | ||||
private: | private: | ||||
// confidence's LSB bit is the result. Higher bits are actual confidence | |||||
// score. | |||||
uint16_t confidence = 0; | |||||
// Historical record of votes. | // Historical record of votes. | ||||
uint8_t votes = 0; | uint8_t votes = 0; | ||||
// Each bit indicate if the vote is to be considered. | // Each bit indicate if the vote is to be considered. | ||||
uint8_t consider = 0; | uint8_t consider = 0; | ||||
// How many in flight requests exists for this element. | // How many in flight requests exists for this element. | ||||
mutable std::atomic<uint8_t> inflight{0}; | mutable std::atomic<uint8_t> inflight{0}; | ||||
// confidence's LSB bit is the result. Higher bits are actual confidence | // Track how many successful votes occured. | ||||
// score. | uint32_t successfulVotes = 0; | ||||
uint16_t confidence = 0; | |||||
public: | public: | ||||
VoteRecord(bool accepted) : confidence(accepted) {} | VoteRecord(bool accepted) : confidence(accepted) {} | ||||
/** | /** | ||||
* Copy semantic | * Copy semantic | ||||
*/ | */ | ||||
VoteRecord(const VoteRecord &other) | VoteRecord(const VoteRecord &other) | ||||
: votes(other.votes), consider(other.consider), | : confidence(other.confidence), votes(other.votes), | ||||
inflight(other.inflight.load()), confidence(other.confidence) {} | consider(other.consider), inflight(other.inflight.load()), | ||||
successfulVotes(other.successfulVotes) {} | |||||
/** | /** | ||||
* Vote accounting facilities. | * Vote accounting facilities. | ||||
*/ | */ | ||||
bool isAccepted() const { return confidence & 0x01; } | bool isAccepted() const { return confidence & 0x01; } | ||||
uint16_t getConfidence() const { return confidence >> 1; } | uint16_t getConfidence() const { return confidence >> 1; } | ||||
bool hasFinalized() const { | bool hasFinalized() const { | ||||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |