mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Simplify consensus message sending (#1166)
* Create gossip_consensus_message helper on service, simplify consensus_gossip access
This commit is contained in:
committed by
GitHub
parent
59af4de4fd
commit
dbe31230c3
@@ -259,10 +259,7 @@ impl<B: BlockT, S: network::specialization::NetworkSpecialization<B>, H: ExHashT
|
||||
|
||||
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>) {
|
||||
let topic = message_topic::<B>(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<B: BlockT, S: network::specialization::NetworkSpecialization<B>, H: ExHashT
|
||||
|
||||
fn send_commit(&self, set_id: u64, message: Vec<u8>) {
|
||||
let topic = commit_topic::<B>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,6 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
&self.sync
|
||||
}
|
||||
|
||||
|
||||
pub(crate) fn consensus_gossip<'a>(&'a self) -> &'a RwLock<ConsensusGossip<B>> {
|
||||
&self.consensus_gossip
|
||||
}
|
||||
@@ -297,6 +296,13 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
send_message::<B, H>(&self.context_data.peers, io, who, message)
|
||||
}
|
||||
|
||||
pub fn gossip_consensus_message(&self, io: &mut SyncIo, topic: B::Hash, message: Vec<u8>) {
|
||||
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));
|
||||
|
||||
@@ -126,6 +126,13 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> Service<B, S,
|
||||
self.handler.propagate_extrinsics(&mut NetSyncIo::new(&self.network, self.protocol_id));
|
||||
}
|
||||
|
||||
/// Send a consensus message through the gossip
|
||||
pub fn gossip_consensus_message(&self, topic: B::Hash, message: Vec<u8>) {
|
||||
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<F, U>(&self, f: F) -> U
|
||||
where F: FnOnce(&mut S, &mut Context<B>) -> U
|
||||
|
||||
@@ -229,10 +229,7 @@ impl<V: 'static + Verifier<Block>, D> Peer<V, D> {
|
||||
/// 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<u8>) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user