Skip to content

Commit

Permalink
Fix off-by-one error in starting height of test and example apps
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 10, 2025
1 parent b7e8ee4 commit bcbd49f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
11 changes: 5 additions & 6 deletions code/crates/test/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use malachitebft_app_channel::app::types::sync::RawDecidedValue;
use malachitebft_app_channel::app::types::ProposedValue;
use malachitebft_app_channel::{AppMsg, Channels, ConsensusMsg, NetworkMsg};
use malachitebft_test::codec::proto::ProtobufCodec;
use malachitebft_test::{Genesis, TestContext};
use malachitebft_test::{Genesis, Height, TestContext};

use crate::state::{decode_value, State};

Expand All @@ -25,15 +25,14 @@ pub async fn run(
// The first message to handle is the `ConsensusReady` message, signaling to the app
// that Malachite is ready to start consensus
AppMsg::ConsensusReady { reply } => {
info!("Consensus is ready");

let latest_height = state
let start_height = state
.store
.max_decided_value_height()
.await
.unwrap_or_default();
.map(|height| height.increment())
.unwrap_or_else(|| Height::new(1));

let start_height = latest_height.increment();
info!(%start_height, "Consensus is ready");

sleep(Duration::from_millis(200)).await;

Expand Down
16 changes: 10 additions & 6 deletions code/examples/channel/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::Duration;

use eyre::eyre;
use tokio::time::sleep;
use tracing::{error, info};

use malachitebft_app_channel::app::streaming::StreamContent;
Expand All @@ -8,7 +11,7 @@ use malachitebft_app_channel::app::types::sync::RawDecidedValue;
use malachitebft_app_channel::app::types::ProposedValue;
use malachitebft_app_channel::{AppMsg, Channels, ConsensusMsg, NetworkMsg};
use malachitebft_test::codec::proto::ProtobufCodec;
use malachitebft_test::TestContext;
use malachitebft_test::{Height, TestContext};

use crate::state::{decode_value, State};

Expand All @@ -18,15 +21,16 @@ pub async fn run(state: &mut State, channels: &mut Channels<TestContext>) -> eyr
// The first message to handle is the `ConsensusReady` message, signaling to the app
// that Malachite is ready to start consensus
AppMsg::ConsensusReady { reply } => {
info!("Consensus is ready");

let latest_height = state
let start_height = state
.store
.max_decided_value_height()
.await
.unwrap_or_default();
.map(|height| height.increment())
.unwrap_or_else(|| Height::new(1));

info!(%start_height, "Consensus is ready");

let start_height = latest_height.increment();
sleep(Duration::from_millis(200)).await;

// We can simply respond by telling the engine to start consensus
// at the current height, which is initially 1
Expand Down

0 comments on commit bcbd49f

Please sign in to comment.