Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show All 28 Lines | |||||
bool AvalancheProcessor::isAccepted(const CBlockIndex *pindex) const { | bool AvalancheProcessor::isAccepted(const CBlockIndex *pindex) const { | ||||
if (auto vr = GetRecord(vote_records, pindex)) { | if (auto vr = GetRecord(vote_records, pindex)) { | ||||
return vr->isValid(); | return vr->isValid(); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool AvalancheProcessor::hasFinalized(const CBlockIndex *pindex) const { | bool AvalancheProcessor::registerVotes(const AvalancheResponse &response, | ||||
if (auto vr = GetRecord(vote_records, pindex)) { | std::vector<uint256> &accepted, | ||||
return vr->hasFinalized(); | std::vector<uint256> &rejected) { | ||||
} | |||||
return false; | |||||
} | |||||
bool AvalancheProcessor::registerVotes(const AvalancheResponse &response) { | |||||
const std::vector<AvalancheVote> &votes = response.GetVotes(); | const std::vector<AvalancheVote> &votes = response.GetVotes(); | ||||
// Register votes. | // Register votes. | ||||
auto w = vote_records.getWriteView(); | auto w = vote_records.getWriteView(); | ||||
for (auto &v : votes) { | for (auto &v : votes) { | ||||
w[v.GetHash()].registerVote(v.IsValid()); | auto it = w->find(v.GetHash()); | ||||
if (it == w.end()) { | |||||
// We are not voting on that item anymore. | |||||
continue; | |||||
} | |||||
auto &vr = it->second; | |||||
vr.registerVote(v.IsValid()); | |||||
if (!vr.hasFinalized()) { | |||||
// This item has note been finalized, so we have nothing more to do. | |||||
continue; | |||||
} | |||||
// We just finalized a vote. If it is valid, then let the caller know. | |||||
// Either way, remove the item from the map. | |||||
if (vr.isValid()) { | |||||
accepted.push_back(v.GetHash()); | |||||
} else { | |||||
rejected.push_back(v.GetHash()); | |||||
} | |||||
w->erase(it); | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
namespace { | namespace { | ||||
/** | /** | ||||
* Run the avalanche event loop every 20ms. | * Run the avalanche event loop every 20ms. | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |