diff --git a/CHANGELOG.md b/CHANGELOG.md index ac0e5ad..5919e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Re-export `digest` from the `session` module. ([#56]) - Added `Message::destination()`. ([#56]) - `PartyId` trait alias for the combination of bounds needed for a party identifier. ([#59]) +- An impl of `ProtocolError` for `()` for protocols that don't use errors. ([#60]) [#32]: https://github.com/entropyxyz/manul/pull/32 diff --git a/manul/benches/empty_rounds.rs b/manul/benches/empty_rounds.rs index 25cbf5f..87eefee 100644 --- a/manul/benches/empty_rounds.rs +++ b/manul/benches/empty_rounds.rs @@ -1,17 +1,14 @@ extern crate alloc; -use alloc::{ - collections::{BTreeMap, BTreeSet}, - string::String, -}; +use alloc::collections::{BTreeMap, BTreeSet}; use core::fmt::Debug; use criterion::{criterion_group, criterion_main, Criterion}; use manul::{ protocol::{ Artifact, BoxedRound, Deserializer, DirectMessage, EchoBroadcast, EntryPoint, FinalizeError, FinalizeOutcome, - LocalError, NormalBroadcast, PartyId, Payload, Protocol, ProtocolError, ProtocolMessagePart, - ProtocolValidationError, ReceiveError, Round, RoundId, Serializer, + LocalError, NormalBroadcast, PartyId, Payload, Protocol, ProtocolMessagePart, ReceiveError, Round, RoundId, + Serializer, }, session::{signature::Keypair, SessionOutcome}, testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner, TestVerifier}, @@ -22,31 +19,9 @@ use serde::{Deserialize, Serialize}; #[derive(Debug)] pub struct EmptyProtocol; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EmptyProtocolError; - -impl ProtocolError for EmptyProtocolError { - fn description(&self) -> String { - unimplemented!() - } - fn verify_messages_constitute_error( - &self, - _deserializer: &Deserializer, - _echo_broadcast: &EchoBroadcast, - _normal_broadcast: &NormalBroadcast, - _direct_message: &DirectMessage, - _echo_broadcasts: &BTreeMap, - _normal_broadcasts: &BTreeMap, - _direct_messages: &BTreeMap, - _combined_echos: &BTreeMap>, - ) -> Result<(), ProtocolValidationError> { - unimplemented!() - } -} - impl Protocol for EmptyProtocol { type Result = (); - type ProtocolError = EmptyProtocolError; + type ProtocolError = (); type CorrectnessProof = (); } diff --git a/manul/src/protocol/round.rs b/manul/src/protocol/round.rs index ec58c1d..ddc3011 100644 --- a/manul/src/protocol/round.rs +++ b/manul/src/protocol/round.rs @@ -201,6 +201,28 @@ pub trait ProtocolError: Debug + Clone + Send { ) -> Result<(), ProtocolValidationError>; } +// A convenience implementation for protocols that don't define any errors. +// Have to do it for `()`, since `!` is unstable. +impl ProtocolError for () { + fn description(&self) -> String { + panic!("Attempt to use an empty error type in an evidence. This is a bug in the protocol implementation.") + } + + fn verify_messages_constitute_error( + &self, + _deserializer: &Deserializer, + _echo_broadcast: &EchoBroadcast, + _normal_broadcast: &NormalBroadcast, + _direct_message: &DirectMessage, + _echo_broadcasts: &BTreeMap, + _normal_broadcasts: &BTreeMap, + _direct_messages: &BTreeMap, + _combined_echos: &BTreeMap>, + ) -> Result<(), ProtocolValidationError> { + panic!("Attempt to use an empty error type in an evidence. This is a bug in the protocol implementation.") + } +} + /// Message payload created in [`Round::receive_message`]. #[derive(Debug)] pub struct Payload(pub Box); diff --git a/manul/src/session/session.rs b/manul/src/session/session.rs index 32d926b..c556344 100644 --- a/manul/src/session/session.rs +++ b/manul/src/session/session.rs @@ -816,17 +816,11 @@ fn filter_messages( #[cfg(test)] mod tests { - use alloc::{collections::BTreeMap, string::String, vec::Vec}; - use impls::impls; - use serde::{Deserialize, Serialize}; use super::{Message, ProcessedArtifact, ProcessedMessage, Session, VerifiedMessage}; use crate::{ - protocol::{ - Deserializer, DirectMessage, EchoBroadcast, NormalBroadcast, Protocol, ProtocolError, - ProtocolValidationError, RoundId, - }, + protocol::Protocol, testing::{BinaryFormat, TestSessionParams, TestVerifier}, }; @@ -842,32 +836,9 @@ mod tests { struct DummyProtocol; - #[derive(Debug, Clone, Serialize, Deserialize)] - struct DummyProtocolError; - - impl ProtocolError for DummyProtocolError { - fn description(&self) -> String { - unimplemented!() - } - - fn verify_messages_constitute_error( - &self, - _deserializer: &Deserializer, - _echo_broadcast: &EchoBroadcast, - _normal_broadcast: &NormalBroadcast, - _direct_message: &DirectMessage, - _echo_broadcasts: &BTreeMap, - _normal_broadcasts: &BTreeMap, - _direct_messages: &BTreeMap, - _combined_echos: &BTreeMap>, - ) -> Result<(), ProtocolValidationError> { - unimplemented!() - } - } - impl Protocol for DummyProtocol { type Result = (); - type ProtocolError = DummyProtocolError; + type ProtocolError = (); type CorrectnessProof = (); }