Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | bool PeerManager::updateNextRequestTime(NodeId nodeid, TimePoint timeout) { | ||||
return nodes.modify(it, [&](Node &n) { n.nextRequestTime = timeout; }); | return nodes.modify(it, [&](Node &n) { n.nextRequestTime = timeout; }); | ||||
} | } | ||||
bool PeerManager::registerProof(const std::shared_ptr<Proof> &proof) { | bool PeerManager::registerProof(const std::shared_ptr<Proof> &proof) { | ||||
return !getProof(proof->getId()) && getPeerId(proof) != NO_PEER; | return !getProof(proof->getId()) && getPeerId(proof) != NO_PEER; | ||||
} | } | ||||
bool PeerManager::registerConflictingProof( | |||||
const std::shared_ptr<Proof> &proof) { | |||||
for (const auto &s : proof->getStakes()) { | |||||
auto it = utxos.find(s.getStake().getUTXO()); | |||||
if (it != utxos.end()) { | |||||
removePeer(it->second); | |||||
} | |||||
} | |||||
// If the proof ends up being invalid lately, we have removed the valid | |||||
// conflicting peers. This might be a deliberate action from the proof | |||||
// owner, or maybe the invalidity did not propagate the same over the | |||||
// network. In any case we want to follow the vote of the avalanche network. | |||||
return registerProof(proof); | |||||
} | |||||
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 | ||||
// unlikely due to high fragmentation, so compact and retry. | // unlikely due to high fragmentation, so compact and retry. | ||||
if (p == NO_PEER) { | if (p == NO_PEER) { | ||||
compact(); | compact(); | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |