diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -227,13 +227,10 @@ return proof->verify(validationState, ::ChainstateActive().CoinsTip()))) { if (isOrphanState(validationState)) { + orphanProofPool.addProofIfPreferred(proof); + // Only accept orphan proofs if there's room in the orphan pool. - auto status = orphanProofPool.addProofIfNoConflict(proof); - if (status != ProofPool::AddProofStatus::SUCCEED) { - // Attempt proof replacement - orphanProofPool.addProofIfPreferred(proof); - } else if (orphanProofPool.countProofs() > - AVALANCHE_MAX_ORPHAN_PROOFS) { + if (orphanProofPool.countProofs() > AVALANCHE_MAX_ORPHAN_PROOFS) { // Adding this proof exceeds the orphan pool limit, so remove // it. orphanProofPool.removeProof(proof->getId()); diff --git a/src/avalanche/proofpool.h b/src/avalanche/proofpool.h --- a/src/avalanche/proofpool.h +++ b/src/avalanche/proofpool.h @@ -74,9 +74,6 @@ ProofComparatorByScore>>> pool; - bool cacheClean = true; - size_t cacheProofCount = 0; - struct ProofRegistrationTime { ProofId proofid; // std::chrono::duration is not hashable by default, so use an integer @@ -145,7 +142,7 @@ std::optional getRegistrationTime(const ProofId &proofid) const; size_t size() const { return pool.size(); } - size_t countProofs(); + size_t countProofs() { return registrationTimes.size(); }; }; } // namespace avalanche diff --git a/src/avalanche/proofpool.cpp b/src/avalanche/proofpool.cpp --- a/src/avalanche/proofpool.cpp +++ b/src/avalanche/proofpool.cpp @@ -48,7 +48,6 @@ registrationTimes.emplace(proofid, GetTime()); - cacheClean = false; return AddProofStatus::SUCCEED; } @@ -71,7 +70,6 @@ status = addProofIfNoConflict(proof); assert(status == AddProofStatus::SUCCEED); - cacheClean = false; return AddProofStatus::SUCCEED; } @@ -79,8 +77,6 @@ // reference to a proof member. This proof will be deleted during the erasure // loop so we pass it by value. bool ProofPool::removeProof(ProofId proofid) { - cacheClean = false; - if (!registrationTimes.erase(proofid)) { return false; } @@ -94,7 +90,6 @@ auto previousRegistrationTimes = std::move(registrationTimes); pool.clear(); registrationTimes.clear(); - cacheClean = false; for (auto &entry : previousPool) { const ProofId &proofid = entry.proof->getId(); @@ -146,25 +141,4 @@ return std::make_optional(it->registrationTime); } -size_t ProofPool::countProofs() { - if (cacheClean) { - return cacheProofCount; - } - - size_t count = 0; - ProofId lastProofId; - auto &poolView = pool.get(); - for (auto it = poolView.begin(); it != poolView.end(); it++) { - const ProofId &proofId = it->proof->getId(); - if (lastProofId != proofId) { - lastProofId = proofId; - count++; - } - } - - cacheProofCount = count; - cacheClean = true; - return cacheProofCount; -} - } // namespace avalanche