Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | bool isAccepted; | ||||
isAccepted = ::ChainActive().Contains(pindex); | isAccepted = ::ChainActive().Contains(pindex); | ||||
} | } | ||||
return blockVoteRecords.getWriteView() | return blockVoteRecords.getWriteView() | ||||
->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ||||
.second; | .second; | ||||
} | } | ||||
void Processor::addProofToReconcile(const std::shared_ptr<Proof> &proof, | |||||
bool isAccepted) { | |||||
// TODO We don't want to accept an infinite number of conflicting proofs. | |||||
// They should be some rules to make them expensive and/or limited by | |||||
// design. | |||||
proofsVoteRecords.getWriteView()->insert( | |||||
std::make_pair(proof, VoteRecord(isAccepted))); | |||||
} | |||||
bool Processor::isAccepted(const CBlockIndex *pindex) const { | bool Processor::isAccepted(const CBlockIndex *pindex) const { | ||||
auto r = blockVoteRecords.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(); | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | |||||
bool Processor::stopEventLoop() { | bool Processor::stopEventLoop() { | ||||
return eventLoop.stopEventLoop(); | return eventLoop.stopEventLoop(); | ||||
} | } | ||||
std::vector<CInv> Processor::getInvsForNextPoll(bool forPoll) { | std::vector<CInv> Processor::getInvsForNextPoll(bool forPoll) { | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
auto conflictingProofsReadView = proofsVoteRecords.getReadView(); | |||||
auto pit = conflictingProofsReadView.begin(); | |||||
// Clamp to AVALANCHE_MAX_ELEMENT_POLL - 1 so we're always able to poll | |||||
// for a new block. Since the proofs are sorted by score, the most | |||||
// valuable are voted first. | |||||
while (pit != conflictingProofsReadView.end() && | |||||
invs.size() < AVALANCHE_MAX_ELEMENT_POLL - 1) { | |||||
invs.emplace_back(MSG_AVA_PROOF, pit->first->getId()); | |||||
++pit; | |||||
} | |||||
// 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 = blockVoteRecords.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++); | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |