From 3dd03c3fcf12ed87d30743b1d9ea0f75ac1b8b64 Mon Sep 17 00:00:00 2001 From: David Palm Date: Thu, 24 Oct 2024 09:48:25 +0200 Subject: [PATCH] Add missing Debug lints and missing impls/constraints --- examples/src/simple.rs | 3 +++ examples/src/simple_malicious.rs | 2 ++ manul/benches/empty_rounds.rs | 3 ++- manul/src/lib.rs | 3 ++- manul/src/protocol/errors.rs | 1 + manul/src/protocol/object_safe.rs | 10 ++++++---- manul/src/protocol/round.rs | 12 +++++++----- manul/src/session/echo.rs | 3 ++- manul/src/session/session.rs | 8 ++++++-- manul/src/session/transcript.rs | 2 ++ manul/src/testing/macros.rs | 1 + manul/src/testing/run_sync.rs | 6 ++++-- 12 files changed, 38 insertions(+), 16 deletions(-) diff --git a/examples/src/simple.rs b/examples/src/simple.rs index 51f1cfc..3cd6f7c 100644 --- a/examples/src/simple.rs +++ b/examples/src/simple.rs @@ -99,12 +99,14 @@ pub struct Inputs { pub all_ids: BTreeSet, } +#[derive(Debug)] pub(crate) struct Context { pub(crate) id: Id, pub(crate) other_ids: BTreeSet, pub(crate) ids_to_positions: BTreeMap, } +#[derive(Debug)] pub struct Round1 { pub(crate) context: Context, } @@ -246,6 +248,7 @@ impl Round for Round1 { } } +#[derive(Debug)] pub(crate) struct Round2 { round1_sum: u8, pub(crate) context: Context, diff --git a/examples/src/simple_malicious.rs b/examples/src/simple_malicious.rs index e7e73da..33bcad3 100644 --- a/examples/src/simple_malicious.rs +++ b/examples/src/simple_malicious.rs @@ -26,6 +26,7 @@ struct MaliciousInputs { behavior: Behavior, } +#[derive(Debug)] struct MaliciousRound1 { round: Round1, behavior: Behavior, @@ -105,6 +106,7 @@ impl RoundOverride for Mali round_override!(MaliciousRound1); +#[derive(Debug)] struct MaliciousRound2 { round: Round2, behavior: Behavior, diff --git a/manul/benches/empty_rounds.rs b/manul/benches/empty_rounds.rs index f0612b2..4b9135c 100644 --- a/manul/benches/empty_rounds.rs +++ b/manul/benches/empty_rounds.rs @@ -51,12 +51,13 @@ impl Protocol for EmptyProtocol { } } +#[derive(Debug)] struct EmptyRound { round_counter: u8, inputs: Inputs, } -#[derive(Clone)] +#[derive(Debug, Clone)] struct Inputs { rounds_num: u8, echo: bool, diff --git a/manul/src/lib.rs b/manul/src/lib.rs index 6291440..8d3323f 100644 --- a/manul/src/lib.rs +++ b/manul/src/lib.rs @@ -10,7 +10,8 @@ rust_2018_idioms, trivial_casts, trivial_numeric_casts, - unused_qualifications + unused_qualifications, + missing_debug_implementations )] extern crate alloc; diff --git a/manul/src/protocol/errors.rs b/manul/src/protocol/errors.rs index 045c062..27ef651 100644 --- a/manul/src/protocol/errors.rs +++ b/manul/src/protocol/errors.rs @@ -114,6 +114,7 @@ where } /// An error that can occur during [`Round::finalize`](`super::Round::finalize`). +#[derive(Debug)] pub enum FinalizeError { /// A local error, usually indicating a bug in the implementation. Local(LocalError), diff --git a/manul/src/protocol/object_safe.rs b/manul/src/protocol/object_safe.rs index 508663e..5d42262 100644 --- a/manul/src/protocol/object_safe.rs +++ b/manul/src/protocol/object_safe.rs @@ -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}; @@ -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: 'static + Send + Sync { +pub(crate) trait ObjectSafeRound: 'static + Send + Sync + Debug { type Protocol: Protocol; fn id(&self) -> RoundId; @@ -75,7 +75,9 @@ pub(crate) trait ObjectSafeRound: '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 { round: R, phantom: PhantomData Id>, @@ -92,7 +94,7 @@ impl> ObjectSafeRoundWrapper { impl ObjectSafeRound for ObjectSafeRoundWrapper where - Id: 'static, + Id: 'static + Debug, R: Round, { type Protocol = >::Protocol; diff --git a/manul/src/protocol/round.rs b/manul/src/protocol/round.rs index f32de81..71e4724 100644 --- a/manul/src/protocol/round.rs +++ b/manul/src/protocol/round.rs @@ -20,6 +20,7 @@ use super::{ use crate::session::SessionId; /// Possible successful outcomes of [`Round::finalize`]. +#[derive(Debug)] pub enum FinalizeOutcome { /// Transition to a new round. AnotherRound(AnotherRound), @@ -29,7 +30,7 @@ pub enum FinalizeOutcome { impl FinalizeOutcome where - Id: 'static, + Id: 'static + Debug, P: 'static + Protocol, { /// A helper method to create an [`AnotherRound`](`Self::AnotherRound`) variant. @@ -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(Box>); impl AnotherRound where - Id: 'static, + Id: 'static + Debug, P: 'static + Protocol, { /// Wraps an object implementing [`Round`]. @@ -119,7 +121,7 @@ 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>; @@ -127,7 +129,7 @@ pub trait Protocol: Debug + Sized { /// 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(value: T) -> Result, LocalError>; @@ -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: 'static + Send + Sync { +pub trait Round: 'static + Send + Sync + Debug { /// The protocol this round is a part of. type Protocol: Protocol; diff --git a/manul/src/session/echo.rs b/manul/src/session/echo.rs index 649abf2..f32a198 100644 --- a/manul/src/session/echo.rs +++ b/manul/src/session/echo.rs @@ -34,6 +34,7 @@ pub struct EchoRoundMessage { pub(crate) echo_messages: SerializableMap>, } +#[derive(Debug)] pub struct EchoRound { verifier: SP::Verifier, echo_messages: BTreeMap>, @@ -82,7 +83,7 @@ where impl Round for EchoRound where P: 'static + Protocol, - SP: 'static + SessionParameters, + SP: 'static + SessionParameters + Debug, { type Protocol = P; diff --git a/manul/src/session/session.rs b/manul/src/session/session.rs index 057aeb8..f57b976 100644 --- a/manul/src/session/session.rs +++ b/manul/src/session/session.rs @@ -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 + Keypair; + type Signer: Debug + RandomizedDigestSigner + Keypair; /// The hash type that will be used to pre-hash message payloads before signing. type Digest: Digest; @@ -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 { session_id: SessionId, signer: SP::Signer, @@ -93,6 +94,7 @@ pub struct Session { } /// Possible non-erroneous results of finalizing a round. +#[derive(Debug)] pub enum RoundOutcome { /// The execution is finished. Finished(SessionReport), @@ -108,7 +110,7 @@ pub enum RoundOutcome { impl Session where P: 'static + Protocol, - SP: 'static + SessionParameters, + SP: 'static + SessionParameters + Debug, { /// Initializes a new session. pub fn new( @@ -657,11 +659,13 @@ where } } +#[derive(Debug)] pub struct ProcessedArtifact { destination: SP::Verifier, artifact: Artifact, } +#[derive(Debug)] pub struct ProcessedMessage { message: VerifiedMessageBundle, processed: Result>, diff --git a/manul/src/session/transcript.rs b/manul/src/session/transcript.rs index a5b7d4f..3803d2e 100644 --- a/manul/src/session/transcript.rs +++ b/manul/src/session/transcript.rs @@ -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 { echo_broadcasts: BTreeMap>>, direct_messages: BTreeMap>>, @@ -152,6 +153,7 @@ pub enum SessionOutcome { } /// The report of a session execution. +#[derive(Debug)] pub struct SessionReport { /// The session outcome. pub outcome: SessionOutcome

