gossipsub: Topic Streams Extension - #729
Conversation
| When this extension is negotiated, the original gossipsub stream becomes the | ||
| control stream. Application messages (such as the `Message` or | ||
| `PartialMessagesExtension` messages) MUST NOT be published on the control | ||
| stream. |
There was a problem hiding this comment.
What do you think about a design where we have per topic control streams too?
So the control stream would share the topic relevant: IHave, IWant, IDontWant, and maybe Graft and Prune
This allows:
Easier implementation. Need to read a control scoped RPC.
Heartbeat can now be per topic and be staggered by having different topics at different times, and also more frequent for some topics.
Less HOL Blocking when sharing IHave, IWant, IDontWant
And mostly the fact that there really isn't any reason that control messages for a topic should interleave with control messages of another topic.
Similarly What do you think about?
1 topic control stream as defined above
1 topic data stream per message.
With this design we get nice cancellation properties. So we can cancel in progress sends easily. And if we add message preambles / ids before sending messages we can also reset on the receive side.
There was a problem hiding this comment.
Discussed synchronously. Resolved that theoretically 1 topic control stream would be better, the actual utility doesn't justify its implementation complexity. Decided to leave as is.
| If there are multiple streams for a single topic, the receiver SHOULD process | ||
| them in the order the streams were opened by the initiator. The receiver | ||
| SHOULD limit the number of concurrent topic streams for the same topic to 3 and | ||
| downscore peers that open more. Initiators SHOULD limit the number of | ||
| concurrent topic streams to 1 per topic. The initiator MUST close the old | ||
| stream before writing on a new stream for a given topic. |
There was a problem hiding this comment.
it's a bit confusing, why would there be 3 streams?
Is this because of subscribe, unsubscribe, subscribe, unsubscribe kind of pattern?
There was a problem hiding this comment.
right, or if the implementation opens a new stream per message. Because there is a potential for packets to be reordered or delayed, the sender should avoid concurrent streams that could appear to the receiver as multiple concurrent streams open at the same time.
Add a Shadow scenario that publishes a 1MiB message then a 1KiB message on different topics, and a log-timestamp check that the small message is not head-of-line blocked. Wire the go binary to the topic-streams pubsub fork (libp2p/specs#729) with WithTopicStreams enabled.
| If a receiver receives a message from a peer that violates a MUST condition, | ||
| the receiver MUST reset the connection to the peer and send error code | ||
| `0xd52505` when the transport allows it. This code signifies a Topic Streams |
There was a problem hiding this comment.
the message violates the condition, no? not the peer
| If a receiver receives a message from a peer that violates a MUST condition, | |
| the receiver MUST reset the connection to the peer and send error code | |
| `0xd52505` when the transport allows it. This code signifies a Topic Streams | |
| If a peer receives a message that violates a MUST condition, | |
| the receiver MUST reset the connection to the peer and send error code | |
| `0xd52505` when the transport allows it. This code signifies a Topic Streams |
| Protocol Violation error, and is derived from the first 3 bytes of the sha256 | ||
| hashsum of the string `gossipsub-topic-streams`. (i.e. `echo -n | ||
| "gossipsub-topic-streams" | sha256sum | head -c 6`) |
There was a problem hiding this comment.
Is this usual for specs to do? Otherwise, I see no point to explain where it comes from (maybe for curiosity in an appendix?
|
|
||
| ## Topic Streams | ||
|
|
||
| A peer opens a bidirectional stream for each topic that it wishes to send |
There was a problem hiding this comment.
| A peer opens a bidirectional stream for each topic that it wishes to send | |
| A peer MUST open a bidirectional stream for each topic that it wishes to send |
| The responder of the bidirectional stream MUST NOT write on the stream after | ||
| protocol negotiation completes. |
There was a problem hiding this comment.
So it is only bidirectional to accomodate the initial handshake? If so this should be stated explicitly
|
|
||
| If there are multiple streams for a single topic, the receiver SHOULD process | ||
| them in the order the streams were opened by the initiator. The receiver | ||
| SHOULD limit the number of concurrent topic streams for the same topic to 3 and |
There was a problem hiding this comment.
I wonder if it'd be better to use variables here for this, as well as the stream reset timeout or other constants, and then add a table below with recommended default values for these.
| downscore peers that open more. Initiators SHOULD limit the number of | ||
| concurrent topic streams to 1 per topic. The initiator MUST close the old |
There was a problem hiding this comment.
Initiators SHOULD limit the number of concurrent topic streams to 1 per topic
Should we include an explanation about what to do when there are multiple concurrent topic streams for a single topic? Because I can't see how that would work exactly. If it makes no sense whatsoever, then maybe we can change that SHOULD to a MUST?
| If the receiver receives a topic stream for a topic it is not subscribed to and | ||
| has not recently published partial messages to (via fanout), it SHOULD | ||
| downscore the peer. The receiver MUST NOT downscore a peer for opening a topic |
There was a problem hiding this comment.
it SHOULD downscore the peer
Is this true for other spec violations here as well? Maybe we should include this sentence in other places as well
| downscore the peer. The receiver MUST NOT downscore a peer for opening a topic | ||
| stream for a topic the receiver recently unsubscribed from, as the peer may not | ||
| have received the unsubscribe message before opening the topic stream. |
There was a problem hiding this comment.
nit
| downscore the peer. The receiver MUST NOT downscore a peer for opening a topic | |
| stream for a topic the receiver recently unsubscribed from, as the peer may not | |
| have received the unsubscribe message before opening the topic stream. | |
| downscore the peer. | |
| **Note:** The receiver MUST NOT downscore a peer for opening a topic | |
| stream for a topic the receiver recently unsubscribed from, as the peer may not | |
| have received the unsubscribe message before opening the topic stream. |
| When a peer wishes to publish a message, it MUST publish a `TopicScopedMessage` | ||
| and it MUST NOT publish a message on the control stream. |
There was a problem hiding this comment.
This got me thinking... how does a peer know that a message is not a control message? Apologies if I'm missing important gossipsub-related information about this.
| If the partial message extension has been negotiated with this extension, peers | ||
| MUST send each other Partial Messages on the topic stream, not the control | ||
| stream. |
There was a problem hiding this comment.
nit
| If the partial message extension has been negotiated with this extension, peers | |
| MUST send each other Partial Messages on the topic stream, not the control | |
| stream. | |
| If the partial message extension has been negotiated with this extension, peers | |
| MUST send each other Partial Messages on the topic stream. | |
| Peers MUST NOT send Partial Messages on the control stream. |
| `TopicRPC` messages MUST NOT be empty. They MUST contain either a partial or | ||
| publish message. The data length of the application message MUST be non zero. |
There was a problem hiding this comment.
The data length of the application message MUST be non zero
Is this restriction mandatory? because pubsub does allow empty data.
https://github.com/libp2p/specs/blob/master/pubsub/README.md#the-message
| not publish messages to a peer before learning of its subscriptions, there is | ||
| no window when a publisher wishes to publish a message, but does not know if | ||
| the peer supports Topic Streams. |
There was a problem hiding this comment.
What to do in case of races?: Assuming you have to peers (A and B) the following can happen (specially in quic):
AandBwritetopicStreams=trueon their gossip streamsAreceivesB's extension advertisement soAknows that both sides support the extensionsAopens/gsts/v0beta- But, because the streams are muxed independently,
Bcan receive the topic stream before it readAextension advertisement, - Then in that moment
Bknows it support topic streams, however it still does not know thatAsupports it.
Should A open the stream ONLY after receiving the extension advertisement from B? or should B assume A opening a stream for /gsts/v0beta is proof enough that A supports topic streams?
| A topic stream is created when a node publishes a topic message to a peer. It is | ||
| closed when either the peer unsubscribes from the topic, or the publisher will | ||
| no longer publish on the topic. Either side may close the stream. |
There was a problem hiding this comment.
| A topic stream is created when a node publishes a topic message to a peer. It is | |
| closed when either the peer unsubscribes from the topic, or the publisher will | |
| no longer publish on the topic. Either side may close the stream. | |
| A topic stream is created when a node publishes a topic message to a peer. It is | |
| closed when the peer unsubscribes or the sender no longer intends to send | |
| messages on that topic. Either side may close the stream. |
| // Included for computing signatures, not used on the wire | ||
| optional string unset_topic_name = 4; |
There was a problem hiding this comment.
Should this use
https://protobuf.dev/programming-guides/proto3/#reserved ?
| // Included for computing signatures, not used on the wire | |
| optional string unset_topic_name = 4; | |
| // Included for computing signatures, not used on the wire | |
| reserved 4; |
| If there are multiple streams for a single topic, the receiver SHOULD process | ||
| them in the order the streams were opened by the initiator. The receiver | ||
| SHOULD limit the number of concurrent topic streams for the same topic to 3 and | ||
| downscore peers that open more. Initiators SHOULD limit the number of |
There was a problem hiding this comment.
What happens with streams that are opened after the limit is reached? are they reset?
Gossipsub v1.3 uses a single stream per direction for all RPCs. This introduces some problems: unnecessary head of line blocking between messages (especially problematic when a large message in one topic delays small messages in another topic) and topic name overhead on each message.
The Topic Streams Extension addresses these problems. It moves topic scoped application messages to separate long-lived streams.