Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip sending IWants based on received IDontWants #1109

Draft
wants to merge 1 commit into
base: p2p-research
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions libp2p/protocols/pubsub/gossipsub/behavior.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declareGauge(libp2p_gossipsub_low_peers_topics, "number of topics in mesh with a
declareGauge(libp2p_gossipsub_healthy_peers_topics, "number of topics in mesh with at least dlow peers (but below dhigh)")
declareCounter(libp2p_gossipsub_above_dhigh_condition, "number of above dhigh pruning branches ran", labels = ["topic"])
declareGauge(libp2p_gossipsub_received_iwants, "received iwants", labels = ["kind"])
declareCounter(libp2p_gossipsub_IWANT_Saves, "number of saved IWANTs based on received IDontWants")

proc grafted*(g: GossipSub, p: PubSubPeer, topic: string) =
g.withPeerStats(p.peerId) do (stats: var PeerStats):
Expand Down Expand Up @@ -249,14 +250,29 @@ proc handleIHave*(g: GossipSub,
trace "peer sent ihave",
peer, topicID = ihave.topicID, msgs = ihave.messageIDs
if ihave.topicID in g.topics:
#look here for receieved idontwants for the same message
var meshPeers: HashSet[PubSubPeer]
g.mesh.withValue(ihave.topicID, peers): meshPeers.incl(peers[])

for msgId in ihave.messageIDs:
if not g.hasSeen(g.salt(msgId)):
if peer.iHaveBudget <= 0:
break
elif msgId notin res.messageIDs:
res.messageIDs.add(msgId)
dec peer.iHaveBudget
trace "requested message via ihave", messageID=msgId
#dont send IWANT if we have received (N number of) IDontWant(s) for a msgID
let saltedID = g.salt(msgId)
var numFinds: int = 0
for meshPeer in meshPeers:
for heDontWant in meshPeer.heDontWants:
if saltedID in heDontWant:
numFinds = numFinds + 1
#break;
if numFinds > 0: #Or wait for N number of IDontWants
libp2p_gossipsub_IWANT_Saves.inc
else:
res.messageIDs.add(msgId)
dec peer.iHaveBudget
trace "requested message via ihave", messageID=msgId
# shuffling res.messageIDs before sending it out to increase the likelihood
# of getting an answer if the peer truncates the list due to internal size restrictions.
g.rng.shuffle(res.messageIDs)
Expand Down
Loading