Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | void PeerManager::updatedBlockTip() { | ||||
std::vector<PeerId> invalidPeers; | std::vector<PeerId> invalidPeers; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | const CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | ||||
for (const auto &p : peers) { | for (const auto &p : peers) { | ||||
ProofValidationState state; | ProofValidationState state; | ||||
if (!p.proof.verify(state, coins)) { | if (!p.proof->verify(state, coins)) { | ||||
invalidPeers.push_back(p.peerid); | invalidPeers.push_back(p.peerid); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (const auto &pid : invalidPeers) { | for (const auto &pid : invalidPeers) { | ||||
removePeer(pid); | removePeer(pid); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | bool PeerManager::removePeer(const PeerId peerid) { | ||||
// active. This ensure that we don't overquery them in case they are | // active. This ensure that we don't overquery them in case they are | ||||
// subsequently added to another peer. | // subsequently added to another peer. | ||||
auto &nview = nodes.get<next_request_time>(); | auto &nview = nodes.get<next_request_time>(); | ||||
nview.erase(nview.lower_bound(boost::make_tuple(peerid, TimePoint())), | nview.erase(nview.lower_bound(boost::make_tuple(peerid, TimePoint())), | ||||
nview.upper_bound(boost::make_tuple( | nview.upper_bound(boost::make_tuple( | ||||
peerid, std::chrono::steady_clock::now()))); | peerid, std::chrono::steady_clock::now()))); | ||||
// Release UTXOs attached to this proof. | // Release UTXOs attached to this proof. | ||||
for (const auto &s : it->proof.getStakes()) { | for (const auto &s : it->proof->getStakes()) { | ||||
bool deleted = utxos.erase(s.getStake().getUTXO()) > 0; | bool deleted = utxos.erase(s.getStake().getUTXO()) > 0; | ||||
assert(deleted); | assert(deleted); | ||||
} | } | ||||
peers.erase(it); | peers.erase(it); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |