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:
Pierre Krieger
2020-11-18 16:05:35 +01:00
committed by GitHub
parent 22a02d3e7a
commit 1eae9f5792
18 changed files with 228 additions and 284 deletions
@@ -68,7 +68,6 @@ mod periodic;
#[cfg(test)]
pub(crate) mod tests;
pub use sp_finality_grandpa::GRANDPA_ENGINE_ID;
pub const GRANDPA_PROTOCOL_NAME: &'static str = "/paritytech/grandpa/1";
// cost scalars for reporting peers.
@@ -215,7 +214,6 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
let validator = Arc::new(validator);
let gossip_engine = Arc::new(Mutex::new(GossipEngine::new(
service.clone(),
GRANDPA_ENGINE_ID,
GRANDPA_PROTOCOL_NAME,
validator.clone()
)));
@@ -24,10 +24,11 @@ use sc_network_gossip::Validator;
use std::sync::Arc;
use sp_keyring::Ed25519Keyring;
use parity_scale_codec::Encode;
use sp_runtime::{ConsensusEngineId, traits::NumberFor};
use sp_runtime::traits::NumberFor;
use std::{borrow::Cow, pin::Pin, task::{Context, Poll}};
use crate::communication::GRANDPA_PROTOCOL_NAME;
use crate::environment::SharedVoterSetState;
use sp_finality_grandpa::{AuthorityList, GRANDPA_ENGINE_ID};
use sp_finality_grandpa::AuthorityList;
use super::gossip::{self, GossipValidator};
use super::{VoterSet, Round, SetId};
@@ -57,11 +58,11 @@ impl sc_network_gossip::Network<Block> for TestNetwork {
fn disconnect_peer(&self, _: PeerId) {}
fn write_notification(&self, who: PeerId, _: ConsensusEngineId, message: Vec<u8>) {
fn write_notification(&self, who: PeerId, _: Cow<'static, str>, message: Vec<u8>) {
let _ = self.sender.unbounded_send(Event::WriteNotification(who, message));
}
fn register_notifications_protocol(&self, _: ConsensusEngineId, _: Cow<'static, str>) {}
fn register_notifications_protocol(&self, _: Cow<'static, str>) {}
fn announce(&self, block: Hash, _associated_data: Vec<u8>) {
let _ = self.sender.unbounded_send(Event::Announce(block));
@@ -86,7 +87,7 @@ impl sc_network_gossip::ValidatorContext<Block> for TestNetwork {
<Self as sc_network_gossip::Network<Block>>::write_notification(
self,
who.clone(),
GRANDPA_ENGINE_ID,
GRANDPA_PROTOCOL_NAME.into(),
data,
);
}
@@ -287,20 +288,20 @@ fn good_commit_leads_to_relay() {
// Add the sending peer and send the commit
let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened {
remote: sender_id.clone(),
engine_id: GRANDPA_ENGINE_ID,
protocol: GRANDPA_PROTOCOL_NAME.into(),
role: ObservedRole::Full,
});
let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived {
remote: sender_id.clone(),
messages: vec![(GRANDPA_ENGINE_ID, commit_to_send.clone().into())],
messages: vec![(GRANDPA_PROTOCOL_NAME.into(), commit_to_send.clone().into())],
});
// Add a random peer which will be the recipient of this message
let receiver_id = sc_network::PeerId::random();
let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened {
remote: receiver_id.clone(),
engine_id: GRANDPA_ENGINE_ID,
protocol: GRANDPA_PROTOCOL_NAME.into(),
role: ObservedRole::Full,
});
@@ -319,7 +320,7 @@ fn good_commit_leads_to_relay() {
sender.unbounded_send(NetworkEvent::NotificationsReceived {
remote: receiver_id,
messages: vec![(GRANDPA_ENGINE_ID, msg.encode().into())],
messages: vec![(GRANDPA_PROTOCOL_NAME.into(), msg.encode().into())],
})
};
@@ -434,12 +435,12 @@ fn bad_commit_leads_to_report() {
Event::EventStream(sender) => {
let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened {
remote: sender_id.clone(),
engine_id: GRANDPA_ENGINE_ID,
protocol: GRANDPA_PROTOCOL_NAME.into(),
role: ObservedRole::Full,
});
let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived {
remote: sender_id.clone(),
messages: vec![(GRANDPA_ENGINE_ID, commit_to_send.clone().into())],
messages: vec![(GRANDPA_PROTOCOL_NAME.into(), commit_to_send.clone().into())],
});
true