mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 17:11:05 +00:00
Open one substream for each notifications protocol (#4909)
* Open one substream for each notifications protocol * Fix WASM build * Apply suggestions from code review Co-Authored-By: Toralf Wittner <tw@dtex.org> * Address concerns * Use unsigned-varint to read the varint * Use unsigned-varint * Forgot Cargo.lock Co-authored-by: Toralf Wittner <tw@dtex.org>
This commit is contained in:
@@ -24,7 +24,7 @@ use futures::{prelude::*, channel::mpsc};
|
||||
use libp2p::PeerId;
|
||||
use parking_lot::Mutex;
|
||||
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
|
||||
use std::{pin::Pin, sync::Arc, task::{Context, Poll}};
|
||||
use std::{borrow::Cow, pin::Pin, sync::Arc, task::{Context, Poll}};
|
||||
|
||||
/// Wraps around an implementation of the `Network` crate and provides gossiping capabilities on
|
||||
/// top of it.
|
||||
@@ -48,6 +48,7 @@ impl<B: BlockT> GossipEngine<B> {
|
||||
pub fn new<N: Network<B> + Send + Clone + 'static>(
|
||||
mut network: N,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: impl Into<Cow<'static, [u8]>>,
|
||||
validator: Arc<dyn Validator<B>>,
|
||||
) -> Self where B: 'static {
|
||||
let mut state_machine = ConsensusGossip::new();
|
||||
@@ -56,7 +57,7 @@ impl<B: BlockT> GossipEngine<B> {
|
||||
// might miss events.
|
||||
let network_event_stream = network.event_stream();
|
||||
|
||||
network.register_notifications_protocol(engine_id);
|
||||
network.register_notifications_protocol(engine_id, protocol_name.into());
|
||||
state_machine.register_validator(&mut network, engine_id, validator);
|
||||
|
||||
let inner = Arc::new(Mutex::new(GossipEngineInner {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub use self::validator::{DiscardAll, MessageIntent, Validator, ValidatorContext
|
||||
use futures::prelude::*;
|
||||
use sc_network::{specialization::NetworkSpecialization, Event, ExHashT, NetworkService, PeerId, ReputationChange};
|
||||
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
|
||||
use std::{pin::Pin, sync::Arc};
|
||||
use std::{borrow::Cow, pin::Pin, sync::Arc};
|
||||
|
||||
mod bridge;
|
||||
mod state_machine;
|
||||
@@ -86,7 +86,8 @@ pub trait Network<B: BlockT> {
|
||||
/// See the documentation of [`NetworkService:register_notifications_protocol`] for more information.
|
||||
fn register_notifications_protocol(
|
||||
&self,
|
||||
engine_id: ConsensusEngineId
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: Cow<'static, [u8]>,
|
||||
);
|
||||
|
||||
/// Notify everyone we're connected to that we have the given block.
|
||||
@@ -116,8 +117,9 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Network<B> for Arc<Netw
|
||||
fn register_notifications_protocol(
|
||||
&self,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: Cow<'static, [u8]>,
|
||||
) {
|
||||
NetworkService::register_notifications_protocol(self, engine_id)
|
||||
NetworkService::register_notifications_protocol(self, engine_id, protocol_name)
|
||||
}
|
||||
|
||||
fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
|
||||
|
||||
Reference in New Issue
Block a user