diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index 9b48f5aa51..cea9653083 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -259,10 +259,7 @@ impl, H: ExHashT fn send_message(&self, round: u64, set_id: u64, message: Vec) { let topic = message_topic::(round, set_id); - let gossip = self.service.consensus_gossip(); - self.service.with_spec(move |_s, context|{ - gossip.write().multicast(context, topic, message); - }); + self.service.gossip_consensus_message(topic, message); } fn drop_messages(&self, round: u64, set_id: u64) { @@ -276,10 +273,7 @@ impl, H: ExHashT fn send_commit(&self, set_id: u64, message: Vec) { let topic = commit_topic::(set_id); - let gossip = self.service.consensus_gossip(); - self.service.with_spec(move |_s, context|{ - gossip.write().multicast(context, topic, message); - }); + self.service.gossip_consensus_message(topic, message); } } diff --git a/substrate/core/network/src/protocol.rs b/substrate/core/network/src/protocol.rs index 9b3a3965c1..cebda6c69c 100644 --- a/substrate/core/network/src/protocol.rs +++ b/substrate/core/network/src/protocol.rs @@ -224,7 +224,6 @@ impl, H: ExHashT> Protocol { &self.sync } - pub(crate) fn consensus_gossip<'a>(&'a self) -> &'a RwLock> { &self.consensus_gossip } @@ -297,6 +296,13 @@ impl, H: ExHashT> Protocol { send_message::(&self.context_data.peers, io, who, message) } + pub fn gossip_consensus_message(&self, io: &mut SyncIo, topic: B::Hash, message: Vec) { + let gossip = self.consensus_gossip(); + self.with_spec(io, move |_s, context|{ + gossip.write().multicast(context, topic, message); + }); + } + /// Called when a new peer is connected pub fn on_peer_connected(&self, io: &mut SyncIo, who: NodeIndex) { trace!(target: "sync", "Connected {}: {}", who, io.peer_debug_info(who)); diff --git a/substrate/core/network/src/service.rs b/substrate/core/network/src/service.rs index d5552f8520..d7d72dca8d 100644 --- a/substrate/core/network/src/service.rs +++ b/substrate/core/network/src/service.rs @@ -126,6 +126,13 @@ impl, H: ExHashT> Service) { + self.handler.gossip_consensus_message( + &mut NetSyncIo::new(&self.network, self.protocol_id), + topic, + message) + } /// Execute a closure with the chain-specific network specialization. pub fn with_spec(&self, f: F) -> U where F: FnOnce(&mut S, &mut Context) -> U diff --git a/substrate/core/network/src/test/mod.rs b/substrate/core/network/src/test/mod.rs index 6120cd2035..374e825bc8 100644 --- a/substrate/core/network/src/test/mod.rs +++ b/substrate/core/network/src/test/mod.rs @@ -229,10 +229,7 @@ impl, D> Peer { /// Push a message into the gossip network and relay to peers. /// `TestNet::sync_step` needs to be called to ensure it's propagated. pub fn gossip_message(&self, topic: Hash, data: Vec) { - let gossip = self.sync.consensus_gossip(); - self.sync.with_spec(&mut TestIo::new(&self.queue, None), move |_s, context|{ - gossip.write().multicast(context, topic, data); - }); + self.sync.gossip_consensus_message(&mut TestIo::new(&self.queue, None), topic, data); } /// Add blocks to the peer -- edit the block before adding