Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | ||||
return it->nodeid; | return it->nodeid; | ||||
} | } | ||||
} | } | ||||
return NO_NODE; | return NO_NODE; | ||||
} | } | ||||
void PeerManager::updatedBlockTip() { | void PeerManager::updatedBlockTip() { | ||||
std::vector<PeerId> invalidPeers; | std::vector<ProofId> invalidProofIds; | ||||
std::vector<ProofRef> newOrphans; | std::vector<ProofRef> newOrphans; | ||||
{ | { | ||||
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)) { | ||||
if (isOrphanState(state)) { | if (isOrphanState(state)) { | ||||
newOrphans.push_back(p.proof); | newOrphans.push_back(p.proof); | ||||
} | } | ||||
invalidPeers.push_back(p.peerid); | invalidProofIds.push_back(p.getProofId()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Remove the invalid peers before the orphans rescan. This makes it | // Remove the invalid proofs before the orphans rescan. This makes it | ||||
// possible to pull back proofs with utxos that conflicted with these | // possible to pull back proofs with utxos that conflicted with these | ||||
// invalid peers. | // invalid proofs. | ||||
for (const auto &pid : invalidPeers) { | for (const ProofId &invalidProofId : invalidProofIds) { | ||||
auto it = peers.find(pid); | rejectProof(invalidProofId); | ||||
assert(it != peers.end()); | |||||
const ProofRef peerProof = it->proof; | |||||
removePeer(pid); | |||||
// If the peer had conflicting proofs, attempt to pull them back | |||||
for (const SignedStake &ss : peerProof->getStakes()) { | |||||
const ProofRef conflictingProof = | |||||
conflictingProofPool.getProof(ss.getStake().getUTXO()); | |||||
if (!conflictingProof) { | |||||
continue; | |||||
} | |||||
conflictingProofPool.removeProof(conflictingProof->getId()); | |||||
registerProof(conflictingProof); | |||||
} | |||||
} | } | ||||
orphanProofPool.rescan(*this); | orphanProofPool.rescan(*this); | ||||
for (auto &p : newOrphans) { | for (auto &p : newOrphans) { | ||||
orphanProofPool.addProofIfPreferred(p); | orphanProofPool.addProofIfPreferred(p); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |