Skip to content

Commit

Permalink
Merge pull request #71 from fjarri/dev-infrastructure
Browse files Browse the repository at this point in the history
Dev infrastructure
  • Loading branch information
fjarri authored Nov 19, 2024
2 parents 8a2335d + 59aec37 commit 963d36e
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 97 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `EntryPoint` and `FinalizeOutcome::AnotherRound` now use a new `BoxedRound` wrapper type. ([#60])
- `PartyId` and `ProtocolError` are now bound on `Serialize`/`Deserialize`. ([#60])
- Entry points are now stateful; combinator API reworked accordingly. ([#68])
- `run_sync()` now returns an `ExecutionResult` object. ([#71])
- `testing` module and feature renamed to `dev` to avoid confusion with tests. ([#71])


### Added
Expand All @@ -41,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A `chain` combinator for chaining two protocols. ([#60])
- `EntryPoint::ENTRY_ROUND` constant. ([#60])
- `Round::echo_round_participation()`. ([#67])
- `SessionReport::result()`. ([#71])
- `run_sync_with_tracing()`. ([#71])


[#32]: https://github.com/entropyxyz/manul/pull/32
Expand All @@ -58,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#60]: https://github.com/entropyxyz/manul/pull/60
[#67]: https://github.com/entropyxyz/manul/pull/67
[#68]: https://github.com/entropyxyz/manul/pull/68
[#71]: https://github.com/entropyxyz/manul/pull/71


## [0.0.1] - 2024-10-12
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ postcard = { version = "1", features = ["alloc"] }
serde = "1"
sha3 = "0.10"
rand_core = "0.6"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = "0.1"

[dev-dependencies]
tokio = { version = "1", features = ["rt", "sync", "time", "macros"] }
rand = "0.8"
digest = "0.10"
manul = { path = "../manul", features = ["testing"] }
manul = { path = "../manul", features = ["dev"] }
23 changes: 8 additions & 15 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,10 @@ mod tests {
use alloc::collections::BTreeSet;

use manul::{
session::{signature::Keypair, SessionOutcome},
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
session::signature::Keypair,
};
use rand_core::OsRng;
use tracing_subscriber::EnvFilter;

use super::SimpleProtocolEntryPoint;

Expand All @@ -430,19 +429,13 @@ mod tests {
.map(|signer| (signer, SimpleProtocolEntryPoint::new(all_ids.clone())))
.collect::<Vec<_>>();

let my_subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let reports = tracing::subscriber::with_default(my_subscriber, || {
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap()
});
let results = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.results()
.unwrap();

for (_id, report) in reports {
if let SessionOutcome::Result(result) = report.outcome {
assert_eq!(result, 3); // 0 + 1 + 2
} else {
panic!("Session did not finish successfully");
}
for (_id, result) in results {
assert_eq!(result, 3); // 0 + 1 + 2
}
}
}
25 changes: 9 additions & 16 deletions examples/src/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ mod tests {
use alloc::collections::BTreeSet;

use manul::{
session::{signature::Keypair, SessionOutcome},
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
session::signature::Keypair,
};
use rand_core::OsRng;
use tracing_subscriber::EnvFilter;

use super::DoubleSimpleEntryPoint;

Expand All @@ -90,19 +89,13 @@ mod tests {
.map(|signer| (signer, DoubleSimpleEntryPoint::new(all_ids.clone())))
.collect::<Vec<_>>();

let my_subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let reports = tracing::subscriber::with_default(my_subscriber, || {
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap()
});

for (_id, report) in reports {
if let SessionOutcome::Result(result) = report.outcome {
assert_eq!(result, 3); // 0 + 1 + 2
} else {
panic!("Session did not finish successfully");
}
let results = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.results()
.unwrap();

for (_id, result) in results {
assert_eq!(result, 3); // 0 + 1 + 2
}
}
}
30 changes: 10 additions & 20 deletions examples/src/simple_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use core::fmt::Debug;

use manul::{
combinators::misbehave::{Misbehaving, MisbehavingEntryPoint},
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
protocol::{
Artifact, BoxedRound, Deserializer, DirectMessage, EntryPoint, LocalError, PartyId, ProtocolMessagePart,
RoundId, Serializer,
},
session::signature::Keypair,
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
};
use rand_core::{CryptoRngCore, OsRng};
use tracing_subscriber::EnvFilter;

use crate::simple::{Round1, Round1Message, Round2, Round2Message, SimpleProtocolEntryPoint};

Expand Down Expand Up @@ -94,12 +93,9 @@ fn serialized_garbage() {
})
.collect::<Vec<_>>();

let my_subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let mut reports = tracing::subscriber::with_default(my_subscriber, || {
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap()
});
let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

let v0 = signers[0].verifying_key();
let v1 = signers[1].verifying_key();
Expand Down Expand Up @@ -136,12 +132,9 @@ fn attributable_failure() {
})
.collect::<Vec<_>>();

let my_subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let mut reports = tracing::subscriber::with_default(my_subscriber, || {
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap()
});
let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

let v0 = signers[0].verifying_key();
let v1 = signers[1].verifying_key();
Expand Down Expand Up @@ -178,12 +171,9 @@ fn attributable_failure_round2() {
})
.collect::<Vec<_>>();

let my_subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
let mut reports = tracing::subscriber::with_default(my_subscriber, || {
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap()
});
let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

let v0 = signers[0].verifying_key();
let v1 = signers[1].verifying_key();
Expand Down
9 changes: 1 addition & 8 deletions examples/tests/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ extern crate alloc;
use alloc::collections::{BTreeMap, BTreeSet};

use manul::{
dev::{BinaryFormat, TestSessionParams, TestSigner},
protocol::Protocol,
session::{
signature::Keypair, CanFinalize, LocalError, Message, RoundOutcome, Session, SessionId, SessionParameters,
SessionReport,
},
testing::{BinaryFormat, TestSessionParams, TestSigner},
};
use manul_example::simple::{SimpleProtocol, SimpleProtocolEntryPoint};
use rand::Rng;
Expand All @@ -18,7 +18,6 @@ use tokio::{
time::{sleep, Duration},
};
use tracing::{debug, trace};
use tracing_subscriber::{util::SubscriberInitExt, EnvFilter};

struct MessageOut<SP: SessionParameters> {
from: SP::Verifier,
Expand Down Expand Up @@ -261,12 +260,6 @@ async fn async_run() {
})
.collect::<Vec<_>>();

tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish()
.try_init()
.unwrap();

// Run the protocol
run_nodes(sessions).await;
}
11 changes: 8 additions & 3 deletions manul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ displaydoc = { version = "0.2", default-features = false }
derive-where = "1"
tinyvec = { version = "1", default-features = false, features = ["alloc", "serde"] }

# Optional dependencies
rand = { version = "0.8", default-features = false, optional = true }
serde-persistent-deserializer = { version = "0.3", optional = true }
postcard = { version = "1", default-features = false, features = ["alloc"], optional = true }
serde_json = { version = "1", default-features = false, features = ["alloc"], optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }

[dev-dependencies]
impls = "1"
rand_core = { version = "0.6.4", default-features = false, features = ["getrandom"] }
rand = { version = "0.8", default-features = false }
serde_asn1_der = "0.8"
criterion = "0.5"

# These mirror the versions from the optional dependencies above.
rand = { version = "0.8", default-features = false }
serde-persistent-deserializer = "0.3"
postcard = { version = "1", default-features = false, features = ["alloc"] }
serde_json = { version = "1", default-features = false, features = ["alloc"] }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
testing = ["rand", "postcard", "serde_json", "serde-persistent-deserializer"]
dev = ["rand", "postcard", "serde_json", "tracing/std", "serde-persistent-deserializer", "tracing-subscriber"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -48,4 +53,4 @@ rustdoc-args = ["--cfg", "docsrs"]
[[bench]]
name = "empty_rounds"
harness = false
required-features = ["testing"]
required-features = ["dev"]
12 changes: 6 additions & 6 deletions manul/benches/empty_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use core::fmt::Debug;

use criterion::{criterion_group, criterion_main, Criterion};
use manul::{
dev::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
protocol::{
Artifact, BoxedRound, Deserializer, DirectMessage, EchoBroadcast, EntryPoint, FinalizeError, FinalizeOutcome,
LocalError, NormalBroadcast, PartyId, Payload, Protocol, ProtocolMessagePart, ReceiveError, Round, RoundId,
Serializer,
},
session::{signature::Keypair, SessionOutcome},
testing::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
session::signature::Keypair,
};
use rand_core::{CryptoRngCore, OsRng};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -195,8 +195,8 @@ fn bench_empty_rounds(c: &mut Criterion) {
assert!(
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points_no_echo.clone())
.unwrap()
.values()
.all(|report| matches!(report.outcome, SessionOutcome::Result(_)))
.results()
.is_ok()
)
})
});
Expand Down Expand Up @@ -225,8 +225,8 @@ fn bench_empty_rounds(c: &mut Criterion) {
assert!(
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points_echo.clone())
.unwrap()
.values()
.all(|report| matches!(report.outcome, SessionOutcome::Result(_)))
.results()
.is_ok()
)
})
});
Expand Down
2 changes: 1 addition & 1 deletion manul/src/testing.rs → manul/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ mod run_sync;
mod session_parameters;
mod wire_format;

pub use run_sync::run_sync;
pub use run_sync::{run_sync, run_sync_with_tracing};
pub use session_parameters::{TestHasher, TestSessionParams, TestSignature, TestSigner, TestVerifier};
pub use wire_format::{BinaryFormat, HumanReadableFormat};
Loading

0 comments on commit 963d36e

Please sign in to comment.