Skip to content

Commit

Permalink
Make T: Send in most traits
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Jun 19, 2024
1 parent 498fabc commit 895dc7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/net/agency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::{error::Error, marker::PhantomData};
use futures::Future;
use itertools::Itertools;

pub trait Broadcast {
pub trait Broadcast: Send {
type BroadcastError: Error + Send + 'static;
// type Error: Error + 'static;

Expand All @@ -52,12 +52,12 @@ pub trait Broadcast {
msg: T,
) -> impl Future<Output = Result<Vec<T>, Self::BroadcastError>> + Send
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync;
T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync;

/// Receive a message from a party
///
/// Returns: a message from the given party or an error
fn recv_from<T: serde::de::DeserializeOwned>(
fn recv_from<T: serde::de::DeserializeOwned + Send>(
&mut self,
idx: usize,
) -> impl Future<Output = Result<T, Self::BroadcastError>> + Send;
Expand All @@ -82,12 +82,12 @@ impl<'a, B: Broadcast> Broadcast for &'a mut B {
msg: T,
) -> impl Future<Output = Result<Vec<T>, Self::BroadcastError>> + Send
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync,
T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync,
{
(**self).symmetric_broadcast(msg)
}

fn recv_from<T: serde::de::DeserializeOwned>(
fn recv_from<T: serde::de::DeserializeOwned + Send>(
&mut self,
idx: usize,
) -> impl Future<Output = Result<T, Self::BroadcastError>> + Send {
Expand All @@ -113,7 +113,7 @@ pub trait Unicast {
/// * `msgs`: Messages to send
fn unicast(
&mut self,
msgs: &[impl serde::Serialize + Sync],
msgs: &[impl serde::Serialize + Send + Sync],
) -> impl std::future::Future<Output = Result<(), Self::UnicastError>> + Send;

/// Unicast a message to each party and await their messages
Expand All @@ -126,14 +126,14 @@ pub trait Unicast {
msgs: Vec<T>,
) -> impl Future<Output = Result<Vec<T>, Self::UnicastError>> + Send
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync;
T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync;

/// Receive a message for each party.
///
/// Asymmetric, waiting
///
/// Returns: A list sorted by the connections (skipping yourself)
fn receive_all<T: serde::de::DeserializeOwned>(
fn receive_all<T: serde::de::DeserializeOwned + Send>(
&mut self,
) -> impl Future<Output = Result<Vec<T>, Self::UnicastError>> + Send;

Expand All @@ -149,15 +149,15 @@ impl<'a, U: Unicast> Unicast for &'a mut U {
(**self).size()
}

fn receive_all<T: serde::de::DeserializeOwned>(
fn receive_all<T: serde::de::DeserializeOwned + Send>(
&mut self,
) -> impl Future<Output = Result<Vec<T>, Self::UnicastError>> + Send {
(**self).receive_all()
}

fn unicast(
&mut self,
msgs: &[impl serde::Serialize + Sync],
msgs: &[impl serde::Serialize + Send + Sync],
) -> impl std::future::Future<Output = Result<(), Self::UnicastError>> + Send {
(**self).unicast(msgs)
}
Expand All @@ -167,7 +167,7 @@ impl<'a, U: Unicast> Unicast for &'a mut U {
msgs: Vec<T>,
) -> impl Future<Output = Result<Vec<T>, Self::UnicastError>> + Send
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync,
T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync,
{
(**self).symmetric_unicast(msgs)
}
Expand Down Expand Up @@ -353,7 +353,7 @@ pub enum BroadcastVerificationError<E> {
Other(E),
}

impl<B: Broadcast, D: Digest> Broadcast for VerifiedBroadcast<B, D> {
impl<B: Broadcast, D: Digest + Send> Broadcast for VerifiedBroadcast<B, D> {
type BroadcastError = BroadcastVerificationError<<B as Broadcast>::BroadcastError>;

async fn broadcast(&mut self, msg: &impl serde::Serialize) -> Result<(), Self::BroadcastError> {
Expand Down
2 changes: 1 addition & 1 deletion src/net/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<C: SplitChannel> Unicast for Network<C> {
}

#[tracing::instrument(skip_all)]
async fn receive_all<T: serde::de::DeserializeOwned>(
async fn receive_all<T: serde::de::DeserializeOwned + Send>(
&mut self,
) -> Result<Vec<T>, Self::UnicastError> {
self.receive_all().await
Expand Down
8 changes: 6 additions & 2 deletions src/schemes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub trait Shared:
+ serde::Serialize
+ serde::de::DeserializeOwned
+ Clone
+ Send
+ Sync
{
/// The context needed to use the scheme.
Expand Down Expand Up @@ -117,6 +118,8 @@ pub trait Shared:
}
}

// NOTE: Not used currently.
//
/// Support for multiplication of two shares for producing a share.
///
/// Note, that this is different to beaver multiplication as it does not require
Expand All @@ -137,7 +140,7 @@ pub trait InteractiveMult: Shared {
net: &mut U,
a: Self,
b: Self,
) -> impl Future<Output = Result<Self, Box<dyn Error>>> + Send;
) -> impl Future<Output = Result<Self, Box<dyn Error>>>;
}

pub mod interactive {
Expand Down Expand Up @@ -300,7 +303,8 @@ pub mod interactive {
S: InteractiveShared<Error = CommunicationError, Value = V, Context = Ctx>
+ Shared<Value = V, Context = Ctx>
+ Send,
V: Send + Clone,
V: Send + Sync + Clone,
Ctx: Send + Sync,
{
type VectorShare = Vector<S>;

Expand Down
2 changes: 1 addition & 1 deletion src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn assert_holded_by<F>(shares: impl IntoIterator<Item = Share<F>>, party: us
assert_eq!(val, party, "Shares not issued to party {party}");
}

impl<F: Field + Serialize + DeserializeOwned + PartialEq + Sync> Shared for Share<F> {
impl<F: Field + Serialize + DeserializeOwned + PartialEq + Send + Sync> Shared for Share<F> {
type Context = Context;

type Value = F;
Expand Down

0 comments on commit 895dc7f

Please sign in to comment.