MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / FindProofForGetData

Method FindProofForGetData

src/net_processing.cpp:3542–3584  ·  view source on GitHub ↗

Determine whether or not a peer can request a proof, and return it (or nullptr if not found or not allowed).

Source from the content-addressed store, hash-verified

3540//! Determine whether or not a peer can request a proof, and return it (or
3541//! nullptr if not found or not allowed).
3542avalanche::ProofRef
3543PeerManagerImpl::FindProofForGetData(const Peer &peer,
3544 const avalanche::ProofId &proofid,
3545 const std::chrono::seconds now) {
3546 avalanche::ProofRef proof;
3547
3548 bool send_unconditionally =
3549 m_avalanche->withPeerManager([&](const avalanche::PeerManager &pm) {
3550 return pm.forPeer(proofid, [&](const avalanche::Peer &peer) {
3551 proof = peer.proof;
3552
3553 // If we know that proof for long enough, allow for requesting
3554 // it.
3555 return peer.registration_time <=
3556 now - UNCONDITIONAL_RELAY_DELAY;
3557 });
3558 });
3559
3560 if (!proof) {
3561 // Always send our local proof if it gets requested, assuming it's
3562 // valid. This will make it easier to bind with peers upon startup where
3563 // the status of our proof is unknown pending for a block. Note that it
3564 // still needs to have been announced first (presumably via an avahello
3565 // message).
3566 proof = m_avalanche->getLocalProof();
3567 }
3568
3569 // We don't have this proof
3570 if (!proof) {
3571 return avalanche::ProofRef();
3572 }
3573
3574 if (send_unconditionally) {
3575 return proof;
3576 }
3577
3578 // Otherwise, the proofs must have been announced recently.
3579 if (peer.m_proof_relay->m_recently_announced_proofs.contains(proofid)) {
3580 return proof;
3581 }
3582
3583 return avalanche::ProofRef();
3584}
3585
3586void PeerManagerImpl::ProcessGetData(
3587 const Config &config, CNode &pfrom, Peer &peer,

Callers

nothing calls this directly

Calls 3

forPeerMethod · 0.80
getLocalProofMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected