Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | bool PeerManager::registerProof(const ProofRef &proof) { | ||||
// Check the proof's validity. | // Check the proof's validity. | ||||
ProofValidationState state; | ProofValidationState state; | ||||
// Using WITH_LOCK directly inside the if statement will trigger a cppcheck | // Using WITH_LOCK directly inside the if statement will trigger a cppcheck | ||||
// false positive syntax error | // false positive syntax error | ||||
const bool valid = WITH_LOCK( | const bool valid = WITH_LOCK( | ||||
cs_main, return proof->verify(state, ::ChainstateActive().CoinsTip())); | cs_main, return proof->verify(state, ::ChainstateActive().CoinsTip())); | ||||
if (!valid) { | if (!valid) { | ||||
if (isOrphanState(state)) { | if (isOrphanState(state)) { | ||||
orphanProofPool.addProof(proof); | orphanProofPool.addProofIfPreferred(proof); | ||||
} | } | ||||
// Reject invalid proof. | // Reject invalid proof. | ||||
return false; | return false; | ||||
} | } | ||||
return createPeer(proof); | return createPeer(proof); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void PeerManager::updatedBlockTip() { | ||||
// invalid peers. | // invalid peers. | ||||
for (const auto &pid : invalidPeers) { | for (const auto &pid : invalidPeers) { | ||||
removePeer(pid); | removePeer(pid); | ||||
} | } | ||||
orphanProofPool.rescan(*this); | orphanProofPool.rescan(*this); | ||||
for (auto &p : newOrphans) { | for (auto &p : newOrphans) { | ||||
orphanProofPool.addProof(p); | orphanProofPool.addProofIfPreferred(p); | ||||
} | } | ||||
} | } | ||||
ProofRef PeerManager::getProof(const ProofId &proofid) const { | ProofRef PeerManager::getProof(const ProofId &proofid) const { | ||||
ProofRef proof = nullptr; | ProofRef proof = nullptr; | ||||
forPeer(proofid, [&](const Peer &p) { | forPeer(proofid, [&](const Peer &p) { | ||||
proof = p.proof; | proof = p.proof; | ||||
Show All 14 Lines | |||||
bool PeerManager::isOrphan(const ProofId &proofid) const { | bool PeerManager::isOrphan(const ProofId &proofid) const { | ||||
return orphanProofPool.getProof(proofid) != nullptr; | return orphanProofPool.getProof(proofid) != nullptr; | ||||
} | } | ||||
bool PeerManager::createPeer(const ProofRef &proof) { | bool PeerManager::createPeer(const ProofRef &proof) { | ||||
assert(proof); | assert(proof); | ||||
switch (validProofPool.addProof(proof)) { | switch (validProofPool.addProofIfNoConflict(proof)) { | ||||
case ProofPool::AddProofStatus::REJECTED: | case ProofPool::AddProofStatus::REJECTED: | ||||
// The proof has conflicts, orphan the proof so it can be pulled | // The proof has conflicts, orphan the proof so it can be pulled | ||||
// back if the conflicting ones are invalidated. | // back if the conflicting ones are invalidated. | ||||
orphanProofPool.addProof(proof); | orphanProofPool.addProofIfPreferred(proof); | ||||
return false; | return false; | ||||
case ProofPool::AddProofStatus::DUPLICATED: | case ProofPool::AddProofStatus::DUPLICATED: | ||||
// If the proof was already in the pool, don't duplicate the peer. | // If the proof was already in the pool, don't duplicate the peer. | ||||
return false; | return false; | ||||
case ProofPool::AddProofStatus::SUCCEED: | case ProofPool::AddProofStatus::SUCCEED: | ||||
break; | break; | ||||
// No default case, so the compiler can warn about missing cases | // No default case, so the compiler can warn about missing cases | ||||
▲ Show 20 Lines • Show All 274 Lines • Show Last 20 Lines |