-
Notifications
You must be signed in to change notification settings - Fork 220
[glue] Introduce commonware-glue
#3381
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
Open
clabby
wants to merge
4
commits into
main
Choose a base branch
from
cl/glue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| [package] | ||
| name = "commonware-glue" | ||
| edition.workspace = true | ||
| publish = true | ||
| version.workspace = true | ||
| license.workspace = true | ||
| description = "Bootstrap applications with commonware primitive compositions." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "Construct stateful applications with efficient synchronization." |
||
| readme = "README.md" | ||
| homepage.workspace = true | ||
| repository = "https://github.com/commonwarexyz/monorepo/tree/main/glue" | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [dependencies] | ||
| arbitrary = { workspace = true, optional = true, features = ["derive"] } | ||
| bytes.workspace = true | ||
| commonware-actor.workspace = true | ||
| commonware-codec.workspace = true | ||
| commonware-consensus.workspace = true | ||
| commonware-cryptography.workspace = true | ||
| commonware-macros.workspace = true | ||
| commonware-p2p.workspace = true | ||
| commonware-parallel.workspace = true | ||
| commonware-resolver.workspace = true | ||
| commonware-runtime.workspace = true | ||
| commonware-storage.workspace = true | ||
| commonware-utils.workspace = true | ||
| futures.workspace = true | ||
| prometheus-client.workspace = true | ||
| rand.workspace = true | ||
| rand_core.workspace = true | ||
| thiserror.workspace = true | ||
| tracing.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| commonware-broadcast.workspace = true | ||
| commonware-codec.workspace = true | ||
| commonware-conformance.workspace = true | ||
| commonware-consensus = { workspace = true, features = ["mocks"] } | ||
| commonware-cryptography = { workspace = true, features = ["mocks"] } | ||
| commonware-formatting.workspace = true | ||
| commonware-p2p.workspace = true | ||
| commonware-parallel.workspace = true | ||
| commonware-resolver.workspace = true | ||
| commonware-storage.workspace = true | ||
| tracing-subscriber.workspace = true | ||
|
|
||
| [features] | ||
| test-utils = [] | ||
| arbitrary = [ | ||
| "commonware-codec/arbitrary", | ||
| "commonware-consensus/arbitrary", | ||
| "commonware-cryptography/arbitrary", | ||
| "commonware-p2p/arbitrary", | ||
| "commonware-resolver/arbitrary", | ||
| "commonware-runtime/arbitrary", | ||
| "commonware-storage/arbitrary", | ||
| "commonware-utils/arbitrary", | ||
| "dep:arbitrary", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # commonware-glue | ||
|
|
||
| [](https://crates.io/crates/commonware-glue) | ||
|
|
||
| Bootstrap applications with commonware primitive compositions. | ||
|
|
||
| ## Status | ||
|
|
||
| Stability varies by primitive. See [README](https://github.com/commonwarexyz/monorepo#stability) for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ["commonware_glue::stateful::db::p2p::handler::tests::conformance::CodecConformance<Request<mmr::Family>>"] | ||
| n_cases = 65536 | ||
| hash = "44c363dc52376203a66269a71e13f7271c1a9beb1f8ee9dd9864a3ce7ae2c281" | ||
|
|
||
| ["commonware_glue::stateful::db::p2p::handler::tests::conformance::CodecConformance<Response<mmr::Family,u64,sha256::Digest>>"] | ||
| n_cases = 65536 | ||
| hash = "7ca1ff124e5835f5be5d9b915233b9df088db121a0f5c3baa54b9ab8daf8bd78" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #![doc = include_str!("../README.md")] | ||
| #![doc( | ||
| html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg", | ||
| html_favicon_url = "https://commonware.xyz/favicon.ico" | ||
| )] | ||
|
|
||
| commonware_macros::stability_scope!(ALPHA { | ||
| pub mod stateful; | ||
|
|
||
| #[cfg(any(test, feature = "test-utils"))] | ||
| pub mod simulate; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //! Simulation action types for testing. | ||
|
|
||
| use commonware_cryptography::PublicKey; | ||
| use commonware_p2p::simulated::Link; | ||
| use commonware_runtime::deterministic; | ||
| use std::time::Duration; | ||
|
|
||
| /// Crash strategy for a simulation run. | ||
| #[derive(Clone)] | ||
| pub enum Crash<P: PublicKey> { | ||
| /// Periodically crash random validators and restart them after | ||
| /// a downtime period. | ||
| Random { | ||
| /// How often to trigger crashes. | ||
| frequency: Duration, | ||
| /// How long crashed validators stay offline. | ||
| downtime: Duration, | ||
| /// Number of validators to crash each time. | ||
| count: usize, | ||
| }, | ||
|
|
||
| /// Delay some validators from starting until after N finalizations. | ||
| Delay { | ||
| /// Number of validators to delay. | ||
| count: usize, | ||
| /// Number of finalizations before starting delayed validators. | ||
| after: u64, | ||
| }, | ||
|
|
||
| /// Time-indexed action schedule for precise control. | ||
| Schedule(Schedule<P>), | ||
| } | ||
|
|
||
| /// A time-ordered sequence of simulation actions. | ||
| #[derive(Clone)] | ||
| pub struct Schedule<P: PublicKey> { | ||
| /// Time-indexed actions. | ||
| pub events: Vec<(Duration, Action<P>)>, | ||
| } | ||
|
|
||
| impl<P: PublicKey> Schedule<P> { | ||
| /// Create an empty schedule. | ||
| pub const fn new() -> Self { | ||
| Self { events: vec![] } | ||
| } | ||
|
|
||
| /// Add an action at the given simulation time. | ||
| pub fn at(mut self, time: Duration, action: Action<P>) -> Self { | ||
| self.events.push((time, action)); | ||
| self | ||
| } | ||
| } | ||
|
|
||
| impl<P: PublicKey> Default for Schedule<P> { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| /// A single simulation action to apply at a specific time. | ||
| #[derive(Clone)] | ||
| pub enum Action<P: PublicKey> { | ||
| /// Update deterministic storage fault injection. | ||
| SetStorageFault(deterministic::FaultConfig), | ||
|
|
||
| /// Reset all directed links, restoring full connectivity with the given link. | ||
| Heal(Link), | ||
|
|
||
| /// Update a specific directed link by removing and re-adding it. | ||
| UpdateLink { | ||
| /// Source peer. | ||
| from: P, | ||
| /// Destination peer. | ||
| to: P, | ||
| /// New link configuration. | ||
| link: Link, | ||
| }, | ||
|
|
||
| /// Crash a specific validator. | ||
| Crash(P), | ||
|
|
||
| /// Restart a previously crashed validator. | ||
| Restart(P), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| //! Engine definition trait and supporting types. | ||
|
|
||
| use super::tracker::FinalizationUpdate; | ||
| use commonware_cryptography::PublicKey; | ||
| use commonware_p2p::simulated::{self, Oracle}; | ||
| use commonware_runtime::{deterministic, Handle, Quota}; | ||
| use commonware_utils::channel::mpsc; | ||
| use std::future::Future; | ||
|
|
||
| /// A registered p2p channel pair (sender, receiver). | ||
| pub type ChannelPair<P> = ( | ||
| simulated::Sender<P, deterministic::Context>, | ||
| simulated::Receiver<P>, | ||
| ); | ||
|
|
||
| /// Arguments passed to [`EngineDefinition::init`]. | ||
| pub struct InitContext<'a, P: PublicKey> { | ||
| /// Labeled runtime context for this validator. | ||
| pub context: deterministic::Context, | ||
| /// Index of this validator in the participant list. | ||
| pub index: usize, | ||
| /// This validator's public key. | ||
| pub public_key: &'a P, | ||
| /// Network oracle for peer management. | ||
| pub oracle: &'a Oracle<P, deterministic::Context>, | ||
| /// Registered p2p channel pairs (same order as `channels()`). | ||
| pub channels: Vec<ChannelPair<P>>, | ||
| /// All participants in the simulation. | ||
| pub participants: &'a [P], | ||
| /// Channel for reporting finalization events to the harness. | ||
| pub monitor: mpsc::Sender<FinalizationUpdate<P>>, | ||
| } | ||
|
|
||
| /// Defines how to construct and start one validator's service stack. | ||
| /// | ||
| /// The harness calls these methods for each validator in the simulation. | ||
| /// The lifecycle is: | ||
| /// 1. `channels()` -- declare which p2p channels are needed. | ||
| /// 2. `init()` -- construct the engine (actors, archives, mailboxes). | ||
| /// 3. `start()` -- start all actors, return a joinable handle. | ||
| /// | ||
| /// On restart after a crash, `init()` and `start()` are called again | ||
| /// with the same validator identity but a fresh runtime context (storage | ||
| /// state is preserved by the deterministic runtime). | ||
| pub trait EngineDefinition: Clone + Send + 'static { | ||
| /// The public key type used by this engine. | ||
| type PublicKey: PublicKey; | ||
|
|
||
| /// The constructed engine, passed from `init` to `start`. | ||
| type Engine: Send + 'static; | ||
|
|
||
| /// Per-validator state inspectable by property checkers. | ||
| type State: Send + Sync + 'static; | ||
|
|
||
| /// The participants for this simulation. | ||
| /// | ||
| /// Called once by the harness to determine the validator set. The engine | ||
| /// is responsible for generating keys and any associated state (signing | ||
| /// schemes, databases, etc.) during construction. | ||
| fn participants(&self) -> Vec<Self::PublicKey>; | ||
|
|
||
| /// Which p2p channels to register for each validator. | ||
| /// | ||
| /// Returns `(channel_id, quota)` pairs. The harness registers each | ||
| /// on the simulated oracle and passes sender/receiver pairs to | ||
| /// `init` in the same order. | ||
| fn channels(&self) -> Vec<(u64, Quota)>; | ||
|
|
||
| /// Construct the engine for a single validator. | ||
| fn init( | ||
| &self, | ||
| ctx: InitContext<'_, Self::PublicKey>, | ||
| ) -> impl Future<Output = (Self::Engine, Self::State)> + Send; | ||
|
|
||
| /// Start all actors in the engine. Returns a handle the harness | ||
| /// can join on (or abort on crash). | ||
| fn start(engine: Self::Engine) -> Handle<()>; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.