mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Remove necessity to pass ConsensusEngineId when registering notifications protocol (#7549)
* Remove necessity to pass ConsensusEngineId when registering notifications protocol * Line width * Fix tests protocol name * Other renames * Doc update * Change issue in TODO
This commit is contained in:
@@ -30,7 +30,7 @@ use libp2p::kad::record;
|
||||
use libp2p::swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters};
|
||||
use log::debug;
|
||||
use sp_consensus::{BlockOrigin, import_queue::{IncomingBlock, Origin}};
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId, Justification};
|
||||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, Justification};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashSet, VecDeque},
|
||||
@@ -131,7 +131,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
/// Node we opened the substream with.
|
||||
remote: PeerId,
|
||||
/// The concerned protocol. Each protocol uses a different substream.
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol: Cow<'static, str>,
|
||||
/// Object that permits sending notifications to the peer.
|
||||
notifications_sink: NotificationsSink,
|
||||
/// Role of the remote.
|
||||
@@ -147,7 +147,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
/// Id of the peer we are connected to.
|
||||
remote: PeerId,
|
||||
/// The concerned protocol. Each protocol uses a different substream.
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol: Cow<'static, str>,
|
||||
/// Replacement for the previous [`NotificationsSink`].
|
||||
notifications_sink: NotificationsSink,
|
||||
},
|
||||
@@ -158,7 +158,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
/// Node we closed the substream with.
|
||||
remote: PeerId,
|
||||
/// The concerned protocol. Each protocol uses a different substream.
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol: Cow<'static, str>,
|
||||
},
|
||||
|
||||
/// Received one or more messages from the given node using the given protocol.
|
||||
@@ -166,7 +166,7 @@ pub enum BehaviourOut<B: BlockT> {
|
||||
/// Node we received the message from.
|
||||
remote: PeerId,
|
||||
/// Concerned protocol and associated message.
|
||||
messages: Vec<(ConsensusEngineId, Bytes)>,
|
||||
messages: Vec<(Cow<'static, str>, Bytes)>,
|
||||
},
|
||||
|
||||
/// Events generated by a DHT as a response to get_value or put_value requests as well as the
|
||||
@@ -257,19 +257,20 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
|
||||
/// will retain the protocols that were registered then, and not any new one.
|
||||
pub fn register_notifications_protocol(
|
||||
&mut self,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: impl Into<Cow<'static, str>>,
|
||||
protocol: impl Into<Cow<'static, str>>,
|
||||
) {
|
||||
let protocol = protocol.into();
|
||||
|
||||
// This is the message that we will send to the remote as part of the initial handshake.
|
||||
// At the moment, we force this to be an encoded `Roles`.
|
||||
let handshake_message = Roles::from(&self.role).encode();
|
||||
|
||||
let list = self.substrate.register_notifications_protocol(engine_id, protocol_name, handshake_message);
|
||||
let list = self.substrate.register_notifications_protocol(protocol.clone(), handshake_message);
|
||||
for (remote, roles, notifications_sink) in list {
|
||||
let role = reported_roles_to_observed_role(&self.role, remote, roles);
|
||||
self.events.push_back(BehaviourOut::NotificationStreamOpened {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
protocol: protocol.clone(),
|
||||
role,
|
||||
notifications_sink: notifications_sink.clone(),
|
||||
});
|
||||
@@ -363,28 +364,28 @@ Behaviour<B, H> {
|
||||
},
|
||||
CustomMessageOutcome::NotificationStreamOpened { remote, protocols, roles, notifications_sink } => {
|
||||
let role = reported_roles_to_observed_role(&self.role, &remote, roles);
|
||||
for engine_id in protocols {
|
||||
for protocol in protocols {
|
||||
self.events.push_back(BehaviourOut::NotificationStreamOpened {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
protocol,
|
||||
role: role.clone(),
|
||||
notifications_sink: notifications_sink.clone(),
|
||||
});
|
||||
}
|
||||
},
|
||||
CustomMessageOutcome::NotificationStreamReplaced { remote, protocols, notifications_sink } =>
|
||||
for engine_id in protocols {
|
||||
for protocol in protocols {
|
||||
self.events.push_back(BehaviourOut::NotificationStreamReplaced {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
protocol,
|
||||
notifications_sink: notifications_sink.clone(),
|
||||
});
|
||||
},
|
||||
CustomMessageOutcome::NotificationStreamClosed { remote, protocols } =>
|
||||
for engine_id in protocols {
|
||||
for protocol in protocols {
|
||||
self.events.push_back(BehaviourOut::NotificationStreamClosed {
|
||||
remote: remote.clone(),
|
||||
engine_id,
|
||||
protocol,
|
||||
});
|
||||
},
|
||||
CustomMessageOutcome::NotificationsReceived { remote, messages } => {
|
||||
|
||||
Reference in New Issue
Block a user