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

Some refactoring in network-bridge in the course of dealing with #2177 #2263

Merged
10 commits merged into from
Jan 14, 2021

Conversation

eskimor
Copy link
Member

@eskimor eskimor commented Jan 13, 2021

Changes fall in these categories:

  1. Little restructuring of code, which helps with reading: Entry points and public API are now more prominent and less hidden in implementation details.
  2. I created protocol::peer_set, where I moved PeerSet to and gave a couple of duplicated code a new deduplicated home.
  3. Doc fixes: I added comments and fixed documentation where it was outdated.

For 2, in particular, I changed the code, so the compiler will tell you what to implement if you add another peer set. This leads to more robust code in this area .. you can not easily forget some parts of the implementation. The addition of 1, where I moved code around makes it a bit harder to review 2, but you can see the changes quite clearly by looking at this particular commit of this PR:
3af1f60 (I re-added the apparently missing peers_sets_info() function of this commit here).

If need be, I can also split this PR up in smaller ones.

Anyhow, wanted to get this out of the way as it is prone to merge conflicts.

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!
Some changes, which would have helped me in groking the code faster.

Entry points/public types more to the top. Factored out implementation
in their own files, to clear up the top-level view.
Does not add much at this level.
@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 13, 2021

/// Send a message to the network.
///
/// Usually this will be a `WireMessage`.
Copy link
Contributor

Choose a reason for hiding this comment

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

When not?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well right now, it always is a WireMessage, but the function does not care. On the other hand, it takes a PeerSet which describes which protocol to use and therefore actually specifies what a valid message would be. Which leads again to the question I asked you the other day:

"Unrelated: Are there any particular reasons why WireMessage is parametric over M which is either ValidationProtocol or CollationProtocol right now, instead of WireMessage just having a separate constructor for each?"

If we had a single sum type which specifies valid messages, which naturally maps to the PeerSet enum, this invariant would easily be expressible. (We would just not pass the PeerSet, as it could be derived from the passed message and therefore we make the expression of invalid combinations impossible.)

For this internally and not often used function it should not matter much actually, but that relationship would be handy in a couple of places. Also, I got the feeling that we will likely want more fine grained peer sets than we have right now, so making the implementation of new peer sets straight forward and less error prone seems worthwhile, which was the motivation for the other changes.

Ok, I derailed a bit on my answer, but I guess it gives some context to this PR in general.

Copy link
Member Author

@eskimor eskimor Jan 13, 2021

Choose a reason for hiding this comment

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

For completeness: Your answer was, that we want subsystems to only receive their messages, which is a good invariant to preserve obviously.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. Can you amend the doc to better reflect that although this function doesn't restrict the message type, it is only accessible by the network bridge which is responsible for setting it to the correct type for the PeerSet?

Copy link
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

Looks good.

node/network/bridge/src/action.rs Outdated Show resolved Hide resolved
node/network/bridge/src/network.rs Outdated Show resolved Hide resolved
Extend copyright on new files to 2021 as well.

Co-authored-by: Andronik Ordian <write@reusable.software>
@ordian
Copy link
Member

ordian commented Jan 14, 2021

bot merge

@ghost
Copy link

ghost commented Jan 14, 2021

Trying merge.

@ghost ghost merged commit 490cbd7 into master Jan 14, 2021
@ghost ghost deleted the rk-minor-refactor-2177 branch January 14, 2021 10:29
xlc pushed a commit to xlc/polkadot that referenced this pull request Jan 26, 2021
…tytech#2177 (paritytech#2263)

* More doc fixes.

* Minor refactorings in the process of paritytech#2177

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.

* Add peer set infos on startup properly

For feature real_overseer.

+ Fixes from review. Thanks @coriolinus and @ordian!

* More structure in network-bridge

Some changes, which would have helped me in groking the code faster.

Entry points/public types more to the top. Factored out implementation
in their own files, to clear up the top-level view.

* Get rid of local ProtocolName type definition.

Does not add much at this level.

* Fix tests + import cleanup.

* Make spaces tabs.

* Clarify what correct parameters to send_message are

* Be more less vague in docs of send_message.

* Apply suggestions from code review

Extend copyright on new files to 2021 as well.

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
This pull request was closed.
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.

3 participants