|
1 | 1 | //! Multiparty protocol simulation
|
2 | 2 | //!
|
3 | 3 | //! Simulator is an essential developer tool for testing the multiparty protocol locally.
|
4 |
| -//! It covers most of the boilerplate by mocking networking. |
| 4 | +//! It covers most of the boilerplate of emulating MPC protocol execution. |
5 | 5 | //!
|
6 | 6 | //! The entry point is either [`run`] or [`run_with_setup`] functions. They take a protocol
|
7 | 7 | //! defined as an async function, provide simulated networking, carry out the simulation,
|
8 | 8 | //! and return the result.
|
9 | 9 | //!
|
10 |
| -//! If you need more control over execution, you can use [`Network`] to simulate the networking |
11 |
| -//! and carry out the protocol manually. |
| 10 | +//! If you need more control over execution, you can use [`Simulation`]. For instance, it allows |
| 11 | +//! creating a simulation that has parties defined by different functions, which is helpful, for |
| 12 | +//! instance, in simulation in presence of an adversary (e.g. one set of parties can be defined |
| 13 | +//! with a regular function/protocol implementation, when the other set of parties may be defined |
| 14 | +//! by other function which emulates adversary behavior). |
12 | 15 | //!
|
13 |
| -//! When `state-machine` feature is enabled, [`SimulationSync`] is available which can carry out |
14 |
| -//! protocols defined as a state machine. |
| 16 | +//! ## Limitations |
| 17 | +//! [`Simulation`] works by converting each party (defined as an async function) into the |
| 18 | +//! [state machine](crate::state_machine). That should work without problems in most cases, providing |
| 19 | +//! better UX, without requiring an async runtime (simulation is entirely sync). |
| 20 | +//! |
| 21 | +//! However, a protocol wrapped into a state machine cannot poll any futures except provided within |
| 22 | +//! [`MpcParty`](crate::MpcParty) (so it can only await on sending/receiving messages and yielding). |
| 23 | +//! For instance, if the protocol implementation makes use of tokio timers, it will result into an |
| 24 | +//! execution error. |
| 25 | +//! |
| 26 | +//! In general, we do not recommend awaiting on the futures that aren't provided by `MpcParty` in |
| 27 | +//! the MPC protocol implementation, to keep the protocol implementation runtime-agnostic. |
| 28 | +//! |
| 29 | +//! If you do really need to make use of unsupported futures, you can use [`async_env`] instead, |
| 30 | +//! which provides a simulation on tokio runtime, but has its own limitations. |
15 | 31 | //!
|
16 | 32 | //! ## Example
|
17 | 33 | //! ```rust,no_run
|
@@ -308,7 +324,7 @@ where
|
308 | 324 | }
|
309 | 325 | }
|
310 | 326 |
|
311 |
| -/// Error returned by [`SimulationSync::run`] |
| 327 | +/// Error indicating that simulation failed |
312 | 328 | #[derive(Debug, thiserror::Error)]
|
313 | 329 | #[error(transparent)]
|
314 | 330 | pub struct SimError(#[from] Reason);
|
@@ -385,7 +401,7 @@ impl<M: Clone> MessagesQueue<M> {
|
385 | 401 | /// Simulates execution of the protocol
|
386 | 402 | ///
|
387 | 403 | /// Takes amount of participants, and a function that carries out the protocol for
|
388 |
| -/// one party. The function takes as input: index of the party, and [`MpcParty`] |
| 404 | +/// one party. The function takes as input: index of the party, and [`MpcParty`](crate::MpcParty) |
389 | 405 | /// that can be used to communicate with others.
|
390 | 406 | ///
|
391 | 407 | /// ## Example
|
|
0 commit comments