-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Use sc_network::NetworkStateInfo instead of implementing redundant traits
#4436
Conversation
sc_network::NetworkStateInfo instead of implementing redundant traits
tomusdrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just the preamble is missing in newly created file.
| @@ -0,0 +1,367 @@ | |||
| use std::sync::{Arc, Mutex}; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs preamble. Why move the tests in the first place though? It's a common convention to just have an inline module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides less cognitive load, it'll be easier for me to format the code with rustfmt in a separate file :)
| use libp2p::Multiaddr; | ||
| use sc_network::specialization::NetworkSpecialization; | ||
| use sc_network::{DhtEvent, ExHashT}; | ||
| use sc_network::{DhtEvent, ExHashT, NetworkStateInfo}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like these things (trait + primitives) should rather be moved to primitves, but it's a separate discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check #4450
this made the build fail |
mxinden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of smaller comments. Thanks for the refactoring!
I would prefer the CI fix to get into master in a separate pull request given that it is not related to this change set.
| where | ||
| Block: BlockT + 'static, | ||
| Network: NetworkProvider, | ||
| Network: NetworkProvider + NetworkStateInfo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding + NetworkStateInfo here and below, why not do the following?
pub trait NetworkProvider: NetworkStateInfo {One could read this as: The authority discovery module needs something that provides access to a network with the following functions and everything that NetworkStateInfo offers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it. But actually we already have put_value and get_value in trait Behaviour, there's still some place to improve here.
|
|
||
| impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkService<B, S, H> { | ||
| /// Returns the network identity of the node. | ||
| pub fn local_peer_id(&self) -> PeerId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidating NetworkService with NetworkStateInfo sounds good to me. Great catch. Polkadot might be using NetworkService::local_peer_id, but I guess it could just use NetworkStateInfo as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can even do better. I already addressed this in #4450
|
About the ci fix, since it's very simple and there should exist more specific solution to it, I'd like to get it merged in this pr and try fixing it in another way later. The problem is rather subtle and urgent - it'll block everyone until it gets fixed. |
… gossip-local-peer-id
… gossip-local-peer-id
tomusdrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
mxinden
left a comment
There was a problem hiding this 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. The patch set includes a bunch of (unrelated) changes to Cargo.lock. How do we usually proceed in this regard @tomusdrw?
|
fixed |
ref #4439