Skip to content

Commit

Permalink
Merge branch 'main' into anca/starknet_parts_only
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Feb 12, 2025
2 parents bda4753 + 490766e commit 7c5de2e
Show file tree
Hide file tree
Showing 52 changed files with 1,308 additions and 1,778 deletions.
51 changes: 11 additions & 40 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,20 @@ jobs:
tool: cargo-maelstrom
- name: Disable apparmor container restrictions
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Run integration tests
# MBT tests don't work with maelstrom, but they execute successfully with nextest
- name: Run integration tests (discovery)
run: |
cargo maelstrom \
--slots 16 \
--include 'package.equals(informalsystems-malachitebft-starknet-test) || package.equals(informalsystems-malachitebft-discovery-test)' \
cargo maelstrom --slots 8 \
--include 'package.equals(informalsystems-malachitebft-discovery-test)'
- name: Run integration tests (Starknet app)
run: |
cargo maelstrom --slots 8 \
--include 'package.equals(informalsystems-malachitebft-starknet-test)' \
--exclude 'package.match(informalsystems-malachitebft-starknet-test-mbt)'
integration_test_app:
name: Integration Tests (test app)
runs-on: ubuntu-latest
defaults:
run:
working-directory: code
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install Quint
run: npm install -g @informalsystems/quint
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache-workspaces: "code"
- name: Install cargo-maelstrom
uses: taiki-e/install-action@v2
with:
tool: cargo-maelstrom
- name: Disable apparmor container restrictions
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Run integration tests
continue-on-error: true
- name: Run integration tests (Test app)
run: |
cargo maelstrom \
--slots 8 \
--include 'package.equals(informalsystems-malachitebft-test)'
cargo maelstrom --slots 8 \
--include 'package.equals(informalsystems-malachitebft-test)' \
--exclude 'package.equals(informalsystems-malachitebft-test-mbt)'
no_std:
name: no_std compatibility
Expand Down
7 changes: 6 additions & 1 deletion code/Cargo.lock

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

2 changes: 1 addition & 1 deletion code/crates/app-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ mod msgs;
pub use msgs::{AppMsg, Channels, ConsensusMsg, NetworkMsg, Reply};

mod run;
pub use run::{start_engine, EngineHandle};
pub use run::start_engine;
14 changes: 4 additions & 10 deletions code/crates/app-channel/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
use eyre::Result;

use malachitebft_app::spawn::{
spawn_consensus_actor, spawn_node_actor, spawn_sync_actor, spawn_wal_actor,
};
use malachitebft_engine::node::NodeRef;
use malachitebft_engine::util::events::TxEvent;
use tokio::task::JoinHandle;

use crate::app;
use crate::app::spawn::{
spawn_consensus_actor, spawn_node_actor, spawn_sync_actor, spawn_wal_actor,
};
use crate::app::types::codec::{ConsensusCodec, SyncCodec, WalCodec};
use crate::app::types::config::Config as NodeConfig;
use crate::app::types::core::Context;
use crate::app::types::metrics::{Metrics, SharedRegistry};
use crate::app::EngineHandle;
use crate::spawn::{spawn_host_actor, spawn_network_actor};
use crate::Channels;

pub struct EngineHandle {
pub actor: NodeRef,
pub handle: JoinHandle<()>,
}

