Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/orphanproofpool.cpp
// Copyright (c) 2021 The Bitcoin developers | // Copyright (c) 2021 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/orphanproofpool.h> | #include <avalanche/orphanproofpool.h> | ||||
#include <avalanche/peermanager.h> | |||||
#include <utility> | |||||
namespace avalanche { | namespace avalanche { | ||||
void OrphanProofPool::trimToMaximumSize() { | void OrphanProofPool::trimToMaximumSize() { | ||||
auto &proofs_by_sequence = proofs.get<by_sequence>(); | auto &proofs_by_sequence = proofs.get<by_sequence>(); | ||||
auto it = proofs_by_sequence.begin(); | auto it = proofs_by_sequence.begin(); | ||||
while (nStakes > maxNumberOfStakes) { | while (nStakes > maxNumberOfStakes) { | ||||
nStakes -= (*it)->getStakes().size(); | nStakes -= (*it)->getStakes().size(); | ||||
it = proofs_by_sequence.erase(it); | it = proofs_by_sequence.erase(it); | ||||
Show All 22 Lines | |||||
} | } | ||||
std::shared_ptr<Proof> OrphanProofPool::getProof(const ProofId &proofId) const { | std::shared_ptr<Proof> OrphanProofPool::getProof(const ProofId &proofId) const { | ||||
auto &proofs_by_proofid = proofs.get<by_proofid>(); | auto &proofs_by_proofid = proofs.get<by_proofid>(); | ||||
auto it = proofs_by_proofid.find(proofId); | auto it = proofs_by_proofid.find(proofId); | ||||
return it == proofs_by_proofid.end() ? nullptr : *it; | return it == proofs_by_proofid.end() ? nullptr : *it; | ||||
} | } | ||||
void OrphanProofPool::rescan(PeerManager &peerManager) { | |||||
ProofContainer last_gen_proofs = std::move(proofs); | |||||
proofs.clear(); | |||||
for (auto &proof : last_gen_proofs.get<by_sequence>()) { | |||||
peerManager.getPeerId(proof); | |||||
} | |||||
} | |||||
size_t OrphanProofPool::getNProofs() const { | size_t OrphanProofPool::getNProofs() const { | ||||
return proofs.size(); | return proofs.size(); | ||||
} | } | ||||
size_t OrphanProofPool::getNStakes() const { | size_t OrphanProofPool::getNStakes() const { | ||||
return nStakes; | return nStakes; | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |