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

feat(code): Add async channel-based wrapper around core consensus API #807

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions code/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 code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"crates/core-state-machine",
"crates/core-types",
"crates/core-votekeeper",
"crates/consensus-async",
"crates/engine",
"crates/metrics",
"crates/network",
Expand Down Expand Up @@ -72,6 +73,7 @@ malachitebft-core-driver = { version = "0.0.1", package = "informalsystem
malachitebft-core-state-machine = { version = "0.0.1", package = "informalsystems-malachitebft-core-state-machine", path = "crates/core-state-machine" }
malachitebft-core-types = { version = "0.0.1", package = "informalsystems-malachitebft-core-types", path = "crates/core-types" }
malachitebft-core-votekeeper = { version = "0.0.1", package = "informalsystems-malachitebft-core-votekeeper", path = "crates/core-votekeeper" }
malachitebft-consensus-async = { version = "0.0.1", package = "informalsystems-malachitebft-consensus-async", path = "crates/consensus-async" }
malachitebft-discovery = { version = "0.0.1", package = "informalsystems-malachitebft-discovery", path = "crates/discovery" }
malachitebft-network = { version = "0.0.1", package = "informalsystems-malachitebft-network", path = "crates/network" }
malachitebft-metrics = { version = "0.0.1", package = "informalsystems-malachitebft-metrics", path = "crates/metrics" }
Expand Down
2 changes: 1 addition & 1 deletion code/crates/app/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Re-export of all types required to build a Malachite application.

pub use malachitebft_core_consensus::{
pub use malachitebft_core_consensus::types::{
ConsensusMsg, ProposedValue, SignedConsensusMsg, ValuePayload,
};
pub use malachitebft_engine::host::LocallyProposedValue;
Expand Down
33 changes: 33 additions & 0 deletions code/crates/consensus-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "informalsystems-malachitebft-consensus-async"
description = "High-level async consensus API for the Malachite BFT consensus engine"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true
publish.workspace = true
rust-version.workspace = true
readme = "../../../README.md"

[package.metadata.docs.rs]
all-features = false
rustdoc-args = ["--cfg", "docsrs"]

[features]
serde = ["dep:serde", "dep:humantime-serde"]

[dependencies]
malachitebft-core-types = { workspace = true }
malachitebft-core-consensus = { workspace = true }
malachitebft-sync = { workspace = true }

async-trait = { workspace = true }
derive-where = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true, optional = true }
humantime-serde = { workspace = true, optional = true }
thiserror = { workspace = true }
tracing = { workspace = true }

[lints]
workspace = true
82 changes: 82 additions & 0 deletions code/crates/consensus-async/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use std::time::Duration;

use malachitebft_core_types::TimeoutKind;

/// Timeouts
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Timeouts {
/// How long we wait for a proposal block before prevoting nil
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub propose: Duration,

/// How much timeout_propose increases with each round
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub propose_delta: Duration,

/// How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub prevote: Duration,

/// How much the timeout_prevote increases with each round
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub prevote_delta: Duration,

/// How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub precommit: Duration,

/// How much the timeout_precommit increases with each round
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub precommit_delta: Duration,

/// How long we wait after committing a block, before starting on the new
/// height (this gives us a chance to receive some more precommits, even
/// though we already have +2/3).
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub commit: Duration,

/// How long we stay in preovte or precommit steps before starting
/// the vote synchronization protocol.
#[cfg_attr(feature = "serde", serde(with = "humantime_serde"))]
pub step: Duration,
}

impl Timeouts {
pub fn timeout_duration(&self, kind: TimeoutKind) -> Duration {
match kind {
TimeoutKind::Propose => self.propose,
TimeoutKind::Prevote => self.prevote,
TimeoutKind::Precommit => self.precommit,
TimeoutKind::Commit => self.commit,
TimeoutKind::PrevoteTimeLimit => self.step,
TimeoutKind::PrecommitTimeLimit => self.step,
}
}

pub fn delta_duration(&self, step: TimeoutKind) -> Option<Duration> {
match step {
TimeoutKind::Propose => Some(self.propose_delta),
TimeoutKind::Prevote => Some(self.prevote_delta),
TimeoutKind::Precommit => Some(self.precommit_delta),
TimeoutKind::Commit => None,
TimeoutKind::PrevoteTimeLimit => None,
TimeoutKind::PrecommitTimeLimit => None,
}
}
}

impl Default for Timeouts {
fn default() -> Self {
Self {
propose: Duration::from_secs(3),
propose_delta: Duration::from_millis(500),
prevote: Duration::from_secs(1),
prevote_delta: Duration::from_millis(500),
precommit: Duration::from_secs(1),
precommit_delta: Duration::from_millis(500),
commit: Duration::from_secs(0),
step: Duration::from_secs(30),
}
}
}
Loading
Loading