#[tracing::instrument("node", skip_all, fields(moniker = %cfg.moniker))]
pub async fn start_engine<Node, Ctx, Codec>(
ctx: Ctx,
Expand Down
4 changes: 2 additions & 2 deletions code/crates/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// )]

mod node;
pub use node::Node;
pub use node::{EngineHandle, Node, NodeHandle};

pub mod part_store;
pub mod spawn;
pub mod types;

pub mod events {
pub use malachitebft_engine::util::events::TxEvent;
pub use malachitebft_engine::util::events::{RxEvent, TxEvent};
}

pub mod streaming {
Expand Down
29 changes: 26 additions & 3 deletions code/crates/app/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
use std::io;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use async_trait::async_trait;
use malachitebft_core_types::SigningProvider;
use rand::{CryptoRng, RngCore};
use serde::de::DeserializeOwned;
use serde::Serialize;
use tokio::task::JoinHandle;

use malachitebft_core_types::SigningProvider;
use malachitebft_engine::node::NodeRef;
use malachitebft_engine::util::events::RxEvent;

use crate::types::core::{Context, PrivateKey, PublicKey, VotingPower};
use crate::types::Keypair;

pub struct EngineHandle {
pub actor: NodeRef,
pub handle: JoinHandle<()>,
}

#[async_trait]
pub trait NodeHandle<Ctx>
where
Self: Send + Sync + 'static,
Ctx: Context,
{
fn subscribe(&self) -> RxEvent<Ctx>;

async fn kill(&self, reason: Option<String>) -> eyre::Result<()>;
}

#[async_trait]
pub trait Node {
type Context: Context;
type Genesis: Serialize + DeserializeOwned;
type PrivateKeyFile: Serialize + DeserializeOwned;
type SigningProvider: SigningProvider<Self::Context>;
type NodeHandle: NodeHandle<Self::Context>;

fn get_home_dir(&self) -> PathBuf;

Expand All @@ -39,12 +60,14 @@ pub trait Node {
fn get_signing_provider(&self, private_key: PrivateKey<Self::Context>)
-> Self::SigningProvider;

fn load_genesis(&self, path: impl AsRef<Path>) -> io::Result<Self::Genesis>;
fn load_genesis(&self) -> io::Result<Self::Genesis>;

fn make_genesis(
&self,
validators: Vec<(PublicKey<Self::Context>, VotingPower)>,
) -> Self::Genesis;

async fn start(&self) -> eyre::Result<Self::NodeHandle>;

async fn run(self) -> eyre::Result<()>;
}
4 changes: 2 additions & 2 deletions code/crates/core-state-machine/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::transition::Transition;
#[cfg(feature = "debug")]
use crate::traces::*;

use malachitebft_core_types::{Context, Round};
use malachitebft_core_types::{Context, Height, Round};

/// A value and its associated round
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -152,6 +152,6 @@ where
Ctx: Context,
{
fn default() -> Self {
Self::new(Ctx::Height::default(), Round::Nil)
Self::new(Ctx::Height::ZERO, Round::Nil)
}
}
11 changes: 9 additions & 2 deletions code/crates/core-types/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ use core::fmt::{Debug, Display};
/// A height of 0 represents a chain which has not yet produced a block.
pub trait Height
where
Self:
Default + Copy + Clone + Debug + Display + PartialEq + Eq + PartialOrd + Ord + Send + Sync,
Self: Copy + Clone + Default + Debug + Display + Eq + Ord + Send + Sync,
{
/// The zero-th height. Typically 0.
///
/// This value must be the same as the one built by the `Default` impl.
const ZERO: Self;

/// The initial height. Typically 1.
const INITIAL: Self;

/// Increment the height by one.
fn increment(&self) -> Self {
self.increment_by(1)
Expand Down
4 changes: 2 additions & 2 deletions code/crates/engine/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ractor::{async_trait, Actor, ActorProcessingErr, ActorRef, RpcReplyPort, Spa
use tokio::sync::{mpsc, oneshot};
use tracing::{debug, error, info};

use malachitebft_core_types::Context;
use malachitebft_core_types::{Context, Height};
use malachitebft_metrics::SharedRegistry;
use malachitebft_wal as wal;

Expand Down Expand Up @@ -204,7 +204,7 @@ where
let handle = self::thread::spawn(self.span.clone(), log, args.codec, rx);

Ok(State {
height: Ctx::Height::default(),
height: Ctx::Height::ZERO,
wal_sender: tx,
_handle: handle,
})
Expand Down
8 changes: 0 additions & 8 deletions code/crates/starknet/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub fn main() -> color_eyre::Result<()> {
let node = &StarknetNode {
home_dir: args.get_home_dir().unwrap(),
config: Default::default(), // placeholder, because `init` and `testnet` has no valid configuration file.
genesis_file: args.get_genesis_file_path().unwrap(),
private_key_file: args.get_priv_validator_key_file_path().unwrap(),
start_height: Default::default(), // placeholder, because start_height is only valid in StartCmd.
};

Expand Down Expand Up @@ -68,8 +66,6 @@ pub fn main() -> color_eyre::Result<()> {
let node = StarknetNode {
home_dir: args.get_home_dir().unwrap(),
config,
genesis_file: args.get_genesis_file_path().unwrap(),
private_key_file: args.get_priv_validator_key_file_path().unwrap(),
start_height: cmd.start_height,
};

Expand Down Expand Up @@ -119,8 +115,6 @@ mod tests {
let node = &StarknetNode {
home_dir: tmp.path().to_owned(),
config: Default::default(),
genesis_file: PathBuf::from("genesis.json"),
private_key_file: PathBuf::from("priv_validator_key.json"),
start_height: Default::default(),
};
cmd.run(
Expand Down Expand Up @@ -167,8 +161,6 @@ mod tests {
let node = &StarknetNode {
home_dir: tmp.path().to_owned(),
config: Default::default(),
genesis_file: PathBuf::from("genesis.json"),
private_key_file: PathBuf::from("priv_validator_key.json"),
start_height: Default::default(),
};
cmd.run(
Expand Down
6 changes: 4 additions & 2 deletions code/crates/starknet/host/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Host {
state: &mut HostState,
) -> Result<(), ActorProcessingErr> {
match msg {
HostMsg::ConsensusReady(consensus) => on_consensus_ready(state, consensus),
HostMsg::ConsensusReady(consensus) => on_consensus_ready(state, consensus).await,

HostMsg::StartedRound {
height,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Host {
}
}

fn on_consensus_ready(
async fn on_consensus_ready(
state: &mut HostState,
consensus: ConsensusRef<MockContext>,
) -> Result<(), ActorProcessingErr> {
Expand All @@ -234,6 +234,8 @@ fn on_consensus_ready(

state.consensus = Some(consensus.clone());

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

consensus.cast(ConsensusMsg::StartHeight(
start_height,
state.host.validator_set.clone(),
Expand Down
Loading

0 comments on commit 7c5de2e

Please sign in to comment.