Skip to content

Commit 525cac4

Browse files
[consensus] Add consensus::marshal (#1306)
Co-authored-by: Patrick O'Grady <me@patrickogrady.xyz>
1 parent 486b21a commit 525cac4

50 files changed

Lines changed: 2953 additions & 63 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codec/src/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait Read: Sized {
4646
/// collections or strings.
4747
///
4848
/// Use `Cfg = ()` if no configuration is needed for a specific type.
49-
type Cfg: Clone + Send + 'static;
49+
type Cfg: Clone + Send + Sync + 'static;
5050

5151
/// Reads a value from the buffer using the provided configuration `cfg`.
5252
///

consensus/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ documentation = "https://docs.rs/commonware-consensus"
1212

1313
[dependencies]
1414
commonware-codec = { workspace = true }
15+
commonware-broadcast = { workspace = true }
1516
commonware-cryptography = { workspace = true }
17+
commonware-resolver = { workspace = true }
1618
commonware-utils = { workspace = true }
1719
bytes = { workspace = true }
1820
cfg-if = { workspace = true }
@@ -31,6 +33,7 @@ rand_distr = { workspace = true }
3133
tracing = { workspace = true }
3234

3335
[dev-dependencies]
36+
commonware-resolver = { workspace = true, features = ["mocks"] }
3437
tracing-subscriber = { workspace = true }
3538

3639
[lib]

consensus/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,45 @@
55
//! `commonware-consensus` is **ALPHA** software and is not yet recommended for production use. Developers should
66
//! expect breaking changes and occasional instability.
77
8+
use commonware_codec::Codec;
9+
use commonware_cryptography::{Committable, Digestible};
10+
811
pub mod aggregation;
912
pub mod ordered_broadcast;
1013
pub mod simplex;
1114
pub mod threshold_simplex;
1215

16+
/// Viewable is a trait that provides access to the view (round) number.
17+
/// Any consensus message or object that is associated with a specific view should implement this.
18+
pub trait Viewable {
19+
/// View is the type used to indicate the in-progress consensus decision.
20+
type View;
21+
22+
/// Returns the view associated with this object.
23+
fn view(&self) -> Self::View;
24+
}
25+
26+
/// Block is the interface for a block in the blockchain.
27+
///
28+
/// Blocks are used to track the progress of the consensus engine.
29+
pub trait Block: Codec + Digestible + Committable + Send + Sync + 'static {
30+
/// Get the height of the block.
31+
fn height(&self) -> u64;
32+
33+
/// Get the parent block's digest.
34+
fn parent(&self) -> Self::Commitment;
35+
}
36+
1337
cfg_if::cfg_if! {
1438
if #[cfg(not(target_arch = "wasm32"))] {
1539
use commonware_cryptography::{Digest, PublicKey};
1640
use futures::channel::{oneshot, mpsc};
1741
use std::future::Future;
1842

43+
pub mod marshal;
44+
mod reporter;
45+
pub use reporter::*;
46+
1947
/// Histogram buckets for measuring consensus latency.
2048
const LATENCY: [f64; 36] = [
2149
0.05, 0.1, 0.125, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35,

0 commit comments

Comments
 (0)