Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 403 Lines • ▼ Show 20 Lines | bool PeerManager::verify() const { | ||||
for (const auto &p : peers) { | for (const auto &p : peers) { | ||||
// A peer should have a proof attached | // A peer should have a proof attached | ||||
if (!p.proof) { | if (!p.proof) { | ||||
return false; | return false; | ||||
} | } | ||||
// Check proof pool consistency | // Check proof pool consistency | ||||
for (const auto &ss : p.proof->getStakes()) { | for (const auto &ss : p.proof->getStakes()) { | ||||
auto it = validProofPool.pool.find(ss.getStake().getUTXO()); | const COutPoint &outpoint = ss.getStake().getUTXO(); | ||||
auto proof = validProofPool.getProof(outpoint); | |||||
if (it == validProofPool.pool.end()) { | if (!proof) { | ||||
// Missing utxo | // Missing utxo | ||||
return false; | return false; | ||||
} | } | ||||
if (it->proof != p.proof) { | if (proof != p.proof) { | ||||
// Wrong proof | // Wrong proof | ||||
return false; | return false; | ||||
} | } | ||||
if (!peersUtxos.emplace(it->getUTXO()).second) { | if (!peersUtxos.emplace(outpoint).second) { | ||||
// Duplicated utxo | // Duplicated utxo | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// Count node attached to this peer. | // Count node attached to this peer. | ||||
const auto count_nodes = [&]() { | const auto count_nodes = [&]() { | ||||
size_t count = 0; | size_t count = 0; | ||||
Show All 25 Lines | for (const auto &p : peers) { | ||||
} | } | ||||
// If the score do not match, same thing. | // If the score do not match, same thing. | ||||
if (slots[p.index].getScore() != p.getScore()) { | if (slots[p.index].getScore() != p.getScore()) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// Check there is no dangling utxo | // We checked the utxo consistency for all our peers utxos already, so if | ||||
for (const auto &entry : validProofPool.pool) { | // the pool size differs from the expected one there are dangling utxos. | ||||
if (!peersUtxos.count(entry.getUTXO())) { | if (validProofPool.size() != peersUtxos.size()) { | ||||
return false; | return false; | ||||
} | } | ||||
} | |||||
return true; | return true; | ||||
} | } | ||||
PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | ||||
const uint64_t max) { | const uint64_t max) { | ||||
assert(slot <= max); | assert(slot <= max); | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |