Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 361 Lines • ▼ Show 20 Lines | return eventLoop.startEventLoop( | ||||
scheduler, [this]() { this->runEventLoop(); }, | scheduler, [this]() { this->runEventLoop(); }, | ||||
AVALANCHE_TIME_STEP_MILLISECONDS); | AVALANCHE_TIME_STEP_MILLISECONDS); | ||||
} | } | ||||
bool AvalancheProcessor::stopEventLoop() { | bool AvalancheProcessor::stopEventLoop() { | ||||
return eventLoop.stopEventLoop(); | return eventLoop.stopEventLoop(); | ||||
} | } | ||||
std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) const { | std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) { | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
auto r = vote_records.getReadView(); | // First remove all blocks that are not worth polling. | ||||
for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | |||||
reverse_iterate(r)) { | |||||
const CBlockIndex *pindex = p.first; | |||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
auto w = vote_records.getWriteView(); | |||||
for (auto it = w->begin(); it != w->end();) { | |||||
const CBlockIndex *pindex = it->first; | |||||
if (!IsWorthPolling(pindex)) { | if (!IsWorthPolling(pindex)) { | ||||
// Obviously do not poll if the block is not worth polling. | w->erase(it++); | ||||
continue; | } else { | ||||
++it; | |||||
} | |||||
} | } | ||||
} | } | ||||
auto r = vote_records.getReadView(); | |||||
for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | |||||
reverse_iterate(r)) { | |||||
// Check if we can run poll. | // Check if we can run poll. | ||||
const bool shouldPoll = | const bool shouldPoll = | ||||
forPoll ? p.second.registerPoll() : p.second.shouldPoll(); | forPoll ? p.second.registerPoll() : p.second.shouldPoll(); | ||||
if (!shouldPoll) { | if (!shouldPoll) { | ||||
continue; | continue; | ||||
} | } | ||||
// We don't have a decision, we need more votes. | // We don't have a decision, we need more votes. | ||||
invs.emplace_back(MSG_BLOCK, pindex->GetBlockHash()); | invs.emplace_back(MSG_BLOCK, p.first->GetBlockHash()); | ||||
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 invs; | return invs; | ||||
} | } | ||||
} | } | ||||
return invs; | return invs; | ||||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |