Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | auto registerVoteItems = [&](auto voteRecordsWriteView, auto &updates, | ||||
auto it = voteRecordsWriteView->find(item); | auto it = voteRecordsWriteView->find(item); | ||||
if (it == voteRecordsWriteView.end()) { | if (it == voteRecordsWriteView.end()) { | ||||
// We are not voting on that item anymore. | // We are not voting on that item anymore. | ||||
continue; | continue; | ||||
} | } | ||||
auto &vr = it->second; | auto &vr = it->second; | ||||
if (!vr.registerVote(nodeid, v.GetError())) { | if (!vr.registerVote(nodeid, v.GetError())) { | ||||
if (vr.isStale()) { | |||||
// Just drop stale votes. If we see this item again, we'll | |||||
// do a new vote. | |||||
updates.emplace_back(item, VoteStatus::Stale); | |||||
voteRecordsWriteView->erase(it); | |||||
} | |||||
// This vote did not provide any extra information, move on. | // This vote did not provide any extra information, move on. | ||||
continue; | continue; | ||||
} | } | ||||
if (!vr.hasFinalized()) { | if (!vr.hasFinalized()) { | ||||
// This item has note been finalized, so we have nothing more to | // This item has note been finalized, so we have nothing more to | ||||
// do. | // do. | ||||
updates.emplace_back(item, vr.isAccepted() | updates.emplace_back(item, vr.isAccepted() | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | auto extractVoteRecordsToInvs = [&](const auto &itemVoteRecordRange, | ||||
auto buildInvFromVoteItem) { | auto buildInvFromVoteItem) { | ||||
for (const auto &[item, voteRecord] : itemVoteRecordRange) { | for (const auto &[item, voteRecord] : itemVoteRecordRange) { | ||||
if (invs.size() >= AVALANCHE_MAX_ELEMENT_POLL) { | if (invs.size() >= AVALANCHE_MAX_ELEMENT_POLL) { | ||||
// Make sure we do not produce more invs than specified by the | // Make sure we do not produce more invs than specified by the | ||||
// protocol. | // protocol. | ||||
return true; | return true; | ||||
} | } | ||||
const bool shouldPoll = | const bool shouldPoll = voteRecord.shouldPoll() && | ||||
Fabien: You simply don't need this at all.
What this method cares about is making sure you don't… | |||||
forPoll ? voteRecord.registerPoll() : voteRecord.shouldPoll(); | (!forPoll || voteRecord.registerPoll()); | ||||
if (!shouldPoll) { | if (!shouldPoll) { | ||||
continue; | continue; | ||||
} | } | ||||
invs.emplace_back(buildInvFromVoteItem(item)); | invs.emplace_back(buildInvFromVoteItem(item)); | ||||
} | } | ||||
return invs.size() >= AVALANCHE_MAX_ELEMENT_POLL; | return invs.size() >= AVALANCHE_MAX_ELEMENT_POLL; | ||||
▲ Show 20 Lines • Show All 224 Lines • Show Last 20 Lines |
You simply don't need this at all.
What this method cares about is making sure you don't return more elements that the limit. Why does it need to care about the status of the vote ? If it's in the vote record map, then it's worth being polled. The check you introduce here is creating thread safety concern for the sake of maybe avoiding the item one round of vote, it's not worth it imo.
If anything you can do like the blocks and erase the vote records that are no longer needed via an IsWorthPolling method for example.