Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 308 Lines • ▼ Show 20 Lines | bool PeerManager::registerProof(const ProofRef &proof, | ||||
// New peer means new peerid! | // New peer means new peerid! | ||||
const PeerId peerid = nextPeerId++; | const PeerId peerid = nextPeerId++; | ||||
// 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, nextCooldownTimePoint); | auto inserted = peers.emplace(peerid, proof, nextCooldownTimePoint); | ||||
assert(inserted.second); | assert(inserted.second); | ||||
auto insertedRadixTree = | auto insertedRadixTree = | ||||
shareableProofs.insert(RCUPtr<ProofElement>::make(proof)); | shareableProofs.insert(RCUPtr<ProofTreeElement>::make(proof)); | ||||
assert(insertedRadixTree); | assert(insertedRadixTree); | ||||
RCULock::synchronize(); | RCULock::synchronize(); | ||||
// Add to our registered score when adding to the peer list | // Add to our registered score when adding to the peer list | ||||
totalPeersScore += proof->getScore(); | totalPeersScore += proof->getScore(); | ||||
// If there are nodes waiting for this proof, add them | // If there are nodes waiting for this proof, add them | ||||
auto &pendingNodesView = pendingNodes.get<by_proofid>(); | auto &pendingNodesView = pendingNodes.get<by_proofid>(); | ||||
▲ Show 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | bool PeerManager::verify() const { | ||||
// We checked the utxo consistency for all our peers utxos already, so if | // We checked the utxo consistency for all our peers utxos already, so if | ||||
// the pool size differs from the expected one there are dangling utxos. | // the pool size differs from the expected one there are dangling utxos. | ||||
if (validProofPool.size() != peersUtxos.size()) { | if (validProofPool.size() != peersUtxos.size()) { | ||||
return false; | return false; | ||||
} | } | ||||
// Check there is no dangling proof in the radix tree | // Check there is no dangling proof in the radix tree | ||||
bool danglingProofInRadixTree = false; | bool danglingProofInRadixTree = false; | ||||
shareableProofs.forEachLeaf([&](RCUPtr<ProofElement> pLeaf) { | shareableProofs.forEachLeaf([&](RCUPtr<ProofTreeElement> pLeaf) { | ||||
if (!isBoundToPeer(pLeaf->proof->getId())) { | if (!isBoundToPeer(pLeaf->proof->getId())) { | ||||
danglingProofInRadixTree = true; | danglingProofInRadixTree = true; | ||||
} | } | ||||
}); | }); | ||||
return !danglingProofInRadixTree; | return !danglingProofInRadixTree; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |