Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 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/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <avalanche/avalanche.h> | |||||
#include <avalanche/delegation.h> | #include <avalanche/delegation.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <validation.h> // For ChainstateActive() | #include <validation.h> // For ChainstateActive() | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if (!valid) { | ||||
// Reject invalid proof. | // Reject invalid proof. | ||||
return false; | return false; | ||||
} | } | ||||
ProofPool::ConflictingProofSet conflictingProofs; | ProofPool::ConflictingProofSet conflictingProofs; | ||||
switch (validProofPool.addProofIfNoConflict(proof, conflictingProofs)) { | switch (validProofPool.addProofIfNoConflict(proof, conflictingProofs)) { | ||||
case ProofPool::AddProofStatus::REJECTED: { | case ProofPool::AddProofStatus::REJECTED: { | ||||
if (mode != FORCE_ACCEPT) { | if (mode != FORCE_ACCEPT) { | ||||
auto now = GetTime<std::chrono::seconds>(); | |||||
auto nextCooldownTimePoint = | |||||
now + std::chrono::seconds(gArgs.GetArg( | |||||
"-avalancheconflictingproofcooldown", | |||||
AVALANCHE_DEFAULT_CONFLICTING_PROOF_COOLDOWN)); | |||||
auto bestPossibleConflictTime = std::chrono::seconds(); | |||||
auto &pview = peers.get<by_proofid>(); | |||||
for (auto &conflictingProof : conflictingProofs) { | |||||
auto it = pview.find(conflictingProof->getId()); | |||||
assert(it != pview.end()); | |||||
// Search the most recent time over the peers | |||||
bestPossibleConflictTime = std::max( | |||||
bestPossibleConflictTime, it->nextPossibleConflictTime); | |||||
updateNextPossibleConflictTime(it->peerid, | |||||
nextCooldownTimePoint); | |||||
} | |||||
if (bestPossibleConflictTime > now) { | |||||
// Cooldown not elapsed, reject the proof. | |||||
return false; | |||||
} | |||||
// The proof has conflicts, move it to the conflicting proof | // The proof has conflicts, move it to the conflicting proof | ||||
// pool so it can be pulled back if the conflicting ones are | // pool so it can be pulled back if the conflicting ones are | ||||
// invalidated. | // invalidated. | ||||
conflictingProofPool.addProofIfPreferred(proof); | conflictingProofPool.addProofIfPreferred(proof); | ||||
return false; | return false; | ||||
} | } | ||||
conflictingProofPool.removeProof(proof->getId()); | conflictingProofPool.removeProof(proof->getId()); | ||||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |