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

Recipe about gossiping with other nodes over the network #420

Open
JoshOrndorff opened this issue Mar 25, 2021 · 1 comment
Open

Recipe about gossiping with other nodes over the network #420

JoshOrndorff opened this issue Mar 25, 2021 · 1 comment

Comments

@JoshOrndorff
Copy link
Owner

image

@nuke-web3
Copy link
Contributor

Hi, I have few question regarding gossip. I try to use sc_network_gossip::GossipEngine. I hope this is the right way to go.
Do we get the messages sent to us using Receiver returned by messages_for? How does this relate to the ImportQueue in case of gossiping blocks, though I would like to transmit other messages, too)? If I register a message with register_gossip_message and send it selectively to a single peer (using send_topic), does only the recipient receive it or other connected peers, too, after they poll the receiver of messages_for? How do I receive messages sent by send_message, where no topic is specified? Thank you.


I'd recommend to directly use the NetworkService in sc_network instead. It's more simple to use
Step 1: add an entry in NetworkConfiguration::extra_sets: https://docs.rs/sc-network/0.9.0/sc_network/config/struct.NetworkConfiguration.html#structfield.extra_sets
See example config for what we use for GrandPa: https://github.com/paritytech/substrate/blob/6ac86d545f6da8e4afc373dc0876c3e7ba79e51b/client/finality-grandpa/src/lib.rs#L690-L700
Step 2: call events_stream at initialization: https://docs.rs/sc-network/0.9.0/sc_network/struct.NetworkService.html#method.event_stream
Step 3: if you want to gossip to the same peers you're connected to for syncing (which is the easy option), call add_set_reserved and remove_set_reserved when you receive SyncConnected and SyncDisconnected (example)
Adding/removing reserved peers sets the list of peers to have an open gossiping channel with
Step 4: you will receive events whenever a gossiping channel is open or closed or a message received (https://docs.rs/sc-network/0.9.0/sc_network/enum.Event.html)
Step 5: use write_notification to send a message to someone: https://docs.rs/sc-network/0.9.0/sc_network/struct.NetworkService.html#method.write_notification
Step 7: profit

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

No branches or pull requests

2 participants