Skip to content

Conversation

@ufarooqstatus
Copy link
Collaborator

We use message preamble to detect incoming messages. This information is used to:

  • Announce the messages we are receiving to full-message mesh using IMReceiving messages.
  • Make IWANT requests only if we are not already receiving the same message
  • Limit outstanding IWANT requests for a message to 1
  • Stagger (only add small delay) mesh transmissions

PoC implementation for shadow simulation. Not intended for merging
Reduces duplicates to less than 1.5 for large messages

More details here

@github-actions
Copy link
Contributor

Pull requests titles must follow the Conventional Commits specification

@github-actions
Copy link
Contributor

Commits must follow the Conventional Commits specification
Please fix these commit messages:

some coments added
preamble added in IWANT replies also
topicID added in preamble
sem is one (sequential send in staggering)
Added control preamble, and staggering. Still need to add preamble for iwants
stagger send during publish and validateAndRelay. Still need to add timeouts
staggering added in message relay, still need to adjust timeouts
corrected dup_during_validation count
Merge branch 'master' into lma_merge_imreceiving_iwant_1 updating local branch
we make only one iwant request
set num_finds to 1
imreceiving handling merged with iwant optimization
IMReceiving message added
stats places, warmup messages added

@ufarooqstatus ufarooqstatus marked this pull request as draft January 10, 2025 12:47
Copy link
Member

@richard-ramos richard-ramos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting PR!

Is this PR also implementing this part of the spec?:

if the message ID is found in the ongoing_receives list,
the peer should postpone sending the IWANT request for a defer_interval.
The defer_interval may be based on the message download time.

g.handler = handler
g.codecs &= GossipSubCodec_12
g.codecs &= GossipSubCodec_11
g.codecs &= GossipSubCodec_10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this change result in a GossipSubCodec_14 as described in libp2p/specs#654 ?

g.mcache.put(msgId, msg)

g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ ?

Suggested change
#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)

#g.broadcast(peers, RPCMsg(messages: @[msg]), isHighPriority = true)
let sem = newAsyncSemaphore(1)
var staggerPeers = toSeq(peers)
g.rng.shuffle(staggerPeers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the peers randomly sorted?

Comment on lines +881 to +894
#We send message immediately after sending preamble to each peer
proc sendToOne(p: PubSubPeer) {.async.} =
g.broadcast(@[p], RPCMsg(control: some(ControlMessage(
preamble: @[ControlIHave(topicID: topic, messageIDs: @[msgId])]
))), isHighPriority = true)

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)

for p in staggerPeers:
asyncSpawn sendToOne(p)

Copy link
Member

@richard-ramos richard-ramos Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the AsyncSemaphore(1) means that the preambles are being sent sequentially to each peer, right? Why is this the case? Shouldn't we try to get the preamble messages being sent concurrently to all peers?

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No isHighPriority = true?

Comment on lines +386 to +393
return result
continue
let msg = g.mcache.get(mid).valueOr:
libp2p_gossipsub_received_iwants.inc(1, labelValues = ["unknown"])
continue
libp2p_gossipsub_received_iwants.inc(1, labelValues = ["correct"])
messages.add(msg)
return messages
result.messages.add(msg)
result.ids.add(mid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to define a messages and ids variables, instead of using result. See https://status-im.github.io/nim-style-guide/language.result.html

Comment on lines +362 to +363
if peer.heIsReceivings[^1].len > 1000: break
if messageId.len > 100: continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do messageIds exceed 100? I'm wondering if this condition should be added in other places as i haven't seen length checking for messageIds using 100. (Probably a good idea to extract this into a constant too)

Comment on lines +66 to +67
preamble*: seq[ControlIHave]
imreceiving*: seq[ControlIWant]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these have their own type? ControlPreamble and ControlImReceiving?

#We send message immediately after sending preamble to each peer
proc sendToOne(p: PubSubPeer) {.async.} =
g.broadcast(@[p], RPCMsg(control: some(ControlMessage(
preamble: @[ControlIHave(topicID: topic, messageIDs: @[msgId])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending the message length is still pending, right?

await sem.acquire()
defer: sem.release()

g.broadcast(@[p], RPCMsg(messages: @[msg]), isHighPriority = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading in the specs, I see the following:

Adding a message preamble may increase control overhead for small messages.
Therefore, it is preferable to use it only for messages that exceed the preamble_threshold.

The way it is coded right now, it will send the preamble always, right? Is this because this PR is for experiments?

@richard-ramos
Copy link
Member

@ufarooqstatus should this PR be kept open? or can it be closed

@ufarooqstatus
Copy link
Collaborator Author

@ufarooqstatus should this PR be kept open? or can it be closed

yes, it can be closed. it was an early PoC for v1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Experimental

Development

Successfully merging this pull request may close these issues.

3 participants