Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/voterecord.h
Show All 11 Lines | |||||
#include <cstdint> | #include <cstdint> | ||||
/** | /** | ||||
* Finalization score. | * Finalization score. | ||||
*/ | */ | ||||
static constexpr int AVALANCHE_FINALIZATION_SCORE = 128; | static constexpr int AVALANCHE_FINALIZATION_SCORE = 128; | ||||
/** | /** | ||||
* Number of votes before a record is flagged as stale. | |||||
*/ | |||||
static constexpr uint32_t AVALANCHE_VOTE_STALE_THRESHOLD = 1024; | |||||
/** | |||||
* How many inflight requests can exist for one item. | * How many inflight requests can exist for one item. | ||||
*/ | */ | ||||
static constexpr int AVALANCHE_MAX_INFLIGHT_POLL = 10; | static constexpr int AVALANCHE_MAX_INFLIGHT_POLL = 10; | ||||
namespace avalanche { | namespace avalanche { | ||||
/** | /** | ||||
* Vote history. | * Vote history. | ||||
Show All 37 Lines | public: | ||||
*/ | */ | ||||
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; | ||||
} | } | ||||
bool isStale() const { return isStaleVoteCount() && inflight == 0; } | |||||
Fabien: This is possible the condition will never happen under normal circumstances.
Also I don't… | |||||
sdulfariAuthorUnsubmitted Done Inline ActionsYou're right. I was confused about the request lifecycle. This inflight check is not necessary. sdulfari: You're right. I was confused about the request lifecycle. This inflight check is not necessary. | |||||
/** | /** | ||||
* 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(NodeId nodeid, uint32_t error); | bool registerVote(NodeId nodeid, uint32_t error); | ||||
/** | /** | ||||
* Register that a request is being made regarding that item. | * Register that a request is being made regarding that item. | ||||
* The method is made const so that it can be accessed via a read only view | * The method is made const so that it can be accessed via a read only view | ||||
* of blockVoteRecords. It's not a problem as it is made thread safe. | * of blockVoteRecords. It's not a problem as it is made thread safe. | ||||
*/ | */ | ||||
bool registerPoll() const; | bool registerPoll() const; | ||||
/** | /** | ||||
* Return if this item is in condition to be polled at the moment. | * Return if this item is in condition to be polled at the moment. | ||||
*/ | */ | ||||
bool shouldPoll() const { return inflight < AVALANCHE_MAX_INFLIGHT_POLL; } | bool shouldPoll() const { | ||||
return inflight < AVALANCHE_MAX_INFLIGHT_POLL && !isStaleVoteCount(); | |||||
} | |||||
/** | /** | ||||
* Clear `count` inflight requests. | * Clear `count` inflight requests. | ||||
*/ | */ | ||||
void clearInflightRequest(uint8_t count = 1) { inflight -= count; } | void clearInflightRequest(uint8_t count = 1) { inflight -= count; } | ||||
private: | private: | ||||
/** | /** | ||||
* Add the node to the quorum. | * Add the node to the quorum. | ||||
* Returns true if the node was added, false if the node already was in the | * Returns true if the node was added, false if the node already was in the | ||||
* quorum. | * quorum. | ||||
*/ | */ | ||||
bool addNodeToQuorum(NodeId nodeid); | bool addNodeToQuorum(NodeId nodeid); | ||||
bool isStaleVoteCount() const { | |||||
return successfulVotes > AVALANCHE_VOTE_STALE_THRESHOLD; | |||||
} | |||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_VOTERECORD_H | #endif // BITCOIN_AVALANCHE_VOTERECORD_H |
This is possible the condition will never happen under normal circumstances.
Also I don't understand why it is necessary: removing the vote records doesn't clear the queries