Skip to content

Commit

Permalink
Merge branch 'romac/app-channel-test' into romac/generic-test-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 10, 2025
2 parents 70a9078 + c52fcbe commit f956073
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
15 changes: 8 additions & 7 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,16 @@ 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));

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 next height, and provide it with the genesis validator set
Expand Down Expand Up @@ -172,7 +173,7 @@ pub async fn run(
// When that happens, we store the decided value in our store
state.commit(certificate).await?;

sleep(Duration::from_millis(100)).await;
sleep(Duration::from_millis(500)).await;

// And then we instruct consensus to start the next height
if reply
Expand Down
4 changes: 1 addition & 3 deletions code/crates/test/framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ where
decisions.fetch_add(1, Ordering::SeqCst);
}
Event::Published(msg) if is_full_node => {
panic!(
"Full nodes unexpectedly published a consensus message: {msg:?}"
);
panic!("Full node unexpectedly published a consensus message: {msg:?}");
}
_ => (),
}
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 f956073

Please sign in to comment.