Skip to content

Commit

Permalink
Add missing Debug lints and missing impls/constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Oct 24, 2024
1 parent 0d422b5 commit 3dd03c3
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 16 deletions.
3 changes: 3 additions & 0 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ pub struct Inputs<Id> {
pub all_ids: BTreeSet<Id>,
}

#[derive(Debug)]
pub(crate) struct Context<Id> {
pub(crate) id: Id,
pub(crate) other_ids: BTreeSet<Id>,
pub(crate) ids_to_positions: BTreeMap<Id, u8>,
}

#[derive(Debug)]
pub struct Round1<Id> {
pub(crate) context: Context<Id>,
}
Expand Down Expand Up @@ -246,6 +248,7 @@ impl<Id: 'static + Debug + Clone + Ord + Send + Sync> Round<Id> for Round1<Id> {
}
}

#[derive(Debug)]
pub(crate) struct Round2<Id> {
round1_sum: u8,
pub(crate) context: Context<Id>,
Expand Down
2 changes: 2 additions & 0 deletions examples/src/simple_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct MaliciousInputs<Id> {
behavior: Behavior,
}

#[derive(Debug)]
struct MaliciousRound1<Id> {
round: Round1<Id>,
behavior: Behavior,
Expand Down Expand Up @@ -105,6 +106,7 @@ impl<Id: 'static + Debug + Clone + Ord + Send + Sync> RoundOverride<Id> for Mali

round_override!(MaliciousRound1);

#[derive(Debug)]
struct MaliciousRound2<Id> {
round: Round2<Id>,
behavior: Behavior,
Expand Down
3 changes: 2 additions & 1 deletion manul/benches/empty_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ impl Protocol for EmptyProtocol {
}
}

#[derive(Debug)]
struct EmptyRound<Id> {
round_counter: u8,
inputs: Inputs<Id>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
struct Inputs<Id> {
rounds_num: u8,
echo: bool,
Expand Down
3 changes: 2 additions & 1 deletion manul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_qualifications
unused_qualifications,
missing_debug_implementations
)]

extern crate alloc;
Expand Down
1 change: 1 addition & 0 deletions manul/src/protocol/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ where
}

/// An error that can occur during [`Round::finalize`](`super::Round::finalize`).
#[derive(Debug)]
pub enum FinalizeError<P: Protocol> {
/// A local error, usually indicating a bug in the implementation.
Local(LocalError),
Expand Down
10 changes: 6 additions & 4 deletions manul/src/protocol/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloc::{
collections::{BTreeMap, BTreeSet},
format,
};
use core::marker::PhantomData;
use core::{fmt::Debug, marker::PhantomData};

use rand_core::{CryptoRng, CryptoRngCore, RngCore};

Expand Down Expand Up @@ -37,7 +37,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 {
pub(crate) trait ObjectSafeRound<Id>: 'static + Send + Sync + Debug {
type Protocol: Protocol;

fn id(&self) -> RoundId;
Expand Down Expand Up @@ -75,7 +75,9 @@ pub(crate) trait ObjectSafeRound<Id>: 'static + Send + Sync {
fn get_type_id(&self) -> core::any::TypeId;
}

// The `fn(Id) -> Id` bit is so that `ObjectSafeRoundWrapper` didn't require a bound on `Id` to be `Send + Sync`.
// The `fn(Id) -> Id` bit is so that `ObjectSafeRoundWrapper` didn't require a bound on `Id` to be
// `Send + Sync`.
#[derive(Debug)]
pub(crate) struct ObjectSafeRoundWrapper<Id, R> {
round: R,
phantom: PhantomData<fn(Id) -> Id>,
Expand All @@ -92,7 +94,7 @@ impl<Id: 'static, R: Round<Id>> ObjectSafeRoundWrapper<Id, R> {

impl<Id, R> ObjectSafeRound<Id> for ObjectSafeRoundWrapper<Id, R>
where
Id: 'static,
Id: 'static + Debug,
R: Round<Id>,
{
type Protocol = <R as Round<Id>>::Protocol;
Expand Down
12 changes: 7 additions & 5 deletions manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::{
use crate::session::SessionId;

/// Possible successful outcomes of [`Round::finalize`].
#[derive(Debug)]
pub enum FinalizeOutcome<Id, P: Protocol> {
/// Transition to a new round.
AnotherRound(AnotherRound<Id, P>),
Expand All @@ -29,7 +30,7 @@ pub enum FinalizeOutcome<Id, P: Protocol> {

impl<Id, P> FinalizeOutcome<Id, P>
where
Id: 'static,
Id: 'static + Debug,
P: 'static + Protocol,
{
/// A helper method to create an [`AnotherRound`](`Self::AnotherRound`) variant.
Expand All @@ -40,11 +41,12 @@ where

// We do not want to expose `ObjectSafeRound` to the user, so it is hidden in a struct.
/// A wrapped new round that may be returned by [`Round::finalize`].
#[derive(Debug)]
pub struct AnotherRound<Id, P: Protocol>(Box<dyn ObjectSafeRound<Id, Protocol = P>>);

impl<Id, P> AnotherRound<Id, P>
where
Id: 'static,
Id: 'static + Debug,
P: 'static + Protocol,
{
/// Wraps an object implementing [`Round`].
Expand Down Expand Up @@ -119,15 +121,15 @@ impl RoundId {
/// A distributed protocol.
pub trait Protocol: Debug + Sized {
/// The successful result of an execution of this protocol.
type Result;
type Result: Debug;

/// An object of this type will be returned when a provable error happens during [`Round::receive_message`].
type ProtocolError: ProtocolError + Serialize + for<'de> Deserialize<'de>;

/// An object of this type will be returned when an unattributable error happens during [`Round::finalize`].
///
/// It proves that the node did its job correctly, to be adjudicated by a third party.
type CorrectnessProof: Send + Serialize + for<'de> Deserialize<'de>;
type CorrectnessProof: Send + Serialize + for<'de> Deserialize<'de> + Debug;

/// Serializes the given object into a bytestring.
fn serialize<T: Serialize>(value: T) -> Result<Box<[u8]>, LocalError>;
Expand Down Expand Up @@ -360,7 +362,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 {
pub trait Round<Id>: 'static + Send + Sync + Debug {
/// The protocol this round is a part of.
type Protocol: Protocol;

Expand Down
3 changes: 2 additions & 1 deletion manul/src/session/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct EchoRoundMessage<SP: SessionParameters> {
pub(crate) echo_messages: SerializableMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
}

#[derive(Debug)]
pub struct EchoRound<P, SP: SessionParameters> {
verifier: SP::Verifier,
echo_messages: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
Expand Down Expand Up @@ -82,7 +83,7 @@ where
impl<P, SP> Round<SP::Verifier> for EchoRound<P, SP>
where
P: 'static + Protocol,
SP: 'static + SessionParameters,
SP: 'static + SessionParameters + Debug,
{
type Protocol = P;

Expand Down
8 changes: 6 additions & 2 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::protocol::{
/// is used in the network in which they are running the protocol.
pub trait SessionParameters {
/// The signer type.
type Signer: RandomizedDigestSigner<Self::Digest, Self::Signature> + Keypair<VerifyingKey = Self::Verifier>;
type Signer: Debug + RandomizedDigestSigner<Self::Digest, Self::Signature> + Keypair<VerifyingKey = Self::Verifier>;

/// The hash type that will be used to pre-hash message payloads before signing.
type Digest: Digest;
Expand Down Expand Up @@ -81,6 +81,7 @@ impl AsRef<[u8]> for SessionId {

/// An object encapsulating the currently active round, transport protocol,
/// and the database of messages and errors from the previous rounds.
#[derive(Debug)]
pub struct Session<P: Protocol, SP: SessionParameters> {
session_id: SessionId,
signer: SP::Signer,
Expand All @@ -93,6 +94,7 @@ pub struct Session<P: Protocol, SP: SessionParameters> {
}

/// Possible non-erroneous results of finalizing a round.
#[derive(Debug)]
pub enum RoundOutcome<P: Protocol, SP: SessionParameters> {
/// The execution is finished.
Finished(SessionReport<P, SP>),
Expand All @@ -108,7 +110,7 @@ pub enum RoundOutcome<P: Protocol, SP: SessionParameters> {
impl<P, SP> Session<P, SP>
where
P: 'static + Protocol,
SP: 'static + SessionParameters,
SP: 'static + SessionParameters + Debug,
{
/// Initializes a new session.
pub fn new<R>(
Expand Down Expand Up @@ -657,11 +659,13 @@ where
}
}

#[derive(Debug)]
pub struct ProcessedArtifact<SP: SessionParameters> {
destination: SP::Verifier,
artifact: Artifact,
}

#[derive(Debug)]
pub struct ProcessedMessage<P: Protocol, SP: SessionParameters> {
message: VerifiedMessageBundle<SP>,
processed: Result<Payload, ReceiveError<SP::Verifier, P>>,
Expand Down
2 changes: 2 additions & 0 deletions manul/src/session/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::fmt::Debug;
use super::{evidence::Evidence, message::SignedMessage, session::SessionParameters, LocalError, RemoteError};
use crate::protocol::{DirectMessage, EchoBroadcast, Protocol, RoundId};

#[derive(Debug)]
pub(crate) struct Transcript<P: Protocol, SP: SessionParameters> {
echo_broadcasts: BTreeMap<RoundId, BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>>,
direct_messages: BTreeMap<RoundId, BTreeMap<SP::Verifier, SignedMessage<DirectMessage>>>,
Expand Down Expand Up @@ -152,6 +153,7 @@ pub enum SessionOutcome<P: Protocol> {
}

/// The report of a session execution.
#[derive(Debug)]
pub struct SessionReport<P: Protocol, SP: SessionParameters> {
/// The session outcome.
pub outcome: SessionOutcome<P>,
Expand Down
1 change: 1 addition & 0 deletions manul/src/testing/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ macro_rules! round_override {
($round: ident) => {
impl<Id> Round<Id> for $round<Id>
where
Id: Debug,
$round<Id>: RoundOverride<Id>,
{
type Protocol =
Expand Down
6 changes: 4 additions & 2 deletions manul/src/testing/run_sync.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Debug;

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

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

Expand Down Expand Up @@ -95,7 +97,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,
SP: 'static + SessionParameters + Debug,
{
let session_id = SessionId::random(rng);

Expand Down

0 comments on commit 3dd03c3

Please sign in to comment.