, diff --git a/manul/src/testing/macros.rs b/manul/src/testing/macros.rs index 9ce75c2..38f2598 100644 --- a/manul/src/testing/macros.rs +++ b/manul/src/testing/macros.rs @@ -64,6 +64,7 @@ macro_rules! round_override { ($round: ident) => { impl Round for $round where + Id: Debug, $round: RoundOverride, { type Protocol = diff --git a/manul/src/testing/run_sync.rs b/manul/src/testing/run_sync.rs index 7d3a6cb..19d6670 100644 --- a/manul/src/testing/run_sync.rs +++ b/manul/src/testing/run_sync.rs @@ -1,3 +1,5 @@ +use core::fmt::Debug; + use alloc::{collections::BTreeMap, vec::Vec}; use rand::Rng; @@ -35,7 +37,7 @@ fn propagate( ) -> Result<(State, Vec>), LocalError> where P: 'static + Protocol, - SP: 'static + SessionParameters, + SP: 'static + SessionParameters + Debug, { let mut messages = Vec::new(); @@ -95,7 +97,7 @@ pub fn run_sync( ) -> Result>, LocalError> where R: 'static + FirstRound, - SP: 'static + SessionParameters, + SP: 'static + SessionParameters + Debug, { let session_id = SessionId::random(rng);