Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | PeerManager::fetchOrCreatePeer(const std::shared_ptr<Proof> &proof) { | ||||
orphanProofs.removeProof(proofid); | orphanProofs.removeProof(proofid); | ||||
// New peer means new peerid! | // New peer means new peerid! | ||||
const PeerId peerid = nextPeerId++; | const PeerId peerid = nextPeerId++; | ||||
// Attach UTXOs to this proof. | // Attach UTXOs to this proof. | ||||
std::unordered_set<PeerId> conflicting_peerids; | std::unordered_set<PeerId> conflicting_peerids; | ||||
bool accepted = true; | |||||
deadalnix: This is computed but not used anywhere. | |||||
for (const auto &s : proof->getStakes()) { | for (const auto &s : proof->getStakes()) { | ||||
auto p = utxos.emplace(s.getStake().getUTXO(), peerid); | auto p = utxos.emplace(s.getStake().getUTXO(), peerid); | ||||
if (!p.second) { | if (!p.second) { | ||||
// We have a collision with an existing proof. | // We have a collision with an existing proof. | ||||
conflicting_peerids.insert(p.first->second); | conflicting_peerids.insert(p.first->second); | ||||
accepted &= forPeer(p.first->second, [&](const Peer &peer) { | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis seems wasteful to compute all of this when none of it matters when accepted is false. deadalnix: This seems wasteful to compute all of this when none of it matters when accepted is false. | |||||
if (proof->getSequence() > peer.proof->getSequence()) { | |||||
return true; | |||||
} | |||||
return false; | |||||
deadalnixUnsubmitted Not Done Inline ActionsEl famoso if (condition) return true; retrun false; What about that instead? return condition; deadalnix: El famoso
if (condition) return true;
retrun false;
What about that instead? | |||||
}); | |||||
} | } | ||||
} | } | ||||
// For now, if there is a conflict, just cleanup the mess. | // For now, if there is a conflict, just cleanup the mess. | ||||
if (conflicting_peerids.size() > 0) { | if (conflicting_peerids.size() > 0) { | ||||
for (const auto &s : proof->getStakes()) { | for (const auto &s : proof->getStakes()) { | ||||
auto it = utxos.find(s.getStake().getUTXO()); | auto it = utxos.find(s.getStake().getUTXO()); | ||||
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); | ||||
} | } | ||||
} | } | ||||
conflicting_proofs.getWriteView()->emplace(proof, VoteRecord(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. | ||||
auto inserted = peers.emplace(peerid, proof); | auto inserted = peers.emplace(peerid, proof); | ||||
assert(inserted.second); | assert(inserted.second); | ||||
// If there are nodes waiting for this proof, add them | // If there are nodes waiting for this proof, add them | ||||
▲ Show 20 Lines • Show All 234 Lines • ▼ Show 20 Lines | if (getProof(proofid)) { | ||||
m_unbroadcast_proofids.insert(proofid); | m_unbroadcast_proofids.insert(proofid); | ||||
} | } | ||||
} | } | ||||
void PeerManager::removeUnbroadcastProof(const ProofId &proofid) { | void PeerManager::removeUnbroadcastProof(const ProofId &proofid) { | ||||
m_unbroadcast_proofids.erase(proofid); | m_unbroadcast_proofids.erase(proofid); | ||||
} | } | ||||
bool PeerManager::ProofSharedPointerComparator::operator()( | |||||
const std::shared_ptr<Proof> &lhs, | |||||
const std::shared_ptr<Proof> &rhs) const { | |||||
uint32_t scoreLhs = lhs->getScore(); | |||||
uint32_t scoreRhs = rhs->getScore(); | |||||
if (scoreLhs != scoreRhs) { | |||||
return scoreLhs > scoreRhs; | |||||
} | |||||
return lhs->getId() < rhs->getId(); | |||||
} | |||||
} // namespace avalanche | } // namespace avalanche |
This is computed but not used anywhere.