From 6d5524212109418c035fdf56c95c7e20527e836c Mon Sep 17 00:00:00 2001 From: gabriel-aranha-cw <166405807+gabriel-aranha-cw@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:02:38 -0300 Subject: [PATCH 1/2] enha: allow custom env when local (#1602) --- config/stratus-follower.env.local | 10 ++++++++++ justfile | 6 ++---- src/config.rs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 config/stratus-follower.env.local diff --git a/config/stratus-follower.env.local b/config/stratus-follower.env.local new file mode 100644 index 000000000..fc4272a38 --- /dev/null +++ b/config/stratus-follower.env.local @@ -0,0 +1,10 @@ +RUST_LOG=info,stratus::eth::rpc::rpc_subscriptions::rx=off,stratus::eth::consensus::rx=off,stratus::eth::consensus=off,jsonrpsee-server=debug + +CHAIN_ID=2008 +EVMS=1 + +PERM_STORAGE=inmemory +TEMP_STORAGE=inmemory + +EXTERNAL_RPC=http://spec.testnet.cloudwalk.network:9934/ +EXTERNAL_RPC_WS=ws://spec.testnet.cloudwalk.network:9946/ diff --git a/justfile b/justfile index 9465a7253..b6e883218 100644 --- a/justfile +++ b/justfile @@ -8,8 +8,6 @@ export RUST_BACKTRACE := env("RUST_BACKTRACE", "0") nightly_flag := if env("NIGHTLY", "") =~ "(true|1)" { "+nightly" } else { "" } release_flag := if env("RELEASE", "") =~ "(true|1)" { "--release" } else { "" } database_url := env("DATABASE_URL", "postgres://postgres:123@0.0.0.0:5432/stratus") -external_rpc := "http://spec.testnet.cloudwalk.network:9934/" -external_rpc_ws := "ws://spec.testnet.cloudwalk.network:9946/" # Project: Show available tasks default: @@ -92,8 +90,8 @@ stratus *args="": cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --leader {{args}} # Bin: Stratus main service as follower -stratus-follower external_rpc=external_rpc external_rpc_ws=external_rpc_ws *args="": - cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --follower --external-rpc {{external_rpc}} --external-rpc-ws {{external_rpc_ws}} {{args}} +stratus-follower *args="": + LOCAL_ENV_PATH=stratus-follower cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --follower {{args}} # Bin: Download external RPC blocks and receipts to temporary storage rpc-downloader *args="": diff --git a/src/config.rs b/src/config.rs index 24e9de709..3a2f5b9c2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,16 +35,23 @@ pub fn load_dotenv_file() { Ok(env) => Environment::from_str(env.as_str()), Err(_) => Ok(Environment::Local), }; - let env = match env { - Ok(env) => env, + + // determine the .env file to load + let env_filename = match env { + Ok(Environment::Local) => { + // local environment only + match std::env::var("LOCAL_ENV_PATH") { + Ok(local_path) => format!("config/{}.env.local", local_path), + Err(_) => format!("config/{}.env.local", build_info::binary_name()), + } + } + Ok(env) => format!("config/{}.env.{}", build_info::binary_name(), env), Err(e) => { println!("{e}"); return; } }; - // load .env file - let env_filename = format!("config/{}.env.{}", build_info::binary_name(), env); println!("reading env file | filename={}", env_filename); if let Err(e) = dotenvy::from_filename(env_filename) { From e2bc7be9d0efcecee4de0f9cc1132ed999a10c1f Mon Sep 17 00:00:00 2001 From: carneiro-cw <156914855+carneiro-cw@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:06:41 -0300 Subject: [PATCH 2/2] chore: reafac main.rs importer initialization (#1603) --- src/eth/consensus/simple_consensus/mod.rs | 1 + src/main.rs | 21 +++++---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/eth/consensus/simple_consensus/mod.rs b/src/eth/consensus/simple_consensus/mod.rs index 5ec4d1eb6..45b9aaa01 100644 --- a/src/eth/consensus/simple_consensus/mod.rs +++ b/src/eth/consensus/simple_consensus/mod.rs @@ -28,6 +28,7 @@ impl Consensus for SimpleConsensus { fn should_forward(&self) -> bool { self.blockchain_client.is_some() } + async fn should_serve(&self) -> bool { let Some(blockchain_client) = &self.blockchain_client else { return true; diff --git a/src/main.rs b/src/main.rs index 2e93f4d85..927c94770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,17 +26,19 @@ async fn run(config: StratusConfig) -> anyhow::Result<()> { // Init executor let executor = config.executor.init(Arc::clone(&storage), Arc::clone(&miner)); - // Init chain + // Init importer let chain = if config.follower { let importer_config = config.importer.as_ref().ok_or(anyhow::anyhow!("importer config is not set"))?; - Some(Arc::new( + let chain = Arc::new( BlockchainClient::new_http_ws( importer_config.external_rpc.as_ref(), importer_config.external_rpc_ws.as_deref(), importer_config.external_rpc_timeout, ) .await?, - )) + ); + importer_config.init(Arc::clone(&executor), Arc::clone(&miner), Arc::clone(&storage), Arc::clone(&chain))?; + Some(chain) } else { None }; @@ -44,19 +46,6 @@ async fn run(config: StratusConfig) -> anyhow::Result<()> { // Init consensus let consensus: Arc = Arc::new(SimpleConsensus::new(Arc::clone(&storage), chain.clone())); - // Init importer - if config.follower { - if let Some(importer_config) = &config.importer { - if let Some(chain) = chain { - importer_config.init(Arc::clone(&executor), Arc::clone(&miner), Arc::clone(&storage), chain)?; - } else { - return Err(anyhow::anyhow!("chain is not initialized")); - } - } else { - return Err(anyhow::anyhow!("importer config is not set")); - } - } - // Init RPC server serve_rpc( // Services