Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.h
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Vote history. | * Vote history. | ||||
*/ | */ | ||||
struct VoteRecord { | struct VoteRecord { | ||||
private: | private: | ||||
// Historical record of votes. | // Historical record of votes. | ||||
uint16_t votes; | uint8_t votes; | ||||
// Each bit indicate if the vote is to be considered. | |||||
uint8_t consider; | |||||
// confidence's LSB bit is the result. Higher bits are actual confidence | // confidence's LSB bit is the result. Higher bits are actual confidence | ||||
// score. | // score. | ||||
uint16_t confidence; | uint16_t confidence; | ||||
public: | public: | ||||
VoteRecord(bool accepted) : votes(0xaaaa), confidence(accepted) {} | VoteRecord(bool accepted) : votes(0), consider(0), confidence(accepted) {} | ||||
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 { | ||||
return getConfidence() >= AVALANCHE_FINALIZATION_SCORE; | return getConfidence() >= AVALANCHE_FINALIZATION_SCORE; | ||||
} | } | ||||
/** | /** | ||||
* Register a new vote for an item and update confidence accordingly. | * Register a new vote for an item and update confidence accordingly. | ||||
* Returns true if the acceptance or finalization state changed. | * Returns true if the acceptance or finalization state changed. | ||||
*/ | */ | ||||
bool registerVote(bool vote); | bool registerVote(uint32_t error); | ||||
}; | }; | ||||
class AvalancheVote { | class AvalancheVote { | ||||
uint32_t error; | uint32_t error; | ||||
uint256 hash; | uint256 hash; | ||||
public: | public: | ||||
AvalancheVote() : error(-1), hash() {} | AvalancheVote() : error(-1), hash() {} | ||||
AvalancheVote(uint32_t errorIn, uint256 hashIn) | AvalancheVote(uint32_t errorIn, uint256 hashIn) | ||||
: error(errorIn), hash(hashIn) {} | : error(errorIn), hash(hashIn) {} | ||||
const uint256 &GetHash() const { return hash; } | const uint256 &GetHash() const { return hash; } | ||||
bool IsValid() const { return error == 0; } | uint32_t GetError() const { return error; } | ||||
// serialization support | // serialization support | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(error); | READWRITE(error); | ||||
READWRITE(hash); | READWRITE(hash); | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | public: | ||||
~AvalancheProcessor() { stopEventLoop(); } | ~AvalancheProcessor() { stopEventLoop(); } | ||||
void setQueryTimeoutDuration(std::chrono::milliseconds d) { | void setQueryTimeoutDuration(std::chrono::milliseconds d) { | ||||
queryTimeoutDuration = d; | queryTimeoutDuration = d; | ||||
} | } | ||||
bool addBlockToReconcile(const CBlockIndex *pindex); | bool addBlockToReconcile(const CBlockIndex *pindex); | ||||
bool isAccepted(const CBlockIndex *pindex) const; | bool isAccepted(const CBlockIndex *pindex) const; | ||||
int getConfidence(const CBlockIndex *pindex) const; | |||||
bool registerVotes(NodeId nodeid, const AvalancheResponse &response, | bool registerVotes(NodeId nodeid, const AvalancheResponse &response, | ||||
std::vector<AvalancheBlockUpdate> &updates); | std::vector<AvalancheBlockUpdate> &updates); | ||||
bool addPeer(NodeId nodeid, uint32_t score); | bool addPeer(NodeId nodeid, uint32_t score); | ||||
bool startEventLoop(CScheduler &scheduler); | bool startEventLoop(CScheduler &scheduler); | ||||
bool stopEventLoop(); | bool stopEventLoop(); | ||||
Show All 10 Lines |