Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | ||||
} | } | ||||
} | } | ||||
return NO_NODE; | return NO_NODE; | ||||
} | } | ||||
void PeerManager::updatedBlockTip() { | void PeerManager::updatedBlockTip() { | ||||
std::vector<PeerId> invalidPeers; | std::vector<PeerId> invalidPeers; | ||||
std::vector<Proof *> noLongerOrphans; | |||||
{ | { | ||||
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); | ||||
} | } | ||||
// TODO: find out if the coin got spent, or just dropped from | |||||
// the mempool and can potentially be resubmitted again (orphan) | |||||
} | |||||
for (auto &[id, proof] : orphanProofs) { | |||||
ProofValidationState state; | |||||
if (fetchOrCreatePeer(proof, state) != peers.end()) { | |||||
noLongerOrphans.push_back(&proof); | |||||
} else if (state.GetResult() != | |||||
ProofValidationResult::MISSING_UTXO) { | |||||
// An orphan proof can become bad after we find the specified | |||||
// txid and it turns out to not match the amount, or the block | |||||
// height, or the destination type pkhash... | |||||
noLongerOrphans.push_back(&proof); | |||||
recentProofRejects->insert(proof.getId()); | |||||
} | |||||
} | } | ||||
} | } | ||||
for (const auto &pid : invalidPeers) { | for (const auto &pid : invalidPeers) { | ||||
removePeer(pid); | removePeer(pid); | ||||
} | } | ||||
for (const auto &proof : noLongerOrphans) { | |||||
orphanProofs.erase(proof->getId()); | |||||
} | |||||
} | } | ||||
PeerId PeerManager::getPeerId(const Proof &proof) { | PeerId PeerManager::getPeerId(const Proof &proof) { | ||||
auto it = fetchOrCreatePeer(proof); | auto it = fetchOrCreatePeer(proof); | ||||
return it == peers.end() ? NO_PEER : it->peerid; | return it == peers.end() ? NO_PEER : it->peerid; | ||||
} | } | ||||
PeerManager::PeerSet::iterator | PeerManager::PeerSet::iterator | ||||
▲ Show 20 Lines • Show All 316 Lines • Show Last 20 Lines |