Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show All 39 Lines | |||||
}; | }; | ||||
std::unique_ptr<interfaces::Handler> PeerManager::handleConflictingProof( | std::unique_ptr<interfaces::Handler> PeerManager::handleConflictingProof( | ||||
std::shared_ptr<ConflictingProofHandler> handler) { | std::shared_ptr<ConflictingProofHandler> handler) { | ||||
return std::make_unique<ConflictingProofHandlerImpl>(this, | return std::make_unique<ConflictingProofHandlerImpl>(this, | ||||
std::move(handler)); | std::move(handler)); | ||||
} | } | ||||
bool PeerManager::isConflictingProof(const ProofId &proofid) const { | |||||
return !!m_conflicting_proofids.count(proofid); | |||||
} | |||||
bool PeerManager::addNode(NodeId nodeid, const ProofId &proofid) { | bool PeerManager::addNode(NodeId nodeid, const ProofId &proofid) { | ||||
auto &pview = peers.get<proof_index>(); | auto &pview = peers.get<proof_index>(); | ||||
auto it = pview.find(proofid); | auto it = pview.find(proofid); | ||||
if (it == pview.end()) { | if (it == pview.end()) { | ||||
// If the node exists, it is actually updating its proof to an unknown | // If the node exists, it is actually updating its proof to an unknown | ||||
// one. In this case we need to remove it so it is not both active and | // one. In this case we need to remove it so it is not both active and | ||||
// pending at the same time. | // pending at the same time. | ||||
removeNode(nodeid); | removeNode(nodeid); | ||||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | if (conflicting_peerids.size() > 0) { | ||||
assert(it != utxos.end()); | assert(it != utxos.end()); | ||||
// We need to delete that one. | // We need to delete that one. | ||||
if (it->second == peerid) { | if (it->second == peerid) { | ||||
utxos.erase(it); | utxos.erase(it); | ||||
} | } | ||||
} | } | ||||
m_conflicting_proofids.insert(proofid); | |||||
for (auto &cb : conflictingProofHandlers) { | for (auto &cb : conflictingProofHandlers) { | ||||
cb->onConflictingProof(proof, accepted); | cb->onConflictingProof(proof, accepted); | ||||
} | } | ||||
return peers.end(); | return peers.end(); | ||||
} | } | ||||
// We have no peer for this proof, time to create it. | // We have no peer for this proof, time to create it. | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |