From e818944cbe498c833ebef4920aae225055987e80 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 6 Aug 2020 10:15:21 +0200 Subject: [PATCH] Add SyncOracle to network's Service (#1543) * WIP * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * WIP Forked at: e91642361133dba084a9c9b3efa45fcb6cd3c5ca Parent branch: origin/rococo-branch * Apply suggestions from code review * Update collator/src/lib.rs * Update collator/src/lib.rs * Update network/src/protocol/mod.rs --- polkadot/Cargo.lock | 1 + polkadot/collator/src/lib.rs | 9 +++++---- polkadot/network/Cargo.toml | 1 + polkadot/network/src/protocol/mod.rs | 10 ++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index c5510f3bc3..b71a6dfc32 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -4532,6 +4532,7 @@ dependencies = [ "sc-network-gossip", "sp-api", "sp-blockchain", + "sp-consensus", "sp-core", "sp-keyring", "sp-runtime", diff --git a/polkadot/collator/src/lib.rs b/polkadot/collator/src/lib.rs index cfe4000513..070740bf7f 100644 --- a/polkadot/collator/src/lib.rs +++ b/polkadot/collator/src/lib.rs @@ -76,6 +76,7 @@ use polkadot_service_new::{ use sc_service::SpawnTaskHandle; use sp_core::traits::SpawnNamed; use sp_runtime::traits::BlakeTwo256; +use consensus_common::SyncOracle; const COLLATION_TIMEOUT: Duration = Duration::from_secs(30); @@ -120,7 +121,7 @@ pub trait BuildParachainContext { self, client: polkadot_service::Client, spawner: SP, - network: impl Network + Clone + 'static, + network: impl Network + SyncOracle + Clone + 'static, ) -> Result where SP: SpawnNamed + Clone + Send + Sync + 'static; @@ -391,7 +392,7 @@ where .into()); } - let (task_manager, client, handlers) = polkadot_service::build_full( + let (task_manager, client, handles) = polkadot_service::build_full( config, Some((key.public(), para_id)), None, @@ -402,11 +403,11 @@ where let future = build_collator_service( task_manager.spawn_handle(), - handlers, + handles, client, para_id, key, - build_parachain_context + build_parachain_context, )?; Ok((future, task_manager)) diff --git a/polkadot/network/Cargo.toml b/polkadot/network/Cargo.toml index 6685bbb382..748bc20c09 100644 --- a/polkadot/network/Cargo.toml +++ b/polkadot/network/Cargo.toml @@ -17,6 +17,7 @@ polkadot-erasure-coding = { path = "../erasure-coding" } codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network-gossip = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = "0.3.5" diff --git a/polkadot/network/src/protocol/mod.rs b/polkadot/network/src/protocol/mod.rs index 6dfef09da8..2626a5a373 100644 --- a/polkadot/network/src/protocol/mod.rs +++ b/polkadot/network/src/protocol/mod.rs @@ -1488,6 +1488,16 @@ impl av_store::ErasureNetworking for Service { } } +impl sp_consensus::SyncOracle for Service where for<'r> &'r N: sp_consensus::SyncOracle { + fn is_major_syncing(&mut self) -> bool { + self.network_service.is_major_syncing() + } + + fn is_offline(&mut self) -> bool { + self.network_service.is_offline() + } +} + /// Errors when interacting with the statement router. #[derive(Debug, derive_more::Display, derive_more::From)] pub enum RouterError {