Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@tomaka
Copy link
Contributor

@tomaka tomaka commented Dec 3, 2019

Extracted from #4125

This extracts consensus_gossip.rs from the networking crate and puts it in its own crate.

In details:

  • Removes consensus_gossip.rs from the network, as well as the gossiping-related methods: with_gossip and gossip_consensus_message.
  • Instead, you can register a gossiping protocol using register_notifications_protocol. Call event_stream in order to obtain a stream of the events that happen on the network. Call write_notifications in order to send a message to a peer we're connected to.
  • The NetworkService no longer returns events and is now a Future again. Everything is done through event_stream.
  • The abstraction level of finality_grandpa::Network has changed to be lower-level. It's GrandPa that sets up the gossiping system.
  • Adds a new executor parameter to GrandpaParams and to run_grandpa_observer, which must implement the futures::task::Spawn trait and that is used to spawn GrandPa's background tasks. This trait has been implemented on service::SpawnTaskHandler, so that it's the service that spawns GrandPa's tasks (which is also something we've been willing to do for a while).

Note: the Polkadot PR is not ready. I'll work on it while this gets reviewed.

@tomaka tomaka added the A0-please_review Pull request needs code review. label Dec 3, 2019
@tomaka tomaka requested review from mxinden and rphmeier December 3, 2019 14:29
/// handle to a gossip service or similar.
///
/// Intended to be a lightweight handle such as an `Arc`.
pub trait Network<Block: BlockT>: Clone + Send + 'static {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't mind something like this going into consensus-common either - where we can focus on the properties a network needs to provide to a consensus engine.

while let Some(Ok(event)) = stream.next().await {
match event {
Event::NotifOpened { remote, engine_id: msg_engine_id } => {
if msg_engine_id != engine_id {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't get why it's necessary to echo the engine ID in the notifications. shouldn't it be implicit from context?

Copy link
Contributor Author

@tomaka tomaka Dec 4, 2019

Choose a reason for hiding this comment

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

We get events from all the registered protocols, not just ours. The event stream is global to the network. It is not filtered.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, that's kind of strange. why do we get events from all subprotocols?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's any real drawback in doing so, except that we duplicate all messages once event stream (which is why the message itself is a Bytes, which is kind of an Arc<Vec<u8>>, rather than just a Vec<u8>).

I did that in order to not inflict ourself any artificial constraint later, for example if you want the same code to register two different protocols, or if you want to know whether the node you're talking to also has a substream to a different specific protocol open.

And it's also easier to implement this way.

@mxinden
Copy link
Contributor

mxinden commented Dec 6, 2019

Let us know once this is ready for another review @tomaka.

@tomaka
Copy link
Contributor Author

tomaka commented Dec 6, 2019

This is ready. All tests are passing and documentation has been written.

The corresponding Polkadot PR still needs to be written, though.

Copy link
Contributor

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

This looks good to me apart from the somewhat minor open comments above. Were you able to test this out on a small network @tomaka?

@tomaka
Copy link
Contributor Author

tomaka commented Dec 9, 2019

Small update: Polkadot PR almost ready, I just have to fix a tests module.


let validator = Arc::new(validator);
service.register_validator(validator.clone());
let gossip_engine = GossipEngine::new(gossip_engine, executor, GRANDPA_ENGINE_ID, validator.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

My previous comment might not have been very clear. I meant to rename the left side of the equation. Now one creates a GossipEngine with a gossip_engine as an argument. The latter should be a network or a service, no?

@tomaka
Copy link
Contributor Author

tomaka commented Dec 10, 2019

Polkadot PR now ready: paritytech/polkadot#680

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

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants