From eb6ba505440153a105b75969eb913903ce94be04 Mon Sep 17 00:00:00 2001 From: b-m-f Date: Tue, 30 Jul 2019 11:33:37 +0100 Subject: [PATCH] Split network and swarm discovery loop, break each when not ready --- beacon_node/network/src/service.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index a771f8add..046c59774 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -105,10 +105,8 @@ fn network_service( log: slog::Logger, ) -> impl futures::Future { futures::future::poll_fn(move || -> Result<_, eth2_libp2p::error::Error> { - // only end the loop once both major polls are not ready. - let mut not_ready_count = 0; - while not_ready_count < 2 { - not_ready_count = 0; + // if the network channel is not ready, try the swarm + loop { // poll the network channel match network_recv.poll() { Ok(Async::Ready(Some(message))) => match message { @@ -123,7 +121,7 @@ fn network_service( libp2p_service.lock().swarm.publish(topics, *message); } }, - Ok(Async::NotReady) => not_ready_count += 1, + Ok(Async::NotReady) => break, Ok(Async::Ready(None)) => { return Err(eth2_libp2p::error::Error::from("Network channel closed")); } @@ -131,7 +129,9 @@ fn network_service( return Err(eth2_libp2p::error::Error::from("Network channel error")); } } + } + loop { // poll the swarm match libp2p_service.lock().poll() { Ok(Async::Ready(Some(event))) => match event { @@ -164,8 +164,8 @@ fn network_service( } }, Ok(Async::Ready(None)) => unreachable!("Stream never ends"), - Ok(Async::NotReady) => not_ready_count += 1, - Err(_) => not_ready_count += 1, + Ok(Async::NotReady) => break, + Err(_) => break, } }