Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | if ((mode != RegistrationMode::FORCE_ACCEPT || | ||||
exists(proofid)) { | exists(proofid)) { | ||||
// In default mode, we expect the proof to be unknown, i.e. in none of | // In default mode, we expect the proof to be unknown, i.e. in none of | ||||
// the pools. | // the pools. | ||||
// In forced accept mode, the proof can be in the conflicting pool. | // In forced accept mode, the proof can be in the conflicting pool. | ||||
return invalidate(ProofRegistrationResult::ALREADY_REGISTERED, | return invalidate(ProofRegistrationResult::ALREADY_REGISTERED, | ||||
"proof-already-registered"); | "proof-already-registered"); | ||||
} | } | ||||
if (danglingProofIds.contains(proofid) && | |||||
pendingNodes.count(proofid) == 0) { | |||||
// Don't attempt to register a proof that we already evicted because it | |||||
// was dangling. | |||||
return invalidate(ProofRegistrationResult::DANGLING, "dangling-proof"); | |||||
} | |||||
// Check the proof's validity. | // Check the proof's validity. | ||||
ProofValidationState validationState; | ProofValidationState validationState; | ||||
if (!WITH_LOCK(cs_main, | if (!WITH_LOCK(cs_main, | ||||
return proof->verify(validationState, | return proof->verify(validationState, | ||||
::ChainstateActive().CoinsTip()))) { | ::ChainstateActive().CoinsTip()))) { | ||||
if (isOrphanState(validationState)) { | if (isOrphanState(validationState)) { | ||||
orphanProofPool.addProofIfPreferred(proof); | orphanProofPool.addProofIfPreferred(proof); | ||||
if (orphanProofPool.countProofs() > AVALANCHE_MAX_ORPHAN_PROOFS) { | if (orphanProofPool.countProofs() > AVALANCHE_MAX_ORPHAN_PROOFS) { | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | bool PeerManager::rejectProof(const ProofId &proofid, RejectionMode mode) { | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void PeerManager::cleanupDanglingProofs() { | void PeerManager::cleanupDanglingProofs() { | ||||
const auto now = GetTime<std::chrono::seconds>(); | const auto now = GetTime<std::chrono::seconds>(); | ||||
std::vector<ProofId> danglingProofIds; | std::vector<ProofId> newlyDanglingProofIds; | ||||
for (const Peer &peer : peers) { | for (const Peer &peer : peers) { | ||||
// If the peer has been registered for some time and has no node | // If the peer has been registered for some time and has no node | ||||
// attached, discard it. | // attached, discard it. | ||||
if (peer.node_count == 0 && | if (peer.node_count == 0 && | ||||
(peer.registration_time + Peer::DANGLING_TIMEOUT) <= now) { | (peer.registration_time + Peer::DANGLING_TIMEOUT) <= now) { | ||||
danglingProofIds.push_back(peer.getProofId()); | newlyDanglingProofIds.push_back(peer.getProofId()); | ||||
} | } | ||||
} | } | ||||
for (const ProofId &proofid : danglingProofIds) { | for (const ProofId &proofid : newlyDanglingProofIds) { | ||||
rejectProof(proofid, RejectionMode::INVALIDATE); | rejectProof(proofid, RejectionMode::INVALIDATE); | ||||
danglingProofIds.insert(proofid); | |||||
} | } | ||||
} | } | ||||
NodeId PeerManager::selectNode() { | NodeId PeerManager::selectNode() { | ||||
for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | ||||
const PeerId p = selectPeer(); | const PeerId p = selectPeer(); | ||||
// If we cannot find a peer, it may be due to the fact that it is | // If we cannot find a peer, it may be due to the fact that it is | ||||
▲ Show 20 Lines • Show All 373 Lines • Show Last 20 Lines |