Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < size; i++) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
std::map<CBlockIndex *, AvalancheVote> responseIndex; | std::map<CBlockIndex *, AvalancheVote> responseIndex; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
for (auto &v : votes) { | for (const auto &v : votes) { | ||||
BlockMap::iterator mi = mapBlockIndex.find(BlockHash(v.GetHash())); | BlockMap::iterator mi = mapBlockIndex.find(BlockHash(v.GetHash())); | ||||
if (mi == mapBlockIndex.end()) { | if (mi == mapBlockIndex.end()) { | ||||
// This should not happen, but just in case... | // This should not happen, but just in case... | ||||
continue; | continue; | ||||
} | } | ||||
CBlockIndex *pindex = mi->second; | CBlockIndex *pindex = mi->second; | ||||
if (!IsWorthPolling(pindex)) { | if (!IsWorthPolling(pindex)) { | ||||
// There is no point polling this block. | // There is no point polling this block. | ||||
continue; | continue; | ||||
} | } | ||||
responseIndex.insert(std::make_pair(pindex, v)); | responseIndex.insert(std::make_pair(pindex, v)); | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
// Register votes. | // Register votes. | ||||
auto w = vote_records.getWriteView(); | auto w = vote_records.getWriteView(); | ||||
for (auto &p : responseIndex) { | for (const auto &p : responseIndex) { | ||||
CBlockIndex *pindex = p.first; | CBlockIndex *pindex = p.first; | ||||
const AvalancheVote &v = p.second; | const AvalancheVote &v = p.second; | ||||
auto it = w->find(pindex); | auto it = w->find(pindex); | ||||
if (it == w.end()) { | if (it == w.end()) { | ||||
// We are not voting on that item anymore. | // We are not voting on that item anymore. | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | void AvalancheProcessor::clearTimedoutRequests() { | ||||
auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
std::map<CInv, uint8_t> timedout_items{}; | std::map<CInv, uint8_t> timedout_items{}; | ||||
{ | { | ||||
// Clear expired requests. | // Clear expired requests. | ||||
auto w = queries.getWriteView(); | auto w = queries.getWriteView(); | ||||
auto it = w->get<query_timeout>().begin(); | auto it = w->get<query_timeout>().begin(); | ||||
while (it != w->get<query_timeout>().end() && it->timeout < now) { | while (it != w->get<query_timeout>().end() && it->timeout < now) { | ||||
for (auto &i : it->invs) { | for (const auto &i : it->invs) { | ||||
timedout_items[i]++; | timedout_items[i]++; | ||||
} | } | ||||
w->get<query_timeout>().erase(it++); | w->get<query_timeout>().erase(it++); | ||||
} | } | ||||
} | } | ||||
if (timedout_items.empty()) { | if (timedout_items.empty()) { | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |