Skip to content

Commit

Permalink
Merge branch 'main' into anca/adr-overall-architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 10, 2023
2 parents 6d1ba70 + f0b9d2f commit e2d551b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
20 changes: 10 additions & 10 deletions Code/driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ use malachite_vote::keeper::Message as VoteMessage;
use malachite_vote::keeper::VoteKeeper;
use malachite_vote::Threshold;

use crate::client::Client as EnvClient;
use crate::env::Env as DriverEnv;
use crate::event::Event;
use crate::message::Message;
use crate::ProposerSelector;

/// Driver for the state machine of the Malachite consensus engine at a given height.
#[derive(Clone, Debug)]
pub struct Driver<Ctx, Client, PSel>
pub struct Driver<Ctx, Env, PSel>
where
Ctx: Context,
Client: EnvClient<Ctx>,
Env: DriverEnv<Ctx>,
PSel: ProposerSelector<Ctx>,
{
pub ctx: Ctx,
pub client: Client,
pub env: Env,
pub proposer_selector: PSel,

pub height: Ctx::Height,
Expand All @@ -42,15 +42,15 @@ where
pub round_states: BTreeMap<Round, RoundState<Ctx>>,
}

impl<Ctx, Client, PSel> Driver<Ctx, Client, PSel>
impl<Ctx, Env, PSel> Driver<Ctx, Env, PSel>
where
Ctx: Context,
Client: EnvClient<Ctx>,
Env: DriverEnv<Ctx>,
PSel: ProposerSelector<Ctx>,
{
pub fn new(
ctx: Ctx,
client: Client,
env: Env,
proposer_selector: PSel,
height: Ctx::Height,
validator_set: Ctx::ValidatorSet,
Expand All @@ -61,7 +61,7 @@ where

Self {
ctx,
client,
env,
proposer_selector,
height,
private_key: Secret::new(private_key),
Expand All @@ -74,11 +74,11 @@ where
}

async fn get_value(&self) -> Ctx::Value {
self.client.get_value().await
self.env.get_value().await
}

async fn validate_proposal(&self, proposal: &Ctx::Proposal) -> bool {
self.client.validate_proposal(proposal).await
self.env.validate_proposal(proposal).await
}

pub async fn execute(&mut self, msg: Event<Ctx>) -> Option<Message<Ctx>> {
Expand Down
4 changes: 2 additions & 2 deletions Code/driver/src/client.rs → Code/driver/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use async_trait::async_trait;

use malachite_common::Context;

/// Client for use by the [`Driver`](crate::Driver) to ask
/// Environment for use by the [`Driver`](crate::Driver) to ask
/// for a value to propose and validate proposals.
#[async_trait]
pub trait Client<Ctx>
pub trait Env<Ctx>
where
Ctx: Context,
{
Expand Down
4 changes: 2 additions & 2 deletions Code/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

extern crate alloc;

mod client;
mod driver;
mod env;
mod event;
mod message;
mod proposer;

pub use client::Client;
pub use driver::Driver;
pub use env::Env;
pub use event::Event;
pub use message::Message;
pub use proposer::ProposerSelector;
Expand Down
8 changes: 4 additions & 4 deletions Code/test/src/client.rs → Code/test/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use async_trait::async_trait;

use malachite_driver::Client;
use malachite_driver::Env;

use crate::{Proposal, TestContext, Value};

pub struct TestClient {
pub struct TestEnv {
pub value: Value,
pub is_valid: fn(&Proposal) -> bool,
}

impl TestClient {
impl TestEnv {
pub fn new(value: Value, is_valid: fn(&Proposal) -> bool) -> Self {
Self { value, is_valid }
}
}

#[async_trait]
impl Client<TestContext> for TestClient {
impl Env<TestContext> for TestEnv {
async fn get_value(&self) -> Value {
self.value.clone()
}
Expand Down
4 changes: 2 additions & 2 deletions Code/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#![deny(trivial_casts, trivial_numeric_casts)]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

mod client;
mod context;
mod env;
mod height;
mod proposal;
mod signing;
mod validator_set;
mod value;
mod vote;

pub use crate::client::*;
pub use crate::context::*;
pub use crate::env::*;
pub use crate::height::*;
pub use crate::proposal::*;
pub use crate::signing::*;
Expand Down
18 changes: 9 additions & 9 deletions Code/test/tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use malachite_driver::{Driver, Event, Message, ProposerSelector};
use malachite_round::state::{RoundValue, State, Step};

use malachite_test::{
Address, Height, PrivateKey, Proposal, TestClient, TestContext, Validator, ValidatorSet, Vote,
Address, Height, PrivateKey, Proposal, TestContext, TestEnv, Validator, ValidatorSet, Vote,
};
use rand::rngs::StdRng;
use rand::SeedableRng;
Expand Down Expand Up @@ -46,7 +46,7 @@ fn driver_steps_proposer() {
let value_id = value.id();

let sel = RotateProposer::default();
let client = TestClient::new(value.clone(), |_| true);
let env = TestEnv::new(value.clone(), |_| true);

let mut rng = StdRng::seed_from_u64(0x42);

Expand All @@ -67,7 +67,7 @@ fn driver_steps_proposer() {
let ctx = TestContext::new(my_sk.clone());

let vs = ValidatorSet::new(vec![v1, v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, client, sel, Height::new(1), vs, my_sk.clone(), my_addr);
let mut driver = Driver::new(ctx, env, sel, Height::new(1), vs, my_sk.clone(), my_addr);

let proposal = Proposal::new(Height::new(1), Round::new(0), value.clone(), Round::new(-1));

Expand Down Expand Up @@ -241,7 +241,7 @@ fn driver_steps_not_proposer_valid() {
let value_id = value.id();

let sel = RotateProposer::default();
let client = TestClient::new(value.clone(), |_| true);
let env = TestEnv::new(value.clone(), |_| true);

let mut rng = StdRng::seed_from_u64(0x42);

Expand All @@ -263,7 +263,7 @@ fn driver_steps_not_proposer_valid() {
let ctx = TestContext::new(my_sk.clone());

let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, client, sel, Height::new(1), vs, my_sk.clone(), my_addr);
let mut driver = Driver::new(ctx, env, sel, Height::new(1), vs, my_sk.clone(), my_addr);

let proposal = Proposal::new(Height::new(1), Round::new(0), value.clone(), Round::new(-1));

Expand Down Expand Up @@ -437,7 +437,7 @@ fn driver_steps_not_proposer_invalid() {
let value_id = value.id();

let sel = RotateProposer::default();
let client = TestClient::new(value.clone(), |_| false);
let env = TestEnv::new(value.clone(), |_| false);

let mut rng = StdRng::seed_from_u64(0x42);

Expand All @@ -459,7 +459,7 @@ fn driver_steps_not_proposer_invalid() {
let ctx = TestContext::new(my_sk.clone());

let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, client, sel, Height::new(1), vs, my_sk.clone(), my_addr);
let mut driver = Driver::new(ctx, env, sel, Height::new(1), vs, my_sk.clone(), my_addr);

let proposal = Proposal::new(Height::new(1), Round::new(0), value.clone(), Round::new(-1));

Expand Down Expand Up @@ -579,7 +579,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() {
let value_id = value.id();

let sel = RotateProposer::default();
let client = TestClient::new(value.clone(), |_| true);
let env = TestEnv::new(value.clone(), |_| true);

let mut rng = StdRng::seed_from_u64(0x42);

Expand All @@ -601,7 +601,7 @@ fn driver_steps_not_proposer_timeout_multiple_rounds() {
let ctx = TestContext::new(my_sk.clone());

let vs = ValidatorSet::new(vec![v1.clone(), v2.clone(), v3.clone()]);
let mut driver = Driver::new(ctx, client, sel, Height::new(1), vs, my_sk.clone(), my_addr);
let mut driver = Driver::new(ctx, env, sel, Height::new(1), vs, my_sk.clone(), my_addr);

let steps = vec![
// Start round 0, we, v3, are not the proposer
Expand Down

0 comments on commit e2d551b

Please sign in to comment.