Skip to content

Commit

Permalink
Merge pull request #92 from fjarri/send-sync
Browse files Browse the repository at this point in the history
`Send`/`Sync` adjustment
  • Loading branch information
fjarri authored Feb 10, 2025
2 parents 68d70f8 + 9b00b83 commit 9810d01
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed the RNG parameter from `Round::receive_message()` and `Session::process_message()`. ([#83])
- Renamed `Round::entry_round()` to `entry_round_id()` and made it mandatory to implement. ([#84])
- Rework `RequiredMessageParts` API. ([#85])
- Removed `Send + Sync` bound on `WireFormat`. ([#92])
- Removed `Send` bound on `ProtocolError`. ([#92])


### Added
Expand Down Expand Up @@ -58,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#88]: https://github.com/entropyxyz/manul/pull/88
[#90]: https://github.com/entropyxyz/manul/pull/90
[#91]: https://github.com/entropyxyz/manul/pull/91
[#92]: https://github.com/entropyxyz/manul/pull/92


## [0.1.0] - 2024-11-19
Expand Down
5 changes: 2 additions & 3 deletions manul/src/protocol/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ pub(crate) trait ObjectSafeRound<Id: PartyId>: 'static + Debug + Send + Sync {
}
}

// The `fn(Id) -> Id` bit is so that `ObjectSafeRoundWrapper` didn't require a bound on `Id` to be
// `Send + Sync`.
// The `fn(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>,
phantom: PhantomData<fn(Id)>,
}

impl<Id, R> ObjectSafeRoundWrapper<Id, R>
Expand Down
2 changes: 1 addition & 1 deletion manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl RequiredMessages {
///
/// Provable here means that we can create an evidence object entirely of messages signed by some party,
/// which, in combination, prove the party's malicious actions.
pub trait ProtocolError<Id>: Display + Debug + Clone + Send + Serialize + for<'de> Deserialize<'de> {
pub trait ProtocolError<Id>: Display + Debug + Clone + Serialize + for<'de> Deserialize<'de> {
/// Additional data that cannot be derived from the node's messages alone
/// and therefore has to be supplied externally during evidence verification.
type AssociatedData: Debug;
Expand Down
8 changes: 5 additions & 3 deletions manul/src/protocol/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ trait ObjectSafeSerializer: Debug {
fn serialize(&self, value: Box<dyn erased_serde::Serialize>) -> Result<Box<[u8]>, LocalError>;
}

// `fn(F)` makes the type `Send` + `Sync` even if `F` isn't.
#[derive(Debug)]
struct SerializerWrapper<F: WireFormat>(PhantomData<F>);
struct SerializerWrapper<F: WireFormat>(PhantomData<fn(F)>);

impl<F: WireFormat> ObjectSafeSerializer for SerializerWrapper<F> {
fn serialize(&self, value: Box<dyn erased_serde::Serialize>) -> Result<Box<[u8]>, LocalError> {
Expand Down Expand Up @@ -42,8 +43,9 @@ impl Serializer {

// Deserialization

// `fn(F)` makes the type `Send` + `Sync` even if `F` isn't.
#[derive(Debug)]
struct DeserializerFactoryWrapper<F>(PhantomData<F>);
struct DeserializerFactoryWrapper<F>(PhantomData<fn(F)>);

trait ObjectSafeDeserializerFactory: Debug {
fn make_erased_deserializer<'de>(&self, bytes: &'de [u8]) -> Box<dyn erased_serde::Deserializer<'de> + 'de>;
Expand All @@ -68,7 +70,7 @@ impl Deserializer {
where
F: WireFormat,
{
Self(Box::new(DeserializerFactoryWrapper(PhantomData::<F>)))
Self(Box::new(DeserializerFactoryWrapper::<F>(PhantomData)))
}

/// Deserializes a `serde`-deserializable object.
Expand Down
2 changes: 1 addition & 1 deletion manul/src/session/wire_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if we could instead type-erase the serializer, we wouldn't need that.
*/

/// A (de)serializer that will be used for the protocol messages.
pub trait WireFormat: 'static + Send + Sync + Debug {
pub trait WireFormat: 'static + Debug {
/// Serializes the given object into a bytestring.
fn serialize<T: Serialize>(value: T) -> Result<Box<[u8]>, LocalError>;

Expand Down

0 comments on commit 9810d01

Please sign in to comment.