Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | if (it == nodes.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return !it->avaproofsSent && | return !it->avaproofsSent && | ||||
nodes.modify(it, [&](Node &n) { n.avaproofsSent = true; }); | nodes.modify(it, [&](Node &n) { n.avaproofsSent = true; }); | ||||
} | } | ||||
static bool isOrphanState(const ProofValidationState &state) { | static bool isOrphanState(const ProofValidationState &state) { | ||||
return state.GetResult() == ProofValidationResult::MISSING_UTXO || | return state.GetResult() == ProofValidationResult::IMMATURE_UTXO; | ||||
state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH || | |||||
state.GetResult() == ProofValidationResult::IMMATURE_UTXO; | |||||
} | } | ||||
bool PeerManager::updateNextPossibleConflictTime( | bool PeerManager::updateNextPossibleConflictTime( | ||||
PeerId peerid, const std::chrono::seconds &nextTime) { | PeerId peerid, const std::chrono::seconds &nextTime) { | ||||
auto it = peers.find(peerid); | auto it = peers.find(peerid); | ||||
if (it == peers.end()) { | if (it == peers.end()) { | ||||
// No such peer | // No such peer | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | bool PeerManager::registerProof(const ProofRef &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)) { | ||||
// 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); | orphanProofPool.addProofIfPreferred(proof); | ||||
} else if (orphanProofPool.countProofs() > | if (orphanProofPool.countProofs() > AVALANCHE_MAX_ORPHAN_PROOFS) { | ||||
AVALANCHE_MAX_ORPHAN_PROOFS) { | // Adding this proof exceeds the orphan pool limit, so evict | ||||
// Adding this proof exceeds the orphan pool limit, so remove | // the lowest scoring proof. | ||||
// it. | orphanProofPool.removeProof( | ||||
orphanProofPool.removeProof(proof->getId()); | orphanProofPool.getLowestScoreProof()->getId()); | ||||
} | } | ||||
return invalidate(ProofRegistrationResult::ORPHAN, "orphan-proof"); | return invalidate(ProofRegistrationResult::ORPHAN, "orphan-proof"); | ||||
} | } | ||||
// Reject invalid proof. | // Reject invalid proof. | ||||
return invalidate(ProofRegistrationResult::INVALID, "invalid-proof"); | return invalidate(ProofRegistrationResult::INVALID, "invalid-proof"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 558 Lines • Show Last 20 Lines |