pub trait RoundStore: RoundInfo {
// Required methods
fn add_message(
&mut self,
msg: Incoming<Self::Msg>,
) -> Result<(), Self::Error>;
fn wants_more(&self) -> bool;
fn output(self) -> Result<Self::Output, Self>;
// Provided method
fn read_any_prop(&self, property: &mut dyn Any) { ... }
}Expand description
Stores messages received at particular round
In MPC protocol, party at every round usually needs to receive up to n messages. RoundsStore
is a container that stores messages, it knows how many messages are expected to be received,
and should implement extra measures against malicious parties (e.g. prohibit message overwrite).
§Flow
RoundStore stores received messages. Once enough messages are received, it outputs RoundInfo::Output.
In order to save received messages, .add_message(msg) is called. Then, .wants_more() tells whether more
messages are needed to be received. If it returned false, then output can be retrieved by calling .output().
§Example
RoundInput is an simple messages store. Refer to its docs to see usage examples.
Required Methods§
Sourcefn add_message(&mut self, msg: Incoming<Self::Msg>) -> Result<(), Self::Error>
fn add_message(&mut self, msg: Incoming<Self::Msg>) -> Result<(), Self::Error>
Adds received message to the store
Returns error if message cannot be processed. Usually it means that sender behaves maliciously.
Sourcefn wants_more(&self) -> bool
fn wants_more(&self) -> bool
Indicates if store expects more messages to receive
Provided Methods§
Sourcefn read_any_prop(&self, property: &mut dyn Any)
fn read_any_prop(&self, property: &mut dyn Any)
Interface that exposes ability to retrieve generic information about the round store
For reading store properties, it’s recommended to use RoundStoreExt::read_prop method which
uses this function internally.
When implementing RoundStore trait, if you wish to expose no extra information, leave the default
implementation of this method. If you do want to expose certain properties that will be accessible
through RoundStoreExt::read_prop, follow this example:
pub struct MyStore { /* ... */ }
#[derive(Debug, PartialEq, Eq)]
pub struct SomePropertyWeWantToExpose { value: u64 }
#[derive(Debug, PartialEq, Eq)]
pub struct AnotherProperty(String);
impl round_based::round::RoundStore for MyStore {
// ...
fn read_any_prop(&self, property: &mut dyn core::any::Any) {
if let Some(p) = property.downcast_mut::<Option<SomePropertyWeWantToExpose>>() {
*p = Some(SomePropertyWeWantToExpose { value: 42 })
} else if let Some(p) = property.downcast_mut::<Option<AnotherProperty>>() {
*p = Some(AnotherProperty("here we return a string".to_owned()))
}
}
}
// Which then can be accessed via `.read_prop()` method:
use round_based::round::RoundStoreExt;
let store = MyStore { /* ... */ };
assert_eq!(
store.read_prop::<SomePropertyWeWantToExpose>(),
Some(SomePropertyWeWantToExpose { value: 42 }),
);
assert_eq!(
store.read_prop::<AnotherProperty>(),
Some(AnotherProperty("here we return a string".to_owned())),
);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.