I'm interested to understand how to use sc-network-gossip's GossipEngine to receive P2P messages, not just gossip messages. The motivation is that I would like to send specific peers specific messages rather than gossiping all messages to all peers. So far, I haven't found examples for doing so and so am posting here.

Example of gossiping

The BEEFY client receives gossip messages over its provided topic using the following snippet:

let mut votes = Box::pin(self.gossip_engine.lock().messages_for(topic::<B>()).filter_map(
    |notification| async move {
        trace!(target: "beefy", "🥩 Got vote message: {:?}", notification);

        VoteMessage::<NumberFor<B>, AuthorityId, Signature>::decode(
            &mut &notification.message[..],

The messages are sent using:

self.gossip_engine.lock().gossip_message(topic::<B>(), encoded_message, false);


The GossipEngine API supports this method and another send_message


It is clear where messages received over a given topic are able to be processed and consumed using examples from BEEFY. However, it is unclear how to consume messages that are sent P2P using send_message.

  1. If we send a message to a peer, how does one receive it and process it.
  2. Assuming the message is simply sent without a topic, what structs would I need to access?
  • As far as I know, part of the idea behind gossip is to avoid sending direct messages so that a relationship between the sender and the receiver cannot be established. Sending a direct message to a peer would identify this relationship and therefore break the anonymity of the protocol. That said, the docs state that Consensus code can invoke ... send_topic to send all messages under a single topic to a specific peer. Source
    – forgetso
    May 3, 2022 at 15:40
  • Anonymity of what protocol? I'm intentionally trying to send a target an encrypted piece of data that only they're able to decrypt. If I gossip it, then I am creating an unnecessary amount of outbound traffic. We are currently gossiping it and trying to reduce our outbound bandwidth, since ours continues to climb through our specific protocol implementation. Sending directly would at least be an improvement on that.
    – Drew Stone
    May 3, 2022 at 19:04
  • Did you found out how to receive such messages ?
    – dadzerlaze
    Jan 18 at 13:00
  • sc_network_gossip is deprecated
    – dadzerlaze
    Apr 17 at 17:35
  • Yes, we have been hard at work on custom protocols over Substrate. You can find a lot of work in: github.com/webb-tools/dkg-substrate @dadzerlaze
    – Drew Stone
    Jun 2 at 4:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.