Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve simulation UX #14

Merged
merged 22 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions round-based/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ hex = "0.4"
rand = "0.8"
rand_dev = "0.1"

anyhow = "1"

[features]
default = ["std"]
state-machine = []
Expand Down
1 change: 1 addition & 0 deletions round-based/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub use futures_util::{Sink, SinkExt, Stream, StreamExt};
/// Fixes false-positive of `unused_crate_dependencies` lint that only occur in the tests
#[cfg(test)]
mod false_positives {
use anyhow as _;
use futures as _;
use trybuild as _;

Expand Down
40 changes: 36 additions & 4 deletions round-based/src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//!
//! ## Example
//! ```rust,no_run
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> anyhow::Result<()> {
//! use round_based::{Mpc, PartyIndex};
//! use anyhow::{Result, Error, Context as _};
//!
//! # type Result<T, E = ()> = std::result::Result<T, E>;
//! # type Randomness = [u8; 32];
//! # type Msg = ();
//! // Any MPC protocol
Expand All @@ -25,11 +27,41 @@
//! # todo!()
//! }
//!
//! let state_machine = round_based::state_machine::wrap_protocol(
//! // `state` implements `round_based::state_machine::StateMachine` trait.
//! // Its methods can be used to advance protocol until completion.
//! let mut state = round_based::state_machine::wrap_protocol(
//! |party| protocol_of_random_generation(party, 0, 3)
//! );
//! // `state_machine` implements `round_based::state_machine::StateMachine` trait.
//! // Its methods can be used to advance protocol until completion.
//!
//! // Note: this is just an example. If you have stream/sink, you don't probably need to
//! // use the sync API
//! use futures::{Sink, Stream, SinkExt, StreamExt};
//! async fn connect() -> Result<(
//! impl Stream<Item = anyhow::Result<round_based::Incoming<Msg>>>,
//! impl Sink<round_based::Outgoing<Msg>, Error = Error>
//! )> {
//! // ...
//! # Ok((futures_util::stream::pending(), futures_util::sink::drain().sink_map_err(|err| match err {})))
//! }
//! let (mut incomings, mut outgoings) = connect().await?;
survived marked this conversation as resolved.
Show resolved Hide resolved
//!
//! use round_based::state_machine::{StateMachine as _, ProceedResult};
//! let output = loop {
//! match state.proceed() {
//! ProceedResult::SendMsg(msg) => {
//! outgoings.send(msg).await?
//! }
//! ProceedResult::NeedsOneMoreMessage => {
//! let msg = incomings.next().await.context("unexpected eof")??;
//! state.received_msg(msg)
//! .map_err(|_| anyhow::format_err!("state machine rejected received message"))?;
//! }
//! ProceedResult::Yielded => {},
//! ProceedResult::Output(out) => break Ok(out),
//! ProceedResult::Error(err) => break Err(err),
//! }
//! };
//! # Ok(()) }
//! ```

mod delivery;
Expand Down
Loading