Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show All 13 Lines | |||||
namespace avalanche { | namespace avalanche { | ||||
static bool isOrphanState(const ProofValidationState &state) { | static bool isOrphanState(const ProofValidationState &state) { | ||||
return state.GetResult() == ProofValidationResult::MISSING_UTXO || | return state.GetResult() == ProofValidationResult::MISSING_UTXO || | ||||
state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; | state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; | ||||
} | } | ||||
bool PeerManager::addNode(NodeId nodeid, const std::shared_ptr<Proof> &proof, | bool PeerManager::addNode(NodeId nodeid, const Delegation &delegation) { | ||||
const Delegation &delegation) { | auto &pview = peers.get<proof_index>(); | ||||
auto it = fetchOrCreatePeer(proof); | auto it = pview.find(delegation.getProofId()); | ||||
if (it == peers.end()) { | if (it == pview.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
DelegationState state; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (!delegation.verify(state, pubkey)) { | if (!delegation.verify(state, pubkey)) { | ||||
return false; | return false; | ||||
} | } | ||||
return addOrUpdateNode(it, nodeid, std::move(pubkey)); | return addOrUpdateNode(peers.project<0>(it), nodeid, std::move(pubkey)); | ||||
} | } | ||||
bool PeerManager::addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid, | bool PeerManager::addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid, | ||||
CPubKey pubkey) { | CPubKey pubkey) { | ||||
assert(it != peers.end()); | assert(it != peers.end()); | ||||
const PeerId peerid = it->peerid; | const PeerId peerid = it->peerid; | ||||
▲ Show 20 Lines • Show All 491 Lines • Show Last 20 Lines |