Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit f4d4244

Browse files
tomakaandresilva
andauthored
Remove sc_network::NetworkService::register_notifications_protocol and partially refactor Grandpa tests (#7646)
* Remove sc_network::NetworkService::register_notifications_protocol * Missing calls to .into() * Wrong crate name * [WIP] Fix Grandpa tests * One more passing * One more. Two to go. * This one was actually already passing 🎉 * Last one compiles * Progress * grandpa: fix voter_persists_its_votes test * Restore other tests * Try spawn future later Co-authored-by: André Silva <[email protected]>
1 parent 77f1089 commit f4d4244

File tree

12 files changed

+293
-364
lines changed

12 files changed

+293
-364
lines changed

bin/node-template/node/src/service.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
7979
}
8080

8181
/// Builds a new service for a full client.
82-
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
82+
pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError> {
8383
let sc_service::PartialComponents {
8484
client, backend, mut task_manager, import_queue, keystore_container,
8585
select_chain, transaction_pool, inherent_data_providers,
8686
other: (block_import, grandpa_link),
8787
} = new_partial(&config)?;
8888

89+
config.network.notifications_protocols.push(sc_finality_grandpa::GRANDPA_PROTOCOL_NAME.into());
90+
8991
let (network, network_status_sinks, system_rpc_tx, network_starter) =
9092
sc_service::build_network(sc_service::BuildNetworkParams {
9193
config: &config,
@@ -210,19 +212,19 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
210212
"grandpa-voter",
211213
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?
212214
);
213-
} else {
214-
sc_finality_grandpa::setup_disabled_grandpa(network)?;
215215
}
216216

217217
network_starter.start_network();
218218
Ok(task_manager)
219219
}
220220

221221
/// Builds a new service for a light client.
222-
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
222+
pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError> {
223223
let (client, backend, keystore_container, mut task_manager, on_demand) =
224224
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
225225

226+
config.network.notifications_protocols.push(sc_finality_grandpa::GRANDPA_PROTOCOL_NAME.into());
227+
226228
let select_chain = sc_consensus::LongestChain::new(backend.clone());
227229

228230
let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(

bin/node/cli/src/service.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub struct NewFullBase {
164164

165165
/// Creates a full service from the configuration.
166166
pub fn new_full_base(
167-
config: Configuration,
167+
mut config: Configuration,
168168
with_startup_data: impl FnOnce(
169169
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
170170
&sc_consensus_babe::BabeLink<Block>,
@@ -178,6 +178,8 @@ pub fn new_full_base(
178178

179179
let shared_voter_state = rpc_setup;
180180

181+
config.network.notifications_protocols.push(grandpa::GRANDPA_PROTOCOL_NAME.into());
182+
181183
let (network, network_status_sinks, system_rpc_tx, network_starter) =
182184
sc_service::build_network(sc_service::BuildNetworkParams {
183185
config: &config,
@@ -315,8 +317,6 @@ pub fn new_full_base(
315317
"grandpa-voter",
316318
grandpa::run_grandpa_voter(grandpa_config)?
317319
);
318-
} else {
319-
grandpa::setup_disabled_grandpa(network.clone())?;
320320
}
321321

322322
network_starter.start_network();
@@ -338,14 +338,16 @@ pub fn new_full(config: Configuration)
338338
})
339339
}
340340

341-
pub fn new_light_base(config: Configuration) -> Result<(
341+
pub fn new_light_base(mut config: Configuration) -> Result<(
342342
TaskManager, RpcHandlers, Arc<LightClient>,
343343
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
344344
Arc<sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>>
345345
), ServiceError> {
346346
let (client, backend, keystore_container, mut task_manager, on_demand) =
347347
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
348348

349+
config.network.notifications_protocols.push(grandpa::GRANDPA_PROTOCOL_NAME.into());
350+
349351
let select_chain = sc_consensus::LongestChain::new(backend.clone());
350352

351353
let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(

client/finality-grandpa/src/communication/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ mod periodic;
6868
#[cfg(test)]
6969
pub(crate) mod tests;
7070

71+
/// Name of the notifications protocol used by Grandpa. Must be registered towards the networking
72+
/// in order for Grandpa to properly function.
7173
pub const GRANDPA_PROTOCOL_NAME: &'static str = "/paritytech/grandpa/1";
7274

7375
// cost scalars for reporting peers.

client/finality-grandpa/src/communication/tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ impl sc_network_gossip::Network<Block> for TestNetwork {
6262
let _ = self.sender.unbounded_send(Event::WriteNotification(who, message));
6363
}
6464

65-
fn register_notifications_protocol(&self, _: Cow<'static, str>) {}
66-
6765
fn announce(&self, block: Hash, _associated_data: Vec<u8>) {
6866
let _ = self.sender.unbounded_send(Event::Announce(block));
6967
}

client/finality-grandpa/src/lib.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ mod until_imported;
122122
mod voting_rule;
123123

124124
pub use authorities::{SharedAuthoritySet, AuthoritySet};
125+
pub use communication::GRANDPA_PROTOCOL_NAME;
125126
pub use finality_proof::{FinalityProofFragment, FinalityProofProvider, StorageAndProofProvider};
126127
pub use notification::{GrandpaJustificationSender, GrandpaJustificationStream};
127128
pub use import::GrandpaBlockImport;
@@ -652,6 +653,10 @@ pub struct GrandpaParams<Block: BlockT, C, N, SC, VR> {
652653
/// A link to the block import worker.
653654
pub link: LinkHalf<Block, C, SC>,
654655
/// The Network instance.
656+
///
657+
/// It is assumed that this network will feed us Grandpa notifications. When using the
658+
/// `sc_network` crate, it is assumed that the Grandpa notifications protocol has been passed
659+
/// to the configuration of the networking.
655660
pub network: N,
656661
/// If supplied, can be used to hook on telemetry connection established events.
657662
pub telemetry_on_connect: Option<TracingUnboundedReceiver<()>>,
@@ -1065,26 +1070,6 @@ where
10651070
}
10661071
}
10671072

1068-
/// When GRANDPA is not initialized we still need to register the finality
1069-
/// tracker inherent provider which might be expected by the runtime for block
1070-
/// authoring. Additionally, we register a gossip message validator that
1071-
/// discards all GRANDPA messages (otherwise, we end up banning nodes that send
1072-
/// us a `Neighbor` message, since there is no registered gossip validator for
1073-
/// the engine id defined in the message.)
1074-
pub fn setup_disabled_grandpa<Block: BlockT, N>(network: N) -> Result<(), sp_consensus::Error>
1075-
where
1076-
N: NetworkT<Block> + Send + Clone + 'static,
1077-
{
1078-
// We register the GRANDPA protocol so that we don't consider it an anomaly
1079-
// to receive GRANDPA messages on the network. We don't process the
1080-
// messages.
1081-
network.register_notifications_protocol(
1082-
From::from(communication::GRANDPA_PROTOCOL_NAME),
1083-
);
1084-
1085-
Ok(())
1086-
}
1087-
10881073
/// Checks if this node has any available keys in the keystore for any authority id in the given
10891074
/// voter set. Returns the authority id for which keys are available, or `None` if no keys are
10901075
/// available.

0 commit comments

Comments
 (0)