Struct round_based::dev::Simulation[][src]

pub struct Simulation<P> {
    pub parties: Vec<P>,
    // some fields omitted
}
This is supported on crate feature 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]

Returns benchmark results if they were enabled

Benchmarks show how much time (in average) proceed method takes for proceeding particular rounds. Benchmarks might help to find out which rounds are cheap to proceed, and which of them are expensive to compute.

impl<P> Simulation<P> where
    P: StateMachine,
    P: Debug,
    P::Err: Debug,
    P::MessageBody: Debug,
    P::MessageBody: Clone
[src]

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

impl<P> Send for Simulation<P> where
    P: Send

impl<P> Sync for Simulation<P> where
    P: Sync

impl<P> Unpin for Simulation<P> where
    P: Unpin

impl<P> UnwindSafe for Simulation<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.