From 6cd82ca747b191826df48de70fcd1d2563d7a411 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 13 May 2019 09:18:43 +0300 Subject: [PATCH] send GRANDPA messages without holding validator lock (#2537) --- .../src/communication/gossip.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/substrate/core/finality-grandpa/src/communication/gossip.rs b/substrate/core/finality-grandpa/src/communication/gossip.rs index 62bfe8a657..fd9d30e951 100644 --- a/substrate/core/finality-grandpa/src/communication/gossip.rs +++ b/substrate/core/finality-grandpa/src/communication/gossip.rs @@ -594,24 +594,30 @@ 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) - .map(|(to, msg)| send_neighbor(to, msg)); + let maybe_msg = self.inner.write().note_round(round, set_id); + if let Some((to, msg)) = maybe_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) - .map(|(to, msg)| send_neighbor(to, msg)); + let maybe_msg = self.inner.write().note_set(set_id); + if let Some((to, msg)) = maybe_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) - .map(|(to, msg)| send_neighbor(to, msg)); + let maybe_msg = self.inner.write().note_commit_finalized(finalized); + if let Some((to, msg)) = maybe_msg { + send_neighbor(to, msg); + } } fn report(&self, who: PeerId, cost_benefit: i32) {