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

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

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub use substrate_network::PeerId;
const COLLATION_TIMEOUT: Duration = Duration::from_secs(30);

/// 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`.
fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>;
Expand All @@ -93,8 +93,8 @@ pub trait Network {
}

impl<P, E> Network for ValidationNetwork<P, E, NetworkService, TaskExecutor> where
P: 'static,
E: 'static,
P: 'static + Send + Sync,
E: 'static + Send + Sync,
{
fn collator_id_to_peer_id(&self, collator_id: CollatorId) ->
Box<dyn Future<Item=Option<PeerId>, Error=()> + Send>
Expand Down Expand Up @@ -438,7 +438,7 @@ pub fn run_collator<P, E, I, ArgT>(
P: BuildParachainContext + Send + 'static,
P::ParachainContext: 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,
I: IntoIterator<Item=ArgT>,
ArgT: Into<std::ffi::OsString> + Clone,
Expand Down
7 changes: 5 additions & 2 deletions test-parachains/adder/collator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const GENESIS_BODY: AdderBody = AdderBody {
#[derive(Clone)]
struct AdderContext {
db: Arc<Mutex<HashMap<AdderHead, AdderBody>>>,
/// We store it here to make sure that our interfaces require the correct bounds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly this is done to make sure our instance of Network is Send + Sync.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the code compiled before, but while integrating it into Cumulus the compiler denied it :(

_network: Option<Arc<dyn Network>>,
}

/// The parachain context.
Expand Down Expand Up @@ -99,8 +101,8 @@ impl ParachainContext for AdderContext {
impl BuildParachainContext for AdderContext {
type ParachainContext = Self;

fn build(self, _: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> {
Ok(self)
fn build(self, network: Arc<dyn Network>) -> Result<Self::ParachainContext, ()> {
Ok(Self { _network: Some(network), ..self })
}
}

Expand Down Expand Up @@ -133,6 +135,7 @@ fn main() {

let context = AdderContext {
db: Arc::new(Mutex::new(HashMap::new())),
_network: None,
};

let res = ::collator::run_collator(
Expand Down