diff --git a/substrate/core/finality-grandpa/src/communication/gossip.rs b/substrate/core/finality-grandpa/src/communication/gossip.rs index 6b45fd0745..93511b759d 100644 --- a/substrate/core/finality-grandpa/src/communication/gossip.rs +++ b/substrate/core/finality-grandpa/src/communication/gossip.rs @@ -425,6 +425,8 @@ struct Inner { next_rebroadcast: Instant, } +type MaybeMessage = Option<(Vec, NeighborPacket>)>; + impl Inner { fn new(config: crate::Config) -> Self { Inner { @@ -437,11 +439,9 @@ impl Inner { } /// Note a round in a set has started. - fn note_round(&mut self, round: Round, set_id: SetId, send_neighbor: F) - where F: FnOnce(Vec, NeighborPacket>) - { + fn note_round(&mut self, round: Round, set_id: SetId) -> MaybeMessage { if self.local_view.round == round && self.local_view.set_id == set_id { - return + return None; } debug!(target: "afg", "Voter {} noting beginning of round {:?} to network.", @@ -451,28 +451,28 @@ impl Inner { self.local_view.set_id = set_id; self.live_topics.push(round, set_id); - self.multicast_neighbor_packet(send_neighbor); + self.multicast_neighbor_packet() } /// Note that a voter set with given ID has started. Does nothing if the last /// call to the function was with the same `set_id`. - fn note_set(&mut self, set_id: SetId, send_neighbor: F) - where F: FnOnce(Vec, NeighborPacket>) - { - if self.local_view.set_id == set_id { return } + fn note_set(&mut self, set_id: SetId) -> MaybeMessage { + if self.local_view.set_id == set_id { + return None; + } self.local_view.update_set(set_id); self.live_topics.push(Round(0), set_id); - self.multicast_neighbor_packet(send_neighbor); + self.multicast_neighbor_packet() } /// Note that we've imported a commit finalizing a given block. - fn note_commit_finalized(&mut self, finalized: NumberFor, send_neighbor: F) - where F: FnOnce(Vec, NeighborPacket>) - { + fn note_commit_finalized(&mut self, finalized: NumberFor) -> MaybeMessage { if self.local_view.last_commit.as_ref() < Some(&finalized) { self.local_view.last_commit = Some(finalized); - self.multicast_neighbor_packet(send_neighbor) + self.multicast_neighbor_packet() + } else { + None } } @@ -560,9 +560,7 @@ impl Inner { (neighbor_topics, Action::Discard(cb)) } - fn multicast_neighbor_packet(&self, send_neighbor: F) - where F: FnOnce(Vec, NeighborPacket>) - { + fn multicast_neighbor_packet(&self) -> MaybeMessage { let packet = NeighborPacket { round: self.local_view.round, set_id: self.local_view.set_id, @@ -570,7 +568,7 @@ impl Inner { }; let peers = self.peers.inner.keys().cloned().collect(); - send_neighbor(peers, packet); + Some((peers, packet)) } } @@ -596,21 +594,24 @@ impl GossipValidator { pub(super) fn note_round(&self, round: Round, set_id: SetId, send_neighbor: F) where F: FnOnce(Vec, NeighborPacket>) { - self.inner.write().note_round(round, set_id, send_neighbor); + self.inner.write().note_round(round, set_id) + .map(|(to, msg)| send_neighbor(to, msg)); } /// Note that a voter set with given ID has started. pub(super) fn note_set(&self, set_id: SetId, send_neighbor: F) where F: FnOnce(Vec, NeighborPacket>) { - self.inner.write().note_set(set_id, send_neighbor); + self.inner.write().note_set(set_id) + .map(|(to, msg)| send_neighbor(to, msg)); } /// Note that we've imported a commit finalizing a given block. pub(super) fn note_commit_finalized(&self, finalized: NumberFor, send_neighbor: F) where F: FnOnce(Vec, NeighborPacket>) { - self.inner.write().note_commit_finalized(finalized, send_neighbor); + self.inner.write().note_commit_finalized(finalized) + .map(|(to, msg)| send_neighbor(to, msg)); } fn report(&self, who: PeerId, cost_benefit: i32) { diff --git a/substrate/core/network/src/protocol.rs b/substrate/core/network/src/protocol.rs index b3c56c9e7c..30c2077de6 100644 --- a/substrate/core/network/src/protocol.rs +++ b/substrate/core/network/src/protocol.rs @@ -685,7 +685,7 @@ impl, H: ExHashT> Protocol { { for (who, peer) in self.context_data.peers.iter() { if peer.block_request.as_ref().map_or(false, |(t, _)| (tick - *t).as_secs() > REQUEST_TIMEOUT_SEC) { - trace!(target: "sync", "Reqeust timeout {}", who); + trace!(target: "sync", "Request timeout {}", who); aborting.push(who.clone()); } else if peer.obsolete_requests.values().any(|t| (tick - *t).as_secs() > REQUEST_TIMEOUT_SEC) { trace!(target: "sync", "Obsolete timeout {}", who); diff --git a/substrate/core/network/src/test/mod.rs b/substrate/core/network/src/test/mod.rs index 9b0c72429d..5965868472 100644 --- a/substrate/core/network/src/test/mod.rs +++ b/substrate/core/network/src/test/mod.rs @@ -47,7 +47,6 @@ use runtime_primitives::{Justification, ConsensusEngineId}; use crate::service::{network_channel, NetworkChan, NetworkLink, NetworkMsg, NetworkPort, TransactionPool}; use crate::specialization::NetworkSpecialization; use test_client::{self, AccountKeyring}; -use log::debug; pub use test_client::runtime::{Block, Extrinsic, Hash, Transfer}; pub use test_client::TestClient; @@ -170,7 +169,6 @@ impl> Link for TestLink { /// with `ImportQueue`. #[cfg(any(test, feature = "test-helpers"))] fn synchronized(&self) { - trace!(target: "test_network", "Synchronizing"); drop(self.network_to_protocol_sender.unbounded_send(FromNetworkMsg::Synchronize)) } } @@ -241,14 +239,12 @@ impl> ProtocolChannel { /// Wait until synchronization response is generated by the protocol. pub fn wait_sync(&self) -> Result<(), RecvError> { - trace!(target: "test_network", "Waiting for sync"); loop { match self.protocol_to_network_receiver.receiver().recv() { Ok(NetworkMsg::Synchronized) => return Ok(()), Err(error) => return Err(error), Ok(msg) => self.buffered_messages.lock().push_back(msg), } - trace!(target: "test_network", "Retrying sync"); } } @@ -390,9 +386,7 @@ impl> Peer { /// Synchronize with import queue. #[cfg(any(test, feature = "test-helpers"))] fn import_queue_sync(&self) { - trace!(target: "test_network", "syncing this queue"); self.import_queue.synchronize(); - trace!(target: "test_network", "wating for sync to finish"); let _ = self.net_proto_channel.wait_sync(); } @@ -728,7 +722,6 @@ pub trait TestNetFactory: Sized { } loop { - debug!(target: "test_network", "loop iteration"); // we only deliver Status messages during start let need_continue = self.route_single(true, None, &|msg| match *msg { NetworkMsg::Outgoing(_, crate::message::generic::Message::Status(_)) => true, @@ -755,7 +748,6 @@ pub trait TestNetFactory: Sized { let mut to_disconnect = HashSet::new(); let peers = self.peers(); for peer in peers { - debug!(target: "test_network", "checking peer"); if let Some(message) = peer.pending_message(message_filter) { match message { NetworkMsg::Outgoing(recipient_id, packet) => { @@ -794,13 +786,10 @@ pub trait TestNetFactory: Sized { } } } - debug!(target: "test_network", "syncing queues"); // make sure that the protocol(s) has processed all messages that have been queued self.peers().iter().for_each(|peer| peer.import_queue_sync()); - debug!(target: "test_network", "queues synced"); - had_messages }