mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
client/network-gossip/src/bridge: Finish when network event stream closes (#5282)
* client/network-gossip/src/bridge: Finish when network even stream closes Previously within `<GossipEngine as Future>::poll` one would poll the `network_event_stream` ignoring all messages other than `Poll::Ready(Some())`. Ignoring `Poll::Ready(None)` leads to a panic on the next poll of the stream, gien that it is not fused. By design `network_event_stream` does not close unless an unbounded send into it fails, or the `NetworkWorker` gets shut down. > The stream never ends (unless the `NetworkWorker` gets shut down). > (client/network/src/service.rs) An `unbounded_send` to fail on an unbounded channel is unlikely. The `NetworkWorker` shutting down is not unlikely. In such case the `GossipEngine` should shut down as well. With this patch a `<GossipEngine as Future>` finishes on `Poll::Ready(None)` returned from `network_event_stream`. * client/finality-grandpa/communication: Error on gossip engine finished Have `<NetworkBridge as Future>::poll` return `Poll::Ready(Err)` instead of `Poll::Ready(Ok)` to be consistent with the handling of the neighbor packet worker stream and the gossip validator report stream. Both `Err` as well as `Ok` shut down the `NetworkBridge` as well as the `VoterWorker`. * client/network-gossip/src/bridge: Add regression test * client/network-gossip: Move substrate test client to dev dependencies * client/network-gossip: Remove TODO Addressed in a follow up pull request. * client/network-gossip/bridge: Put match on newline after loop * client/finality-grandpa/src/observer: Fix regression test Make sure the event stream sender side is not dropped till the end.
This commit is contained in:
@@ -451,8 +451,9 @@ impl<B: BlockT, N: Network<B>> Future for NetworkBridge<B, N> {
|
||||
}
|
||||
|
||||
match self.gossip_engine.lock().poll_unpin(cx) {
|
||||
// The gossip engine future finished. We should do the same.
|
||||
Poll::Ready(()) => return Poll::Ready(Ok(())),
|
||||
Poll::Ready(()) => return Poll::Ready(
|
||||
Err(Error::Network("Gossip engine future finished.".into()))
|
||||
),
|
||||
Poll::Pending => {},
|
||||
}
|
||||
|
||||
|
||||
@@ -425,21 +425,16 @@ mod tests {
|
||||
tester.trigger_gossip_validator_reputation_change(&peer_id);
|
||||
|
||||
executor::block_on(async move {
|
||||
// Poll the observer once and have it forward the reputation change from the gossip
|
||||
// validator to the test network.
|
||||
assert!(observer.now_or_never().is_none());
|
||||
|
||||
// Ignore initial event stream request by gossip engine.
|
||||
match tester.events.next().now_or_never() {
|
||||
Some(Some(Event::EventStream(_))) => {},
|
||||
_ => panic!("expected event stream request"),
|
||||
};
|
||||
|
||||
assert!(
|
||||
tester.events.next().now_or_never().is_none(),
|
||||
"expect no further network events",
|
||||
);
|
||||
|
||||
// Poll the observer once and have it forward the reputation change from the gossip
|
||||
// validator to the test network.
|
||||
assert!(observer.now_or_never().is_none());
|
||||
|
||||
assert_matches!(tester.events.next().now_or_never(), Some(Some(Event::Report(_, _))));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user