Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to stables futures #81

Merged
merged 1 commit into from
Oct 23, 2019
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Aug 16, 2019

Updates the crate to use futures from the standard library rather than the futures crate.

@@ -302,13 +304,13 @@ pub struct RoundData<Id, Timer, Input, Output> {
pub outgoing: Output,
}

struct Buffered<S: Sink> {
struct Buffered<S, I> {
Copy link
Contributor Author

@tomaka tomaka Aug 16, 2019

Choose a reason for hiding this comment

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

Note: the signature of the Sink trait has changed. The item is now a parameter of the trait instead of an associated type.

Also note that there is now a Buffered type provided by the futures-preview crate, but I'll open an issue for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice - it didn't exist when I wrote this code.


::futures::future::join_all(finalized_streams).map(|_| signal.fire())
})).unwrap();
threads_pool.spawn_ok(routing_task.map(|_| ()));
Copy link
Contributor Author

@tomaka tomaka Aug 16, 2019

Choose a reason for hiding this comment

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

Note: Because the behaviour of join_all has changed a bit, I had to adjust the order in which things are initialized, otherwise the test wouldn't work (blocked at round 1 with futures not being notified). This is a bit concerning, but I couldn't find the origin of the issue.

Copy link
Contributor

@romanb romanb Oct 2, 2019

Choose a reason for hiding this comment

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

From what I can tell this is not related to join_all. If the routing_task future is spawned before the first Voter is created (i.e. the case where the test stalls / hangs), the NetworkRouting future is polled "immediately" before the first voter is created. It then returns Poll::Pending, which it always does, since it relies on task wakeup from the UnboundedReceivers (i.e. when messages are sent). However, there are no voters and hence no VotingRound yet, so the current task is only scheduled to be polled again if a message is sent to the GlobalMessageNetwork, which doesn't happen in this test. So the NetworkRouting is never polled again, even after the first round with voters is created, resulting in the messages never being dispatched.

In all other tests except one (skips_to_latest_round_after_catch_up), the routing_task is only spawned after the first voter is created. In skips_to_latest_round_after_catch_up it is spawned earlier, but this test then calls network.send_message after a voter is set up, i.e. sends a message on the GlobalMessageNetwork, resulting in the NetworkRouting to be polled again.

The reason this worked previously is most likely due to the semantics of block_on_all in tokio, which results in the spawned "inner" NetworkRouting future to be polled again after the "outer" future resolved, at which point the voters have been set up and a voting round has been created.

So it seems to me that spawning the routing_task only after at least one voter has been created is not only necessary now but arguably more correct, at least the way the NetworkRouting is currently set up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for looking into this and for the detailed explanation @romanb.

@codecov-io
Copy link

Codecov Report

Merging #81 into master will decrease coverage by 2.53%.
The diff coverage is 93.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
- Coverage   90.79%   88.26%   -2.54%     
==========================================
  Files          10       10              
  Lines        3390     2480     -910     
==========================================
- Hits         3078     2189     -889     
+ Misses        312      291      -21
Impacted Files Coverage Δ
src/bridge_state.rs 95.23% <88.88%> (ø) ⬆️
src/voter/past_rounds.rs 91.52% <90%> (+0.07%) ⬆️
src/voter/mod.rs 83.3% <93.61%> (-4.34%) ⬇️
src/testing.rs 89.6% <94.44%> (-4.4%) ⬇️
src/voter/voting_round.rs 77.88% <95.65%> (-6.03%) ⬇️
src/bitfield.rs 81.13% <0%> (-2.42%) ⬇️
src/lib.rs 84.14% <0%> (-1.98%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dab9d4...b6ff0fc. Read the comment docs.

@tomaka
Copy link
Contributor Author

tomaka commented Sep 19, 2019

Ping!

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.

lgtm! only thing a bit worrying is that issue with join_all in the test.

@andresilva
Copy link
Contributor

@tomaka sorry for being a shitty maintainer 😿

@rphmeier
Copy link
Contributor

Yup I also gave this another look after the ping, also worried by the join_all thing.

@romanb
Copy link
Contributor

romanb commented Oct 2, 2019

See this comment regarding the mentioned concern.

@tomaka
Copy link
Contributor Author

tomaka commented Oct 23, 2019

Should we merge this?
I know that GrandPa's code is very sensible and we should be extra careful, but on the other hand I think this PR is quite straight-forward and I don't really see how a bug could be introduced just by transitioning to stable futures.

@andresilva andresilva merged commit 286133e into paritytech:master Oct 23, 2019
@tomaka tomaka deleted the new-futures branch October 23, 2019 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants