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

[GossipSub 1.2] Add IDONTWANT support #374

Merged
merged 20 commits into from
Sep 25, 2024

Conversation

StefanBratanov
Copy link
Collaborator

TODO:

  • Add topics or message size threshold for sending IDONTWANT
  • Add tests

fixes #371

@@ -122,6 +122,7 @@ open class GossipRouter(
private val iAsked = createLRUMap<PeerHandler, AtomicInteger>(MaxIAskedEntries)
private val peerIHave = createLRUMap<PeerHandler, AtomicInteger>(MaxPeerIHaveEntries)
private val iWantRequests = createLRUMap<Pair<PeerHandler, MessageId>, Long>(MaxIWantRequestsEntries)
private val peerIDontWant = createLRUMap<PeerHandler, Pair<AtomicInteger, MutableSet<MessageId>>>(MaxPeerIDontWantEntries)
Copy link
Collaborator

Choose a reason for hiding this comment

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

May we have an explicit structure for Pair<AtomicInteger, MutableSet<MessageId>> for clarity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added IDontWantCacheEntry

@@ -572,9 +590,14 @@ open class GossipRouter(
enqueueIwant(peer, messageIds)
}

private fun iDontWant(peer: PeerHandler, messageIds: List<MessageId>) {
if (messageIds.isEmpty()) return
enqueueIdontwant(peer, messageIds)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understand you are going to add the filtering here yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

@@ -572,9 +590,14 @@ open class GossipRouter(
enqueueIwant(peer, messageIds)
}

private fun iDontWant(peer: PeerHandler, messageIds: List<MessageId>) {
if (messageIds.isEmpty()) return
enqueueIdontwant(peer, messageIds)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe it's worth to add self rate limiting here as well ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or probably it doesn't make much sense if this is not penalized

@@ -572,9 +590,14 @@ open class GossipRouter(
enqueueIwant(peer, messageIds)
}

private fun iDontWant(peer: PeerHandler, messageIds: List<MessageId>) {
if (messageIds.isEmpty()) return
enqueueIdontwant(peer, messageIds)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The thing of IDONTWANT is that it needs to be flushed immediately to have the effect

@@ -459,6 +475,8 @@ open class GossipRouter(
.whenTrue { notifyIWantTimeout(key.first, key.second) }
}

peerIDontWant.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may clear remote IDONTWANT which is still in effect here. We probably need some more sophisticated pruning mechanism here

/**
* [maxIDontWantMessages] is the maximum number of IDONTWANT messages per heartbeat per peer
*/
val maxIDontWantMessages: Int = 10
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe it's pretty low default which may mitigate the whole purpose of IDONTWANT.
I would default it to maxIHaveLength * maxIHaveMessages as proposed here

This one would be pretty high but any client may make it more conservative if needed.

With respect to Ethereum PeerDAS we may legally have up to 128 messages in a single slot for data column subnets

Copy link
Collaborator

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

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

LGTM
Just some neets. Unit tests are very appretiated as well.

@StefanBratanov StefanBratanov marked this pull request as ready for review September 25, 2024 12:55
if (!this.protocol.supportsIDontWant()) return
if (msg.protobufMessage.data.size() < params.iDontWantMinMessageSizeThreshold) return
// we need to send IDONTWANT messages to mesh peers immediately in order for them to have an effect
msg.topics.forEach { topic ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there are more than 1 topic wouldn't we send duplicate messageId to same peers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah that is a good point, fixed in bbe42fa

Copy link
Collaborator

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

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

LGTM

@StefanBratanov StefanBratanov enabled auto-merge (squash) September 25, 2024 15:27
@StefanBratanov StefanBratanov merged commit e9e1d33 into libp2p:develop Sep 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement gossipsub IDONTWANT
2 participants