Skip to content

Commit

Permalink
Reduce tracing level
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Sep 4, 2024
1 parent b92eb34 commit bbe948e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/algebra/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use ff::Field;
///
/// If the rayon feature is enabled the operations will be parallelized.
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Vector<F>(Box<[F]>);
pub struct Vector<F>(pub(super) Box<[F]>);

impl<F> Vector<F> {
pub const fn from_boxed_slice(slice: Box<[F]>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod element;
pub mod field;
pub mod math;
pub mod poly;
mod rayon;
pub mod rayon;
32 changes: 24 additions & 8 deletions src/algebra/rayon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Sub, SubAssign};

use rayon::prelude::*;

use crate::algebra::math;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
struct Vector<F>(Box<[F]>);
#[repr(transparent)]
pub struct Vector<F>(math::Vector<F>);

impl<T> From<math::Vector<T>> for Vector<T> {
fn from(value: math::Vector<T>) -> Self {
Self(value)
}
}

impl<T> From<Vector<T>> for math::Vector<T> {
fn from(val: Vector<T>) -> Self {
val.0
}
}

macro_rules! inherent {
($trait2:ident, $fun2:ident, $trait1:ident, $fun1:ident) => {
Expand All @@ -13,6 +28,7 @@ macro_rules! inherent {
{
fn $fun1(&mut self, rhs: &Self) {
self.0
.0
.par_iter_mut()
.zip(rhs.0.par_iter())
.for_each(|(a, b)| $trait1::$fun1(a, b));
Expand Down Expand Up @@ -71,8 +87,8 @@ inherent!(Sub, sub, SubAssign, sub_assign);
inherent!(Div, div, DivAssign, div_assign);

impl<T: Send + Sync> super::math::Vector<T> {
fn parallelize(self) -> Vector<T> {
Vector(self.into_boxed_slice())
pub fn parallelize(self) -> Vector<T> {
Vector(self)
}
}

Expand All @@ -90,8 +106,8 @@ impl<F: Send + Sync> FromParallelIterator<F> for Vector<F> {
where
I: IntoParallelIterator<Item = F>,
{
let boxed = par_iter.into_par_iter().collect();
Self(boxed)
let boxed: Box<[_]> = par_iter.into_par_iter().collect();
Self(math::Vector(boxed))
}
}

Expand All @@ -106,7 +122,7 @@ where
{
fn mul_assign(&mut self, rhs: &B) {
let b = rhs;
self.0.par_iter_mut().for_each(|a| *a *= b);
self.0 .0.par_iter_mut().for_each(|a| *a *= b);
}
}

Expand All @@ -127,8 +143,8 @@ where

fn mul(self, rhs: B) -> Self::Output {
let b = rhs;
let internal = self.0.par_iter().map(|a| a * &b).collect();
Vector(internal)
let internal: Box<[_]> = self.0 .0.par_iter().map(|a| a * &b).collect();
Vector(math::Vector(internal))
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/net/agency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ use itertools::Itertools;

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

/// Broadcast a message to all other parties.
/// Broadcast a single message to all other parties.
///
/// * `msg`: Message to send
///
Expand All @@ -41,7 +40,7 @@ pub trait Broadcast: Send {
msg: &(impl serde::Serialize + Sync),
) -> impl std::future::Future<Output = Result<(), Self::BroadcastError>> + Send;

/// Broadcast a message to all parties and await their messages
/// Broadcast a single message to all parties and await their messages
/// Messages are ordered by their index.
///
/// This function is symmetric, and as such it is expected that all other parties
Expand Down Expand Up @@ -100,11 +99,11 @@ impl<'a, B: Broadcast> Broadcast for &'a mut B {
}
}

// TODO: Possible rename this trait as it's name is confusing.
/// Uni(que) cast to every party
pub trait Unicast {
type UnicastError: Error + Send + 'static;

/// Unicast messages to each party
/// Send a unique message to each party
///
/// Messages are supposed to be in order, meaning message `i`
/// will be send to party `i`, skipping your own index.
Expand All @@ -117,7 +116,7 @@ pub trait Unicast {
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
/// Send a unique message to each party and await their messages
/// Messages are supposed to be in order, meaning message `i`
/// will be send to party `i`.
///
Expand All @@ -129,7 +128,7 @@ pub trait Unicast {
where
T: serde::Serialize + serde::de::DeserializeOwned + Send + Sync;

/// Receive a message for each party.
/// Receive a message from each party.
///
/// Asymmetric, waiting
///
Expand Down
1 change: 0 additions & 1 deletion src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{error::Error, future::Future};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use thiserror::Error;
use tokio_util::bytes::{Bytes, BytesMut};
use tracing::instrument;

pub mod agency;
pub mod connection;
Expand Down
19 changes: 11 additions & 8 deletions src/net/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,23 @@ impl<C: SplitChannel> Network<C> {
impl<C: SplitChannel> Unicast for Network<C> {
type UnicastError = NetworkError<C::RecvError, C::SendError>;

#[tracing::instrument(skip(msgs))]
#[tracing::instrument(level = "trace", skip(msgs))]
async fn unicast(
&mut self,
msgs: &[impl serde::Serialize + Sync],
) -> Result<(), Self::UnicastError> {
self.unicast(msgs).await
}

#[tracing::instrument(skip(msgs))]
#[tracing::instrument(level = "debug", skip(msgs))]
async fn symmetric_unicast<T>(&mut self, msgs: Vec<T>) -> Result<Vec<T>, Self::UnicastError>
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync,
{
self.symmetric_unicast(msgs).await
}

#[tracing::instrument]
#[tracing::instrument(level = "trace")]
async fn receive_all<T: serde::de::DeserializeOwned + Send>(
&mut self,
) -> Result<Vec<T>, Self::UnicastError> {
Expand All @@ -420,23 +420,23 @@ impl<C: SplitChannel> Unicast for Network<C> {
impl<C: SplitChannel> Broadcast for Network<C> {
type BroadcastError = NetworkError<C::RecvError, C::SendError>;

#[tracing::instrument(skip(msg))]
#[tracing::instrument(level = "trace", skip(msg))]
async fn broadcast(
&mut self,
msg: &(impl serde::Serialize + Sync),
) -> Result<(), Self::BroadcastError> {
self.broadcast(msg).await
}

#[tracing::instrument(skip(msg))]
#[tracing::instrument(level = "trace", skip(msg))]
async fn symmetric_broadcast<T>(&mut self, msg: T) -> Result<Vec<T>, Self::BroadcastError>
where
T: serde::Serialize + serde::de::DeserializeOwned + Sync,
{
self.symmetric_broadcast(msg).await
}

#[tracing::instrument]
#[tracing::instrument(level = "trace")]
fn recv_from<T: serde::de::DeserializeOwned>(
&mut self,
id: Id,
Expand All @@ -456,7 +456,7 @@ impl<C: SplitChannel> Tuneable for Network<C> {
self.id()
}

#[tracing::instrument]
#[tracing::instrument(level = "trace")]
async fn recv_from<T: serde::de::DeserializeOwned>(
&mut self,
id: Id,
Expand All @@ -471,7 +471,7 @@ impl<C: SplitChannel> Tuneable for Network<C> {
})
}

#[tracing::instrument(skip(msg))]
#[tracing::instrument(level = "trace", skip(msg))]
async fn send_to<T: serde::Serialize + Sync>(
&mut self,
id: Id,
Expand Down Expand Up @@ -537,6 +537,7 @@ impl InMemoryNetwork {
networks
}

#[tracing::instrument(level = "trace")]
pub async fn shutdown(self) -> Result<(), std::io::Error> {
let futs = self
.connections
Expand Down Expand Up @@ -580,6 +581,7 @@ impl TcpNetwork {
///
/// * `me`: Socket address to open to
/// * `peers`: Socket addresses of other peers
#[tracing::instrument]
pub async fn connect(me: SocketAddr, peers: &[SocketAddr]) -> NetResult<Self, TcpConnection> {
let n = peers.len();

Expand Down Expand Up @@ -628,6 +630,7 @@ impl TcpNetwork {
Ok(network)
}

#[tracing::instrument]
pub async fn shutdown(self) -> Result<(), std::io::Error> {
let futs = self
.connections
Expand Down

0 comments on commit bbe948e

Please sign in to comment.