mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
client/network-gossip: Integrate GossipEngine tasks into Future impl (#4767)
`GossipEngine` spawns two tasks, one for a periodic tick, one to forward messages from the network to subscribers. These tasks hold an `Arc` to a `GossipEngineInner`. To reduce the amount of shared ownership (locking) this patch integrates the two tasks into a `Future` implementation on the `GossipEngine` struct. This `Future` implementation can now be called from a single owner, e.g. the `finality-grandpa` `NetworkBridge`. As a side effect this removes the requirement on the `network-gossip` crate to spawn tasks and thereby removes the requirement on the `finality-grandpa` crate to spawn any tasks. This is part of a greater effort to reduce the number of owners of components within `finality-grandpa`, `network` and `network-gossip` as well as to reduce the amount of unbounded channels. For details seed9837d7dd,5f80929dcand597c0a6c4.
This commit is contained in:
@@ -178,7 +178,6 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
|
||||
service: N,
|
||||
config: crate::Config,
|
||||
set_state: crate::environment::SharedVoterSetState<B>,
|
||||
executor: &impl futures::task::Spawn,
|
||||
) -> Self {
|
||||
let (validator, report_stream) = GossipValidator::new(
|
||||
config,
|
||||
@@ -186,7 +185,7 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
|
||||
);
|
||||
|
||||
let validator = Arc::new(validator);
|
||||
let gossip_engine = GossipEngine::new(service.clone(), executor, GRANDPA_ENGINE_ID, validator.clone());
|
||||
let gossip_engine = GossipEngine::new(service.clone(), GRANDPA_ENGINE_ID, validator.clone());
|
||||
|
||||
{
|
||||
// register all previous votes with the gossip service so that they're
|
||||
@@ -374,10 +373,9 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
|
||||
|to, neighbor| self.neighbor_sender.send(to, neighbor),
|
||||
);
|
||||
|
||||
let service = self.gossip_engine.clone();
|
||||
let topic = global_topic::<B>(set_id.0);
|
||||
let incoming = incoming_global(
|
||||
service,
|
||||
self.gossip_engine.clone(),
|
||||
topic,
|
||||
voters,
|
||||
self.validator.clone(),
|
||||
@@ -419,7 +417,7 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
|
||||
impl<B: BlockT, N: Network<B>> Future for NetworkBridge<B, N> {
|
||||
type Output = Result<(), Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
loop {
|
||||
match self.neighbor_packet_worker.lock().poll_next_unpin(cx) {
|
||||
Poll::Ready(Some((to, packet))) => {
|
||||
@@ -444,6 +442,12 @@ impl<B: BlockT, N: Network<B>> Future for NetworkBridge<B, N> {
|
||||
}
|
||||
}
|
||||
|
||||
match self.gossip_engine.poll_unpin(cx) {
|
||||
// The gossip engine future finished. We should do the same.
|
||||
Poll::Ready(()) => return Poll::Ready(Ok(())),
|
||||
Poll::Pending => {},
|
||||
}
|
||||
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user