mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Extract consensus_gossip.rs and put it in its own crate (#4284)
* Extract gossiping system from network * Finish porting GRANDPA tests * Try put correct engine ID * Fix messages encoding * Fix communication tests * Use a threads pool to spawn stuff * Fix compilation everywhere * Fix bad merge conflict * Remove dependency on async-std * Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * More suggestions * Remove network startup GP future * Update to futures_timer * adjust wait_when_behind test * Pass correct Roles after handshake * Revert "adjust wait_when_behind test" This reverts commit 23cb3a0a6d25ed732c2cd648607bc44ef2ab0919. * Crate root documentation * Remove MessageRecipient * Address concerns * Fix more concerns * Forgot Cargo.lock
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
|
||||
use crate::{
|
||||
debug_info, discovery::DiscoveryBehaviour, discovery::DiscoveryOut, DiscoveryNetBehaviour,
|
||||
protocol::event::DhtEvent
|
||||
Event, protocol::event::DhtEvent
|
||||
};
|
||||
use crate::{ExHashT, specialization::NetworkSpecialization};
|
||||
use crate::protocol::{CustomMessageOutcome, Protocol};
|
||||
use consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
|
||||
use futures::prelude::*;
|
||||
use libp2p::NetworkBehaviour;
|
||||
use libp2p::core::{Multiaddr, PeerId, PublicKey};
|
||||
@@ -27,7 +28,7 @@ use libp2p::kad::record;
|
||||
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess};
|
||||
use libp2p::core::{nodes::Substream, muxing::StreamMuxerBox};
|
||||
use log::{debug, warn};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, Justification};
|
||||
use std::iter;
|
||||
use void;
|
||||
|
||||
@@ -50,8 +51,10 @@ pub struct Behaviour<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> {
|
||||
|
||||
/// Event generated by `Behaviour`.
|
||||
pub enum BehaviourOut<B: BlockT> {
|
||||
SubstrateAction(CustomMessageOutcome<B>),
|
||||
Dht(DhtEvent),
|
||||
BlockImport(BlockOrigin, Vec<IncomingBlock<B>>),
|
||||
JustificationImport(Origin, B::Hash, NumberFor<B>, Justification),
|
||||
FinalityProofImport(Origin, B::Hash, NumberFor<B>, Vec<u8>),
|
||||
Event(Event),
|
||||
}
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Behaviour<B, S, H> {
|
||||
@@ -127,7 +130,34 @@ Behaviour<B, S, H> {
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> NetworkBehaviourEventProcess<CustomMessageOutcome<B>> for
|
||||
Behaviour<B, S, H> {
|
||||
fn inject_event(&mut self, event: CustomMessageOutcome<B>) {
|
||||
self.events.push(BehaviourOut::SubstrateAction(event));
|
||||
match event {
|
||||
CustomMessageOutcome::BlockImport(origin, blocks) =>
|
||||
self.events.push(BehaviourOut::BlockImport(origin, blocks)),
|
||||
CustomMessageOutcome::JustificationImport(origin, hash, nb, justification) =>
|
||||
self.events.push(BehaviourOut::JustificationImport(origin, hash, nb, justification)),
|
||||
CustomMessageOutcome::FinalityProofImport(origin, hash, nb, proof) =>
|
||||
self.events.push(BehaviourOut::FinalityProofImport(origin, hash, nb, proof)),
|
||||
CustomMessageOutcome::NotificationStreamOpened { remote, protocols, roles } =>
|
||||
for engine_id in protocols {
|
||||
self.events.push(BehaviourOut::Event(Event::NotificationStreamOpened {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
roles,
|
||||
}));
|
||||
},
|
||||
CustomMessageOutcome::NotificationsStreamClosed { remote, protocols } =>
|
||||
for engine_id in protocols {
|
||||
self.events.push(BehaviourOut::Event(Event::NotificationsStreamClosed {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
}));
|
||||
},
|
||||
CustomMessageOutcome::NotificationsReceived { remote, messages } => {
|
||||
let ev = Event::NotificationsReceived { remote, messages };
|
||||
self.events.push(BehaviourOut::Event(ev));
|
||||
},
|
||||
CustomMessageOutcome::None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,16 +196,16 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> NetworkBehaviourEventPr
|
||||
self.substrate.add_discovered_nodes(iter::once(peer_id));
|
||||
}
|
||||
DiscoveryOut::ValueFound(results) => {
|
||||
self.events.push(BehaviourOut::Dht(DhtEvent::ValueFound(results)));
|
||||
self.events.push(BehaviourOut::Event(Event::Dht(DhtEvent::ValueFound(results))));
|
||||
}
|
||||
DiscoveryOut::ValueNotFound(key) => {
|
||||
self.events.push(BehaviourOut::Dht(DhtEvent::ValueNotFound(key)));
|
||||
self.events.push(BehaviourOut::Event(Event::Dht(DhtEvent::ValueNotFound(key))));
|
||||
}
|
||||
DiscoveryOut::ValuePut(key) => {
|
||||
self.events.push(BehaviourOut::Dht(DhtEvent::ValuePut(key)));
|
||||
self.events.push(BehaviourOut::Event(Event::Dht(DhtEvent::ValuePut(key))));
|
||||
}
|
||||
DiscoveryOut::ValuePutFailed(key) => {
|
||||
self.events.push(BehaviourOut::Dht(DhtEvent::ValuePutFailed(key)));
|
||||
self.events.push(BehaviourOut::Event(Event::Dht(DhtEvent::ValuePutFailed(key))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user