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 successfulVotes > AVALANCHE_VOTE_STALE_THRESHOLD; | |||||
Fabien: That's not guaranteed thread safe (despite the increment from addNoteToQuorum) is probably an… | |||||
deadalnixUnsubmitted Not Done Inline ActionsNothing in this class is thead safe, so idk why it is a poblem. However, this method clearly doesn't make sense. The number of successful vote increasing clearly doesn't indicate staleness. If you exclude the possibility of inconclusive votes, this would in fact be indicating the opposite of stale. deadalnix: Nothing in this class is thead safe, so idk why it is a poblem.
However, this method clearly… | |||||
deadalnixUnsubmitted Not Done Inline ActionsSo, what indicates progress is the confidence level. There fore, what indicate staleness would be a confidence score too low for the number of successful vote registered - which would indicate endless flip flopping or very large number of inconclusive rounds. deadalnix: So, what indicates progress is the confidence level. There fore, what indicate staleness would… | |||||
} | |||||
/** | /** | ||||
* 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 && !isStale(); | |||||
FabienUnsubmitted Not Done Inline ActionsThis is mixing the concerns. Why should you not poll if the vote is stale ? Fabien: This is mixing the concerns. Why should you not poll if the vote is stale ? | |||||
} | |||||
/** | /** | ||||
* 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: | ||||
/** | /** | ||||
Show All 10 Lines |
That's not guaranteed thread safe (despite the increment from addNoteToQuorum) is probably an atomic operation)