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

Comments

Minor refactor for peer sets in Polkadot#2220

Closed
eskimor wants to merge 3 commits intotka-companion-rm-prio-groupsfrom
rk-minor-refactor
Closed

Minor refactor for peer sets in Polkadot#2220
eskimor wants to merge 3 commits intotka-companion-rm-prio-groupsfrom
rk-minor-refactor

Conversation

@eskimor
Copy link
Member

@eskimor eskimor commented Jan 7, 2021

By having everything peer set related depend directly on the PeerSet enum the
code becomes more clear and it is also straight forward to add more
peersets/protocols as the compiler will complain if you forget to
implement parts of it.

  • some doc fixes and additional docs

@eskimor eskimor added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jan 7, 2021
@eskimor
Copy link
Member Author

eskimor commented Jan 7, 2021

Note, as I am basing my work on #2095 - this PR targets the branch of #2095, that is: tka-companion-rm-prio-groups.

/// Convert a peer set into a protocol name as understood by Substrate.
///
/// With `ProtocolName` being a proper newtype we could use the `Into` trait here.
pub fn into_protocol_name(self) -> ProtocolName {
Copy link

@ordian ordian Jan 7, 2021

Choose a reason for hiding this comment

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

why not impl From<PeerSet> for ProtocolName?

Ah, should have read the docs first 🤦

Copy link

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely, but I do not think it is valuable to have it for the generic Cow type. In that case I think a special method like into_protocol_name would be preferable.

into() ... with type signature PeerSet -> ProtocolName is pretty self explanatory, not so much with PeerSet -> Cow<'static, str>, therefore I opted for a more descriptive name.

///
/// Should be used during network configuration (added to [`NetworkConfiguration::extra_sets`])
/// or shortly after startup to register the protocols with the network service.
pub fn peer_set_infos() -> Vec<sc_network::config::NonDefaultSetConfig> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn peer_set_infos() -> Vec<sc_network::config::NonDefaultSetConfig> {
pub fn peer_set_info() -> Vec<sc_network::config::NonDefaultSetConfig> {

Nit: "information" is inherently plural; "infos" sounds weird.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair :-) Ok I will go with peer_sets_info then.


/// Protocol name as understood in substrate.
///
/// Ideally this would be defined in substrate as a newtype.
Copy link
Member Author

Choose a reason for hiding this comment

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

Making the newtype would be a trivial but a pervasive change in substrate, likely not worth it, as being in substrate, it would also break code for other users. Type safety gains are probably low, as we are not using Cow<'static,str> much.

Just putting this out there to see what people think.

@eskimor eskimor force-pushed the rk-minor-refactor branch from 490d838 to 0c96592 Compare January 7, 2021 09:11
@ordian ordian requested a review from tomaka January 7, 2021 09:15
@eskimor
Copy link
Member Author

eskimor commented Jan 7, 2021

All fixed. @tomaka do you want to merge this?

@tomaka
Copy link
Contributor

tomaka commented Jan 7, 2021

I don't have any strong opinion in favour or against this

@eskimor
Copy link
Member Author

eskimor commented Jan 7, 2021

I don't have any strong opinion in favour or against this

Also always interested in weak opinions ;-) Anyhow, those changes (and the ones to come) makes addition of new protocols a bit easier and more straight forward.

By having everything peer set related depend directly on the enum the
code becomes more clear and it is also straight forward to add more
peersets/protocols as the compiler will complain if you forget to
implement parts of it.
For feature real_overseer.

+ Fixes from review. Thanks @coriolinus and @ordian!
@eskimor eskimor force-pushed the rk-minor-refactor branch from 0c96592 to 86453f0 Compare January 7, 2021 11:24
@tomaka
Copy link
Contributor

tomaka commented Jan 7, 2021

Did you compile the whole Polkadot with this? I see that PeerSet isn't re-exported, which should trigger a compilation error.
I'd rather not merge the PR if it starts breaking my PR.

Also, I'd argue to do this after #2095 is merged. #2095 intentionally doesn't change anything (or rather, changes as little as possible) compared to master.

@eskimor
Copy link
Member Author

eskimor commented Jan 7, 2021

I did compile all of Polkadot with --all-features with those changes. But delaying this until #2095 is merged is totally fine with me.
checking this re-export issue right now

@eskimor
Copy link
Member Author

eskimor commented Jan 7, 2021

Will be superseded by PR against master.

@eskimor eskimor closed this Jan 7, 2021
@eskimor eskimor deleted the rk-minor-refactor branch January 13, 2021 18:32
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants