Unverified Commit c3e99e3a authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Make `collator::Network` require `Send + Sync` to make it work (#316)

parent a5b223a0
Pipeline #42416 passed with stages
in 13 minutes and 59 seconds
...@@ -79,7 +79,7 @@ pub use substrate_network::PeerId; ...@@ -79,7 +79,7 @@ pub use substrate_network::PeerId;
const COLLATION_TIMEOUT: Duration = Duration::from_secs(30); const COLLATION_TIMEOUT: Duration = Duration::from_secs(30);
/// An abstraction over the `Network` with useful functions for a `Collator`. /// An abstraction over the `Network` with useful functions for a `Collator`.
pub trait Network { pub trait Network: Send + Sync {
/// Convert the given `CollatorId` to a `PeerId`. /// Convert the given `CollatorId` to a `PeerId`.
fn collator_id_to_peer_id(&self, collator_id: CollatorId) -> fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>; Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>;
...@@ -93,8 +93,8 @@ pub trait Network { ...@@ -93,8 +93,8 @@ pub trait Network {
} }
impl<P, E> Network for ValidationNetwork<P, E, NetworkService, TaskExecutor> where impl<P, E> Network for ValidationNetwork<P, E, NetworkService, TaskExecutor> where
P: 'static, P: 'static + Send + Sync,
E: 'static, E: 'static + Send + Sync,
{ {
fn collator_id_to_peer_id(&self, collator_id: CollatorId) -> fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send> Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>
...@@ -438,7 +438,7 @@ pub fn run_collator<P, E, I, ArgT>( ...@@ -438,7 +438,7 @@ pub fn run_collator<P, E, I, ArgT>(
P: BuildParachainContext + Send + 'static, P: BuildParachainContext + Send + 'static,
P::ParachainContext: Send + 'static, P::ParachainContext: Send + 'static,
<<P::ParachainContext as ParachainContext>::ProduceCandidate as IntoFuture>::Future: Send + 'static, <<P::ParachainContext as ParachainContext>::ProduceCandidate as IntoFuture>::Future: Send + 'static,
E: IntoFuture<Item=(),Error=()>, E: IntoFuture<Item=(), Error=()>,
E::Future: Send + Clone + Sync + 'static, E::Future: Send + Clone + Sync + 'static,
I: IntoIterator<Item=ArgT>, I: IntoIterator<Item=ArgT>,
ArgT: Into<std::ffi::OsString> + Clone, ArgT: Into<std::ffi::OsString> + Clone,
......
...@@ -47,6 +47,8 @@ const GENESIS_BODY: AdderBody = AdderBody { ...@@ -47,6 +47,8 @@ const GENESIS_BODY: AdderBody = AdderBody {
#[derive(Clone)] #[derive(Clone)]
struct AdderContext { struct AdderContext {
db: Arc<Mutex<HashMap<AdderHead, AdderBody>>>, db: Arc<Mutex<HashMap<AdderHead, AdderBody>>>,
/// We store it here to make sure that our interfaces require the correct bounds.
_network: Option<Arc<dyn Network>>,
} }
/// The parachain context. /// The parachain context.
...@@ -99,8 +101,8 @@ impl ParachainContext for AdderContext { ...@@ -99,8 +101,8 @@ impl ParachainContext for AdderContext {
impl BuildParachainContext for AdderContext { impl BuildParachainContext for AdderContext {
type ParachainContext = Self; type ParachainContext = Self;
fn build(self, _: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> { fn build(self, network: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> {
Ok(self) Ok(Self { _network: Some(network), ..self })
} }
} }
...@@ -133,6 +135,7 @@ fn main() { ...@@ -133,6 +135,7 @@ fn main() {
let context = AdderContext { let context = AdderContext {
db: Arc::new(Mutex::new(HashMap::new())), db: Arc::new(Mutex::new(HashMap::new())),
_network: None,
}; };
let res = ::collator::run_collator( let res = ::collator::run_collator(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment