Struct round_based::dev::Simulation [−][src]
dev
only.Emulates running protocol between local parties
Takes parties (every party is instance of StateMachine) and executes protocol between them. It logs whole process (changing state of party, receiving messages, etc.) in stdout.
Compared to AsyncSimulation, it’s lightweight (doesn’t require async runtime), and, more importantly, executes everything in straight order (sequently, without any parallelism). It makes this sumaltion more useful for writing benchmarks that detect performance regression.
Limitations
- Currently, it’s a bit silly and doesn’t support specific StateMachine implementations (e.g. it’ll panic if SM wants to proceed, but there are some messages sent by other parties which should be handled)
- No proper error handling. It should attach a context to returning error (like current round, what we was doing when error occurred, etc.). The only way to determine error context is to look at stdout and find out what happened from logs.
- Logs everything to stdout. No choice.
Example
let results = Simulation::new() .add_party(Party::new(1, 3)) .add_party(Party::new(2, 3)) .add_party(Party::new(3, 3)) .run()?; assert!(results.into_iter().all(|r| is_valid(&r)));
Fields
parties: Vec<P>
Parties running a protocol
Field is exposed mainly to allow examining parties state after simulation is completed.
Implementations
impl<P> Simulation<P>
[src]
pub fn new() -> Self
[src]
Creates new simulation
pub fn add_party(&mut self, party: P) -> &mut Self
[src]
Adds protocol participant
pub fn enable_benchmarks(&mut self, enable: bool) -> &mut Self
[src]
Enables benchmarks so they can be retrieved after simulation is completed
pub fn benchmark_results(&self) -> Option<&BenchmarkResults>
[src]
impl<P> Simulation<P> where
P: StateMachine,
P: Debug,
P::Err: Debug,
P::MessageBody: Debug,
P::MessageBody: Clone,
[src]
P: StateMachine,
P: Debug,
P::Err: Debug,
P::MessageBody: Debug,
P::MessageBody: Clone,
pub fn run(&mut self) -> Result<Vec<P::Output>, P::Err>
[src]
Runs a simulation
Returns
Returns either Vec of protocol outputs (one output for each one party) or first occurred critical error.
Panics
- Number of parties is less than 2
- Party behaves unexpectedly (see limitations)
Auto Trait Implementations
impl<P> RefUnwindSafe for Simulation<P> where
P: RefUnwindSafe,
P: RefUnwindSafe,
impl<P> Send for Simulation<P> where
P: Send,
P: Send,
impl<P> Sync for Simulation<P> where
P: Sync,
P: Sync,
impl<P> Unpin for Simulation<P> where
P: Unpin,
P: Unpin,
impl<P> UnwindSafe for Simulation<P> where
P: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,