Skip to content

Commit

Permalink
fix: changed scheduling to instant
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaMasych committed Sep 11, 2024
1 parent 3d99cc0 commit b421020
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Definitions central to BPCon configuration.

use std::time::Duration;
use tokio::time::Instant;

/// Configuration structure for BPCon.
///
Expand All @@ -22,11 +23,11 @@ pub struct BPConConfig {
/// The quorum is the minimum weight required to make decisions in the BPCon protocol.
pub threshold: u128,

/// Timeout before the ballot is launched.
/// Absolute time, at which party begins to work.
///
/// This timeout differs from `launch1a_timeout` as it applies to a distinct status
/// and does not involve listening to external events and messages.
pub launch_timeout: Duration,
pub launch_at: Instant,

/// Timeout before the 1a stage is launched.
///
Expand Down Expand Up @@ -96,7 +97,7 @@ impl BPConConfig {
party_weights,
threshold,
// TODO: deduce actually good defaults.
launch_timeout: Duration::from_millis(0),
launch_at: Instant::now(),
launch1a_timeout: Duration::from_millis(200),
launch1b_timeout: Duration::from_millis(400),
launch2a_timeout: Duration::from_millis(600),
Expand Down
6 changes: 2 additions & 4 deletions src/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::cmp::PartialEq;
use std::collections::hash_map::Entry::Vacant;
use std::collections::{HashMap, HashSet};
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tokio::time::sleep;
use tokio::time::{sleep, sleep_until};

/// Represents the status of a `Party` in the BPCon consensus protocol.
///
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
pub async fn launch_ballot(&mut self) -> Result<V, LaunchBallotError> {
self.prepare_next_ballot()?;

sleep(self.cfg.launch_timeout).await;
sleep_until(self.cfg.launch_at).await;

let launch1a_timer = sleep(self.cfg.launch1a_timeout);
let launch1b_timer = sleep(self.cfg.launch1b_timeout);
Expand Down Expand Up @@ -939,8 +939,6 @@ mod tests {
_ = party.launch_ballot().await;
});

time::advance(cfg.launch_timeout).await;

// Sequential time advance and event check.

time::advance(cfg.launch1a_timeout).await;
Expand Down
2 changes: 1 addition & 1 deletion tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async fn test_ballot_many_parties() {
let cfg = BPConConfig {
party_weights,
threshold,
launch_timeout: Duration::from_secs(0),
launch_at: Instant::now(),
launch1a_timeout: Duration::from_secs(0), // 1a's and 2a's are sent only by leader
launch1b_timeout: Duration::from_secs(1), // meaning we need to wait less.
launch2a_timeout: Duration::from_secs(5),
Expand Down

0 comments on commit b421020

Please sign in to comment.