Skip to content

Commit c3e99e3

Browse files
authored
Make collator::Network require Send + Sync to make it work (paritytech#316)
1 parent a5b223a commit c3e99e3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

collator/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub use substrate_network::PeerId;
7979
const COLLATION_TIMEOUT: Duration = Duration::from_secs(30);
8080

8181
/// An abstraction over the `Network` with useful functions for a `Collator`.
82-
pub trait Network {
82+
pub trait Network: Send + Sync {
8383
/// Convert the given `CollatorId` to a `PeerId`.
8484
fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
8585
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>;
@@ -93,8 +93,8 @@ pub trait Network {
9393
}
9494

9595
impl<P, E> Network for ValidationNetwork<P, E, NetworkService, TaskExecutor> where
96-
P: 'static,
97-
E: 'static,
96+
P: 'static + Send + Sync,
97+
E: 'static + Send + Sync,
9898
{
9999
fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
100100
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>
@@ -438,7 +438,7 @@ pub fn run_collator<P, E, I, ArgT>(
438438
P: BuildParachainContext + Send + 'static,
439439
P::ParachainContext: Send + 'static,
440440
<<P::ParachainContext as ParachainContext>::ProduceCandidate as IntoFuture>::Future: Send + 'static,
441-
E: IntoFuture<Item=(),Error=()>,
441+
E: IntoFuture<Item=(), Error=()>,
442442
E::Future: Send + Clone + Sync + 'static,
443443
I: IntoIterator<Item=ArgT>,
444444
ArgT: Into<std::ffi::OsString> + Clone,

test-parachains/adder/collator/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const GENESIS_BODY: AdderBody = AdderBody {
4747
#[derive(Clone)]
4848
struct AdderContext {
4949
db: Arc<Mutex<HashMap<AdderHead, AdderBody>>>,
50+
/// We store it here to make sure that our interfaces require the correct bounds.
51+
_network: Option<Arc<dyn Network>>,
5052
}
5153

5254
/// The parachain context.
@@ -99,8 +101,8 @@ impl ParachainContext for AdderContext {
99101
impl BuildParachainContext for AdderContext {
100102
type ParachainContext = Self;
101103

102-
fn build(self, _: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> {
103-
Ok(self)
104+
fn build(self, network: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> {
105+
Ok(Self { _network: Some(network), ..self })
104106
}
105107
}
106108

@@ -133,6 +135,7 @@ fn main() {
133135

134136
let context = AdderContext {
135137
db: Arc::new(Mutex::new(HashMap::new())),
138+
_network: None,
136139
};
137140

138141
let res = ::collator::run_collator(

0 commit comments

Comments
 (0)