diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -425,15 +425,13 @@ if (invs[i].IsMsgProof()) { const ProofId proofid(votes[i].GetHash()); - // TODO Use an unordered map or similar to avoid the loop - auto proofVoteRecordsReadView = proofVoteRecords.getReadView(); - for (auto it = proofVoteRecordsReadView.begin(); - it != proofVoteRecordsReadView.end(); it++) { - if (it->first->getId() == proofid) { - responseProof.insert(std::make_pair(it->first, votes[i])); - break; - } + LOCK(cs_peerManager); + const ProofRef proof = peerManager->getProof(proofid); + if (!proof) { + continue; } + + responseProof.insert(std::make_pair(proof, votes[i])); } } @@ -649,15 +647,14 @@ } if (inv.IsMsgProof()) { - auto w = proofVoteRecords.getWriteView(); ProofRef proof; - for (auto it = w.begin(); it != w.end(); it++) { - if (it->first->getId() == inv.hash) { - proof = it->first; - } + { + LOCK(cs_peerManager); + proof = peerManager->getProof(ProofId(inv.hash)); } - if (!clearInflightRequest(std::move(w), proof, p.second)) { + if (!clearInflightRequest(proofVoteRecords.getWriteView(), proof, + p.second)) { continue; } }