Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/voterecord.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | bool VoteRecord::registerVote(NodeId nodeid, uint32_t error) { | ||||
} | } | ||||
// The round changed our state. We reset the confidence. | // The round changed our state. We reset the confidence. | ||||
confidence = yes; | confidence = yes; | ||||
return true; | return true; | ||||
} | } | ||||
bool VoteRecord::addNodeToQuorum(NodeId nodeid) { | bool VoteRecord::addNodeToQuorum(NodeId nodeid) { | ||||
if (nodeid == NO_NODE) { | // Using NO_NODE is helpful for testing. | ||||
// Helpful for testing. | if (nodeid != NO_NODE) { | ||||
deadalnix: This doesn't seem like a good change. Don't count successful votes when no successful vote… | |||||
return true; | |||||
} | |||||
// MMIX Linear Congruent Generator. | // MMIX Linear Congruent Generator. | ||||
const uint64_t r1 = | const uint64_t r1 = | ||||
6364136223846793005 * uint64_t(nodeid) + 1442695040888963407; | 6364136223846793005 * uint64_t(nodeid) + 1442695040888963407; | ||||
// Fibonacci hashing. | // Fibonacci hashing. | ||||
const uint64_t r2 = 11400714819323198485ull * (nodeid ^ seed); | const uint64_t r2 = 11400714819323198485ull * (nodeid ^ seed); | ||||
// Combine and extract hash. | // Combine and extract hash. | ||||
const uint16_t h = (r1 + r2) >> 48; | const uint16_t h = (r1 + r2) >> 48; | ||||
/** | // Check if the node is in the filter. | ||||
* Check if the node is in the filter. | |||||
*/ | |||||
for (size_t i = 1; i < nodeFilter.size(); i++) { | for (size_t i = 1; i < nodeFilter.size(); i++) { | ||||
if (nodeFilter[(successfulVotes + i) % nodeFilter.size()] == h) { | if (nodeFilter[(successfulVotes + i) % nodeFilter.size()] == h) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
/** | // Add the node which just voted to the filter. | ||||
* Add the node which just voted to the filter. | |||||
*/ | |||||
nodeFilter[successfulVotes % nodeFilter.size()] = h; | nodeFilter[successfulVotes % nodeFilter.size()] = h; | ||||
} | |||||
successfulVotes++; | successfulVotes++; | ||||
return true; | return true; | ||||
} | } | ||||
bool VoteRecord::registerPoll() const { | bool VoteRecord::registerPoll() const { | ||||
uint8_t count = inflight.load(); | uint8_t count = inflight.load(); | ||||
while (count < AVALANCHE_MAX_INFLIGHT_POLL) { | while (count < AVALANCHE_MAX_INFLIGHT_POLL) { | ||||
if (inflight.compare_exchange_weak(count, count + 1)) { | if (inflight.compare_exchange_weak(count, count + 1)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |
This doesn't seem like a good change. Don't count successful votes when no successful vote occured.