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

client/finality-grandpa: Make round_communication use bounded channel #4691

Merged
merged 4 commits into from
Jan 23, 2020

Conversation

mxinden
Copy link
Contributor

@mxinden mxinden commented Jan 20, 2020

round_communication returns a Sink and a Stream for outgoing and
incoming messages. The messages send into the Sink are forwarded down
to the network as well as send back into the Stream to ensure the node
processes its own messages.

So far, to send messages into the Sink back into the Stream, an
unbounded channel was used. This patch updates round_communication and
OutgoingMessages to use a bounded channel.

This is part of a greater effort to reduce the number of owners of
components within finality-grandpa and network as well as to reduce
the amount of unbounded channels. For details see d4fbb89 and
f0c1852.

`round_communication` returns a `Sink` and a `Stream` for outgoing and
incoming messages. The messages send into the `Sink` are forwarded down
to the network as well as send back into the `Stream` to ensure the node
processes its own messages.

So far, to send messages into the `Sink` back into the `Stream`, an
unbounded channel was used. This patch updates `round_communication` and
`OutgoingMessages` to use a bounded channel.

This is part of a greater effort to reduce the number of owners of
components within `finality-grandpa` and `network` as well as to reduce
the amount of unbounded channels. For details see d4fbb89 and
f0c1852.
@mxinden mxinden added the A0-please_review Pull request needs code review. label Jan 20, 2020
Copy link
Contributor

@Demi-Marie Demi-Marie left a comment

Choose a reason for hiding this comment

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

We need to ensure that we don’t create deadlocks.

@mxinden
Copy link
Contributor Author

mxinden commented Jan 21, 2020

We need to ensure that we don’t create deadlocks.

Correct. The channel being bounded in this patch is used to send packets back to our self. Thus we depend on us reading from the channel.

@tomaka
Copy link
Contributor

tomaka commented Jan 21, 2020

Let's maybe merge #4612 first?

@mxinden mxinden changed the title clinet/finality-grandpa: Make round_communication use bounded channel client/finality-grandpa: Make round_communication use bounded channel Jan 21, 2020
@Demi-Marie
Copy link
Contributor

Demi-Marie commented Jan 21, 2020

@mxinden We need to ensure that we don’t need to buffer an unbounded amount of data.

@andresilva
Copy link
Contributor

andresilva commented Jan 22, 2020

I agree with the theory behind this change. In practice though I think this is bound to cause more problems than it aims to solve. In particular because AFAIK going OOM (or any noticeable memory usage increase) due to these unbounded channels has not been a problem so far. I'd appreciate that this is properly tested before it is rolled out on a live network to avoid surprises (maybe by deploying to flaming fir along with #4612).

Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

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

Changes lgtm. Regarding my earlier comment on any issues that might be introduced by this, it was made before checking which unbounded channel was being changed. After reviewing the PR I think this one is not problematic at all. Still agree with Pierre that this could probably be merged after #4612 so that we don't need to mix futures versions.

@mxinden
Copy link
Contributor Author

mxinden commented Jan 22, 2020

@mxinden We need to ensure that we don’t need to buffer an unbounded amount of data.

@demimarie-parity I don't understand your comment. Yes, we need to make sure to not buffer unbounded amount of data. That is what the effort behind these pull requests tries to achieve. In the end you can see an unbounded channel as an unbounded buffer.

@mxinden
Copy link
Contributor Author

mxinden commented Jan 22, 2020

I would prefer not to block this pull request on #4612 given that the latter is quite large and given that it is unclear when it will be merged.

so that we don't need to mix futures versions.

We already mix both futures01 and futures03 within client/finality-grandpa.

The changeset in this pull request is not large and I am happy to resolve the merge conflicts with #4612 (already half done locally) once this one merged.

@tomaka @andresilva @expenses let me know if this would be ok for you.

(I will look into #4612 and #4633 next and try to help out.)

@expenses
Copy link
Contributor

@mxinden I doubt the merge conflict would be especially difficult, so that works for me!

match decoded {
Err(ref e) => {
debug!(target: "afg", "Skipping malformed message {:?}: {}", notification, e);
return ready(None);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if this read future::ready instead. Wasn't immediately obvious to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. As a rule of thumb, importing free functions into the local namespace hurts readability.

module::function lets us know where to look for the function without searching the imports.
function lets us know that the function is in the current module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed with 6858319.

@andresilva
Copy link
Contributor

We already mix both futures01 and futures03 within client/finality-grandpa.

After #4612 we don't, which is what I meant. I'm OK with not blocking this PR though.

Instead of importing futures03::future::ready into the scope, only
import futures::future03 into scope and call ready as furure03::ready.
@mxinden
Copy link
Contributor Author

mxinden commented Jan 22, 2020

Thanks for the reviews and help!

@rphmeier any further comments from your side?

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.

None yet

6 participants