Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 450 Lines • ▼ Show 20 Lines | std::vector<NodeId> PeerManager::getNodeIdsForPeer(PeerId peerId) const { | ||||
auto &nview = nodes.get<next_request_time>(); | auto &nview = nodes.get<next_request_time>(); | ||||
auto nodeRange = nview.equal_range(peerId); | auto nodeRange = nview.equal_range(peerId); | ||||
for (auto it = nodeRange.first; it != nodeRange.second; ++it) { | for (auto it = nodeRange.first; it != nodeRange.second; ++it) { | ||||
nodeids.emplace_back(it->nodeid); | nodeids.emplace_back(it->nodeid); | ||||
} | } | ||||
return nodeids; | return nodeids; | ||||
} | } | ||||
const Proof *PeerManager::getProof(const ProofId proofId) const { | |||||
auto &peerView = peers.get<proof_index>(); | |||||
auto peerIt = peerView.find(proofId); | |||||
if (peerIt != peerView.end()) { | |||||
return &peerIt->proof; | |||||
} | |||||
auto proofIt = orphanProofs.find(proofId); | |||||
if (proofIt != orphanProofs.end()) { | |||||
return &proofIt->second; | |||||
} | |||||
return nullptr; | |||||
} | |||||
bool PeerManager::addProof(Proof &&proof) { | |||||
ProofValidationState state; | |||||
const CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | |||||
bool success = proof.verify(state, coins); | |||||
if (success) { | |||||
// Good proof, store the proof in a new peer | |||||
return fetchOrCreatePeer(proof) != peers.end(); | |||||
} | |||||
if (state.GetResult() == ProofValidationResult::MISSING_UTXO) { | |||||
// Maybe it can become valid later | |||||
return orphanProofs | |||||
.insert(std::make_pair(proof.getId(), std::move(proof))) | |||||
.second; | |||||
} | |||||
return false; | |||||
} | |||||
} // namespace avalanche | } // namespace avalanche |