Struct round_based::dev::Simulation
source · [−]pub struct Simulation<P> {
pub parties: Vec<P>,
/* private fields */
}Available on crate feature
dev only.Expand description
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 simulation more useful for writing benchmarks that detect performance regression.
Limitations
- 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
sourceimpl<P> Simulation<P>
impl<P> Simulation<P>
sourcepub fn enable_benchmarks(&mut self, enable: bool) -> &mut Self
pub fn enable_benchmarks(&mut self, enable: bool) -> &mut Self
Enables benchmarks so they can be retrieved after simulation is completed
sourcepub fn benchmark_results(&self) -> Option<&BenchmarkResults>
pub fn benchmark_results(&self) -> Option<&BenchmarkResults>
sourceimpl<P> Simulation<P> where
P: StateMachine,
P: Debug,
P::Err: Debug,
P::MessageBody: Debug + Clone,
impl<P> Simulation<P> where
P: StateMachine,
P: Debug,
P::Err: Debug,
P::MessageBody: Debug + Clone,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more