diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -648,6 +648,7 @@ NodeId nodeid; ServiceFlags nServices; bool fRelayTxes; + bool fRelayProofs; int64_t nLastSend; int64_t nLastRecv; int64_t nLastTXTime; @@ -996,6 +997,20 @@ // m_tx_relay == nullptr if we're not relaying transactions with this peer std::unique_ptr m_tx_relay; + struct ProofRelay { + mutable RecursiveMutex cs_proof_inventory; + CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_proof_inventory){ + 50000, 0.000001}; + // Set of proof ids we still have to announce. + std::set setInventoryProofsToSend; + std::chrono::microseconds nNextInvSend{0}; + }; + + // m_proof_relay == nullptr if we're not relaying proofs with this peer + std::unique_ptr m_proof_relay; + + void InitProofRelay() { m_proof_relay = std::make_unique(); } + struct AvalancheState { AvalancheState() {} @@ -1171,6 +1186,23 @@ vBlockHashesToAnnounce.push_back(hash); } + void AddKnownProof(const avalanche::ProofId &proofid) { + if (m_proof_relay != nullptr) { + LOCK(m_proof_relay->cs_proof_inventory); + m_proof_relay->filterInventoryKnown.insert(proofid); + } + } + + void PushProofInventory(const avalanche::ProofId &proofid) { + if (m_proof_relay == nullptr) { + return; + } + LOCK(m_proof_relay->cs_proof_inventory); + if (!m_proof_relay->filterInventoryKnown.contains(proofid)) { + m_proof_relay->setInventoryProofsToSend.insert(proofid); + } + } + void CloseSocketDisconnect(); void copyStats(CNodeStats &stats, const std::vector &m_asmap); diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -548,6 +548,7 @@ } else { stats.fRelayTxes = false; } + stats.fRelayProofs = (m_proof_relay != nullptr); stats.nLastSend = nLastSend; stats.nLastRecv = nLastRecv; stats.nLastTXTime = nLastTXTime; diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2823,6 +2823,11 @@ pfrom.m_tx_relay->fRelayTxes = fRelay; } + if ((gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) && + (nServices & NODE_AVALANCHE)) { + pfrom.InitProofRelay(); + } + pfrom.nRemoteHostNonce = nNonce; pfrom.nRemoteExtraEntropy = nExtraEntropy;