Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 416 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < size; i++) { | ||||
} | } | ||||
responseIndex.insert(std::make_pair(pindex, votes[i])); | responseIndex.insert(std::make_pair(pindex, votes[i])); | ||||
} | } | ||||
if (invs[i].IsMsgProof()) { | if (invs[i].IsMsgProof()) { | ||||
const ProofId proofid(votes[i].GetHash()); | const ProofId proofid(votes[i].GetHash()); | ||||
// TODO Use an unordered map or similar to avoid the loop | const ProofRef proof = WITH_LOCK( | ||||
auto proofVoteRecordsReadView = proofVoteRecords.getReadView(); | cs_peerManager, return peerManager->getProof(proofid)); | ||||
for (auto it = proofVoteRecordsReadView.begin(); | if (!proof) { | ||||
it != proofVoteRecordsReadView.end(); it++) { | continue; | ||||
if (it->first->getId() == proofid) { | |||||
responseProof.insert(std::make_pair(it->first, votes[i])); | |||||
break; | |||||
} | |||||
} | } | ||||
responseProof.insert(std::make_pair(proof, votes[i])); | |||||
} | } | ||||
} | } | ||||
// Thanks to C++14 generic lambdas, we can apply the same logic to various | // Thanks to C++14 generic lambdas, we can apply the same logic to various | ||||
// parameter types sharing the same interface. | // parameter types sharing the same interface. | ||||
auto registerVoteItems = [&](auto voteRecordsWriteView, auto &updates, | auto registerVoteItems = [&](auto voteRecordsWriteView, auto &updates, | ||||
auto responseItems) { | auto responseItems) { | ||||
// Register votes. | // Register votes. | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | for (const auto &p : timedout_items) { | ||||
cs_main, return LookupBlockIndex(BlockHash(inv.hash))); | cs_main, return LookupBlockIndex(BlockHash(inv.hash))); | ||||
if (!clearInflightRequest(blockVoteRecords, pindex, p.second)) { | if (!clearInflightRequest(blockVoteRecords, pindex, p.second)) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
if (inv.IsMsgProof()) { | if (inv.IsMsgProof()) { | ||||
ProofRef proof; | const ProofRef proof = | ||||
{ | WITH_LOCK(cs_peerManager, | ||||
auto w = proofVoteRecords.getWriteView(); | return peerManager->getProof(ProofId(inv.hash))); | ||||
for (auto it = w.begin(); it != w.end(); it++) { | |||||
if (it->first->getId() == inv.hash) { | |||||
proof = it->first; | |||||
} | |||||
} | |||||
} | |||||
if (!clearInflightRequest(proofVoteRecords, proof, p.second)) { | if (!clearInflightRequest(proofVoteRecords, proof, p.second)) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |