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> &finalized) { | ||||
return vr->hasFinalized(); | |||||
} | |||||
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 &r = w[v.GetHash()]; | ||||
r.registerVote(v.IsValid()); | |||||
if (r.hasFinalized()) { | |||||
finalized.push_back(v.GetHash()); | |||||
} | |||||
} | |||||
for (auto &h : finalized) { | |||||
w->erase(h); | |||||
} | } | ||||
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 |