Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Jan 24, 2025
1 parent e684374 commit ea9004a
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 153 deletions.
2 changes: 2 additions & 0 deletions code/Cargo.lock

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

7 changes: 5 additions & 2 deletions code/crates/consensus-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ rust-version.workspace = true
readme = "../../../README.md"

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

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

[dependencies]
malachitebft-core-types = { workspace = true }
Expand All @@ -23,6 +24,8 @@ 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 }

Expand Down
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

0 comments on commit ea9004a

Please sign in to comment.