From f0b9d2fae5a6bb311205054aece9b39d910bd74b Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 10 Nov 2023 16:59:37 +0100 Subject: [PATCH] Rename `Client` to `Env` (#60) --- Code/driver/src/driver.rs | 20 ++++++++++---------- Code/driver/src/{client.rs => env.rs} | 4 ++-- Code/driver/src/lib.rs | 4 ++-- Code/test/src/{client.rs => env.rs} | 8 ++++---- Code/test/src/lib.rs | 4 ++-- Code/test/tests/driver.rs | 18 +++++++++--------- 6 files changed, 29 insertions(+), 29 deletions(-) rename Code/driver/src/{client.rs => env.rs} (81%) rename Code/test/src/{client.rs => env.rs} (80%) diff --git a/Code/driver/src/driver.rs b/Code/driver/src/driver.rs index 40b7379c6..989b4870a 100644 --- a/Code/driver/src/driver.rs +++ b/Code/driver/src/driver.rs @@ -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 +pub struct Driver where Ctx: Context, - Client: EnvClient, + Env: DriverEnv, PSel: ProposerSelector, { pub ctx: Ctx, - pub client: Client, + pub env: Env, pub proposer_selector: PSel, pub height: Ctx::Height, @@ -42,15 +42,15 @@ where pub round_states: BTreeMap>, } -impl Driver +impl Driver where Ctx: Context, - Client: EnvClient, + Env: DriverEnv, PSel: ProposerSelector, { pub fn new( ctx: Ctx, - client: Client, + env: Env, proposer_selector: PSel, height: Ctx::Height, validator_set: Ctx::ValidatorSet, @@ -61,7 +61,7 @@ where Self { ctx, - client, + env, proposer_selector, height, private_key: Secret::new(private_key), @@ -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) -> Option> { diff --git a/Code/driver/src/client.rs b/Code/driver/src/env.rs similarity index 81% rename from Code/driver/src/client.rs rename to Code/driver/src/env.rs index 29c1c0db3..9db809aa6 100644 --- a/Code/driver/src/client.rs +++ b/Code/driver/src/env.rs @@ -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 +pub trait Env where Ctx: Context, { diff --git a/Code/driver/src/lib.rs b/Code/driver/src/lib.rs index 1e63c9a93..5f94bcce3 100644 --- a/Code/driver/src/lib.rs +++ b/Code/driver/src/lib.rs @@ -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; diff --git a/Code/test/src/client.rs b/Code/test/src/env.rs similarity index 80% rename from Code/test/src/client.rs rename to Code/test/src/env.rs index 3973f766e..a2a2de412 100644 --- a/Code/test/src/client.rs +++ b/Code/test/src/env.rs @@ -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 for TestClient { +impl Env for TestEnv { async fn get_value(&self) -> Value { self.value.clone() } diff --git a/Code/test/src/lib.rs b/Code/test/src/lib.rs index 18c06ffb6..8e09b3a31 100644 --- a/Code/test/src/lib.rs +++ b/Code/test/src/lib.rs @@ -2,8 +2,8 @@ #![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; @@ -11,8 +11,8 @@ 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::*; diff --git a/Code/test/tests/driver.rs b/Code/test/tests/driver.rs index ca3300a85..026d8251c 100644 --- a/Code/test/tests/driver.rs +++ b/Code/test/tests/driver.rs @@ -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; @@ -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); @@ -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)); @@ -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); @@ -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)); @@ -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); @@ -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)); @@ -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); @@ -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