Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | bool isAccepted; | ||||
if (!IsWorthPolling(pindex)) { | if (!IsWorthPolling(pindex)) { | ||||
// There is no point polling this block. | // There is no point polling this block. | ||||
return false; | return false; | ||||
} | } | ||||
isAccepted = ::ChainActive().Contains(pindex); | isAccepted = ::ChainActive().Contains(pindex); | ||||
} | } | ||||
return vote_records.getWriteView() | return blockVoteRecords.getWriteView() | ||||
->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ||||
.second; | .second; | ||||
} | } | ||||
bool Processor::isAccepted(const CBlockIndex *pindex) const { | bool Processor::isAccepted(const CBlockIndex *pindex) const { | ||||
auto r = vote_records.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return it->second.isAccepted(); | return it->second.isAccepted(); | ||||
} | } | ||||
int Processor::getConfidence(const CBlockIndex *pindex) const { | int Processor::getConfidence(const CBlockIndex *pindex) const { | ||||
auto r = vote_records.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return -1; | return -1; | ||||
} | } | ||||
return it->second.getConfidence(); | return it->second.getConfidence(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | std::map<CBlockIndex *, Vote> responseIndex; | ||||
} | } | ||||
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 = blockVoteRecords.getWriteView(); | ||||
for (const auto &p : responseIndex) { | for (const auto &p : responseIndex) { | ||||
CBlockIndex *pindex = p.first; | CBlockIndex *pindex = p.first; | ||||
const Vote &v = p.second; | const Vote &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 80 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
std::vector<CInv> Processor::getInvsForNextPoll(bool forPoll) { | std::vector<CInv> Processor::getInvsForNextPoll(bool forPoll) { | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
// First remove all blocks that are not worth polling. | // First remove all blocks that are not worth polling. | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
auto w = vote_records.getWriteView(); | auto w = blockVoteRecords.getWriteView(); | ||||
for (auto it = w->begin(); it != w->end();) { | for (auto it = w->begin(); it != w->end();) { | ||||
const CBlockIndex *pindex = it->first; | const CBlockIndex *pindex = it->first; | ||||
if (!IsWorthPolling(pindex)) { | if (!IsWorthPolling(pindex)) { | ||||
w->erase(it++); | w->erase(it++); | ||||
} else { | } else { | ||||
++it; | ++it; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
auto r = vote_records.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | ||||
reverse_iterate(r)) { | 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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | for (const auto &p : timedout_items) { | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pindex = LookupBlockIndex(BlockHash(inv.hash)); | pindex = LookupBlockIndex(BlockHash(inv.hash)); | ||||
if (!pindex) { | if (!pindex) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
auto w = vote_records.getWriteView(); | auto w = blockVoteRecords.getWriteView(); | ||||
auto it = w->find(pindex); | auto it = w->find(pindex); | ||||
if (it == w.end()) { | if (it == w.end()) { | ||||
continue; | continue; | ||||
} | } | ||||
it->second.clearInflightRequest(p.second); | it->second.clearInflightRequest(p.second); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |