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/delegation.h> | #include <avalanche/delegation.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <net_processing.h> // For RelayProof | #include <net_processing.h> // For RelayProof | ||||
#include <random.h> | #include <random.h> | ||||
#include <validation.h> // For ChainstateActive() | #include <validation.h> // For ChainstateActive() | ||||
#include <cassert> | #include <cassert> | ||||
namespace avalanche { | namespace avalanche { | ||||
static bool isOrphanState(const ProofValidationState &state) { | |||||
return state.GetResult() == ProofValidationResult::MISSING_UTXO || | |||||
state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; | |||||
} | |||||
bool PeerManager::addNode(NodeId nodeid, const ProofId &proofid) { | bool PeerManager::addNode(NodeId nodeid, const ProofId &proofid) { | ||||
auto &pview = peers.get<proof_index>(); | auto &pview = peers.get<proof_index>(); | ||||
auto it = pview.find(proofid); | auto it = pview.find(proofid); | ||||
if (it == pview.end()) { | if (it == pview.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return addOrUpdateNode(peers.project<0>(it), nodeid); | return addOrUpdateNode(peers.project<0>(it), nodeid); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | ||||
it->nextRequestTime <= std::chrono::steady_clock::now()) { | it->nextRequestTime <= std::chrono::steady_clock::now()) { | ||||
return it->nodeid; | return it->nodeid; | ||||
} | } | ||||
} | } | ||||
return NO_NODE; | return NO_NODE; | ||||
} | } | ||||
static bool isOrphanState(const ProofValidationState &state) { | |||||
return state.GetResult() == ProofValidationResult::MISSING_UTXO || | |||||
state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; | |||||
} | |||||
void PeerManager::updatedBlockTip() { | void PeerManager::updatedBlockTip() { | ||||
std::vector<PeerId> invalidPeers; | std::vector<PeerId> invalidPeers; | ||||
std::vector<std::shared_ptr<Proof>> newOrphans; | std::vector<std::shared_ptr<Proof>> newOrphans; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | const CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | ||||
▲ Show 20 Lines • Show All 356 Lines • Show Last 20 Lines |