Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.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/proofpool.h> | #include <avalanche/proofpool.h> | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <avalanche/proofcomparator.h> | #include <avalanche/proofcomparator.h> | ||||
#include <unordered_set> | |||||
namespace avalanche { | namespace avalanche { | ||||
ProofPool::AddProofStatus | ProofPool::AddProofStatus | ||||
ProofPool::addProofIfNoConflict(const ProofRef &proof, | ProofPool::addProofIfNoConflict(const ProofRef &proof, | ||||
ConflictingProofSet &conflictingProofs) { | ConflictingProofSet &conflictingProofs) { | ||||
const ProofId &proofid = proof->getId(); | const ProofId &proofid = proof->getId(); | ||||
// Make sure the set is empty before we add items | // Make sure the set is empty before we add items | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | bool ProofPool::removeProof(ProofId proofid) { | ||||
return poolView.erase(proofid); | return poolView.erase(proofid); | ||||
} | } | ||||
void ProofPool::rescan(PeerManager &peerManager) { | void ProofPool::rescan(PeerManager &peerManager) { | ||||
auto previousPool = std::move(pool); | auto previousPool = std::move(pool); | ||||
pool.clear(); | pool.clear(); | ||||
cacheClean = false; | cacheClean = false; | ||||
std::unordered_set<ProofRef, SaltedProofHasher> registeredProofs; | |||||
for (auto &entry : previousPool) { | for (auto &entry : previousPool) { | ||||
if (registeredProofs.insert(entry.proof).second) { | |||||
peerManager.registerProof(entry.proof); | peerManager.registerProof(entry.proof); | ||||
} | } | ||||
} | } | ||||
} | |||||
ProofRef ProofPool::getProof(const ProofId &proofid) const { | ProofRef ProofPool::getProof(const ProofId &proofid) const { | ||||
auto &poolView = pool.get<by_proofid>(); | auto &poolView = pool.get<by_proofid>(); | ||||
auto it = poolView.find(proofid); | auto it = poolView.find(proofid); | ||||
return it == poolView.end() ? ProofRef() : it->proof; | return it == poolView.end() ? ProofRef() : it->proof; | ||||
} | } | ||||
ProofRef ProofPool::getProof(const COutPoint &outpoint) const { | ProofRef ProofPool::getProof(const COutPoint &outpoint) const { | ||||
Show All 32 Lines |