Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less bounds #53

Merged
merged 2 commits into from
Oct 30, 2024
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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rand_core::CryptoRngCore;
use serde::{Deserialize, Serialize};
use tracing::debug;

#[derive(Debug)]
pub struct SimpleProtocol;

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
8 changes: 3 additions & 5 deletions examples/tests/async_runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
extern crate alloc;

use std::fmt::Debug;

use alloc::collections::{BTreeMap, BTreeSet};

use manul::{
Expand Down Expand Up @@ -41,7 +39,7 @@ async fn run_session<P, SP>(
) -> Result<SessionReport<P, SP>, LocalError>
where
P: Protocol,
SP: SessionParameters + Debug,
SP: SessionParameters,
{
let rng = &mut OsRng;

Expand Down Expand Up @@ -155,7 +153,7 @@ async fn message_dispatcher<SP>(
txs: BTreeMap<SP::Verifier, mpsc::Sender<MessageIn<SP>>>,
rx: mpsc::Receiver<MessageOut<SP>>,
) where
SP: SessionParameters + Debug,
SP: SessionParameters,
{
let mut rx = rx;
let mut messages = Vec::<MessageOut<SP>>::new();
Expand Down Expand Up @@ -197,7 +195,7 @@ async fn message_dispatcher<SP>(
async fn run_nodes<P, SP>(sessions: Vec<Session<P, SP>>) -> Vec<SessionReport<P, SP>>
where
P: Protocol + Send,
SP: SessionParameters + Debug,
SP: SessionParameters,
P::Result: Send,
SP::Signer: Send,
{
Expand Down
1 change: 1 addition & 0 deletions manul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ signature = { version = "2", default-features = false, features = ["digest", "ra
rand_core = { version = "0.6.4", default-features = false }
tracing = { version = "0.1", default-features = false }
displaydoc = { version = "0.2", default-features = false }
derive-where = "1"

rand = { version = "0.8", default-features = false, optional = true }
serde-persistent-deserializer = { version = "0.3", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions manul/src/protocol/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl RngCore for BoxedRng<'_> {
// Since we want `Round` methods to take `&mut impl CryptoRngCore` arguments
// (which is what all cryptographic libraries generally take), it cannot be object-safe.
// Thus we have to add this crate-private object-safe layer on top of `Round`.
pub(crate) trait ObjectSafeRound<Id>: 'static + Send + Sync + Debug {
pub(crate) trait ObjectSafeRound<Id>: 'static + Debug + Send + Sync {
type Protocol: Protocol;

fn id(&self) -> RoundId;
Expand Down Expand Up @@ -204,7 +204,7 @@ where
impl<Id, P> dyn ObjectSafeRound<Id, Protocol = P>
where
Id: 'static,
P: 'static + Protocol,
P: Protocol,
{
pub fn try_downcast<T: Round<Id>>(self: Box<Self>) -> Result<T, Box<Self>> {
if core::any::TypeId::of::<ObjectSafeRoundWrapper<Id, T>>() == self.get_type_id() {
Expand Down
6 changes: 3 additions & 3 deletions manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl RoundId {
}

/// A distributed protocol.
pub trait Protocol: 'static + Debug + Sized {
pub trait Protocol: 'static + Sized {
/// The successful result of an execution of this protocol.
type Result: Debug;

Expand Down Expand Up @@ -289,7 +289,7 @@ impl Artifact {
///
/// This is a round that can be created directly;
/// all the others are only reachable throud [`Round::finalize`] by the execution layer.
pub trait FirstRound<Id: 'static>: Round<Id> + Sized {
pub trait FirstRound<Id>: Round<Id> + Sized {
/// Additional inputs for the protocol (besides the mandatory ones in [`new`](`Self::new`)).
type Inputs;

Expand All @@ -314,7 +314,7 @@ The way a round will be used by an external caller:
- process received messages from other nodes (by calling [`receive_message`](`Self::receive_message`));
- attempt to finalize (by calling [`finalize`](`Self::finalize`)) to produce the next round, or return a result.
*/
pub trait Round<Id>: 'static + Send + Sync + Debug {
pub trait Round<Id>: 'static + Debug + Send + Sync {
/// The protocol this round is a part of.
type Protocol: Protocol;

Expand Down
8 changes: 4 additions & 4 deletions manul/src/session/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) struct EchoRoundMessage<SP: SessionParameters> {
/// Each protocol round can contain one `EchoRound` with "echo messages" that are sent to all
/// participants. The execution layer of the protocol guarantees that all participants have received
/// the messages.
#[derive(Debug)]
#[derive_where::derive_where(Debug)]
pub struct EchoRound<P, SP: SessionParameters> {
verifier: SP::Verifier,
echo_broadcasts: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
Expand All @@ -75,7 +75,7 @@ pub struct EchoRound<P, SP: SessionParameters> {
impl<P, SP> EchoRound<P, SP>
where
P: Protocol,
SP: SessionParameters + Debug,
SP: SessionParameters,
{
pub fn new(
verifier: SP::Verifier,
Expand Down Expand Up @@ -109,8 +109,8 @@ where

impl<P, SP> Round<SP::Verifier> for EchoRound<P, SP>
where
P: 'static + Protocol,
SP: 'static + SessionParameters + Debug,
P: Protocol,
SP: SessionParameters,
{
type Protocol = P;

Expand Down
21 changes: 14 additions & 7 deletions manul/src/session/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ impl From<ProtocolValidationError> for EvidenceError {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Evidence<P: Protocol, SP: SessionParameters> {
guilty_party: SP::Verifier,
description: String,
Expand Down Expand Up @@ -246,7 +247,8 @@ where
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
enum EvidenceEnum<P: Protocol, SP: SessionParameters> {
Protocol(ProtocolEvidence<P>),
InvalidDirectMessage(InvalidDirectMessageEvidence<P>),
Expand All @@ -256,7 +258,8 @@ enum EvidenceEnum<P: Protocol, SP: SessionParameters> {
MismatchedBroadcasts(MismatchedBroadcastsEvidence),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
pub struct InvalidEchoPackEvidence<SP: SessionParameters> {
normal_broadcast: SignedMessage<NormalBroadcast>,
invalid_echo_sender: SP::Verifier,
Expand Down Expand Up @@ -324,7 +327,8 @@ impl MismatchedBroadcastsEvidence {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
pub struct InvalidDirectMessageEvidence<P: Protocol> {
direct_message: SignedMessage<DirectMessage>,
phantom: core::marker::PhantomData<P>,
Expand All @@ -347,7 +351,8 @@ where
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
pub struct InvalidEchoBroadcastEvidence<P: Protocol> {
echo_broadcast: SignedMessage<EchoBroadcast>,
phantom: core::marker::PhantomData<P>,
Expand All @@ -370,7 +375,8 @@ where
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
pub struct InvalidNormalBroadcastEvidence<P: Protocol> {
normal_broadcast: SignedMessage<NormalBroadcast>,
phantom: core::marker::PhantomData<P>,
Expand All @@ -392,7 +398,8 @@ where
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive_where::derive_where(Debug)]
#[derive(Clone, Serialize, Deserialize)]
struct ProtocolEvidence<P: Protocol> {
error: P::ProtocolError,
direct_message: SignedMessage<DirectMessage>,
Expand Down
3 changes: 2 additions & 1 deletion manul/src/session/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ impl CheckedMessageBundle {
/// A `VerifiedMessageBundle` is the final evolution of a [`MessageBundle`]. At this point in the
/// process, the [`DirectMessage`] and an eventual [`EchoBroadcast`] have been fully checked and the
/// signature on the [`SignedMessage`] from the original [`MessageBundle`] successfully verified.
#[derive(Clone, Debug)]
#[derive_where::derive_where(Debug)]
#[derive(Clone)]
pub struct VerifiedMessageBundle<SP: SessionParameters> {
from: SP::Verifier,
metadata: MessageMetadata,
Expand Down
5 changes: 2 additions & 3 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub enum RoundOutcome<P: Protocol, SP: SessionParameters> {
impl<P, SP> Session<P, SP>
where
P: Protocol,
SP: SessionParameters + Debug,
SP: SessionParameters,
{
/// Initializes a new session.
pub fn new<R>(
Expand Down Expand Up @@ -538,7 +538,7 @@ pub enum CanFinalize {
}

/// A mutable accumulator for collecting the results and errors from processing messages for a single round.
#[derive(Debug)]
#[derive_where::derive_where(Debug)]
pub struct RoundAccumulator<P: Protocol, SP: SessionParameters> {
still_have_not_sent_messages: BTreeSet<SP::Verifier>,
expecting_messages_from: BTreeSet<SP::Verifier>,
Expand Down Expand Up @@ -795,7 +795,6 @@ mod tests {
// Send/Sync. But we want to make sure that if the generic parameters are
// Send/Sync, our types are too.

#[derive(Debug)]
struct DummyProtocol;

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
6 changes: 2 additions & 4 deletions manul/src/testing/run_sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::fmt::Debug;

use alloc::{collections::BTreeMap, vec::Vec};

use rand::Rng;
Expand Down Expand Up @@ -37,7 +35,7 @@ fn propagate<P, SP>(
) -> Result<(State<P, SP>, Vec<Message<SP>>), LocalError>
where
P: 'static + Protocol,
SP: 'static + SessionParameters + Debug,
SP: 'static + SessionParameters,
{
let mut messages = Vec::new();

Expand Down Expand Up @@ -97,7 +95,7 @@ pub fn run_sync<R, SP>(
) -> Result<BTreeMap<SP::Verifier, SessionReport<R::Protocol, SP>>, LocalError>
where
R: 'static + FirstRound<SP::Verifier>,
SP: 'static + SessionParameters + Debug,
SP: 'static + SessionParameters,
{
let session_id = SessionId::random::<SP>(rng);

Expand Down
Loading