Skip to content

Commit

Permalink
Merge branch 'main' into remove-dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Aug 6, 2024
2 parents 394316c + e2bc7be commit 8dcb103
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
10 changes: 10 additions & 0 deletions config/stratus-follower.env.local
Original file line number Diff line number Diff line change
@@ -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/
6 changes: 2 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:5432/stratus")
external_rpc := "http://spec.testnet.cloudwalk.network:9934/"
external_rpc_ws := "ws://spec.testnet.cloudwalk.network:9946/"

# Project: Show available tasks
default:
Expand Down Expand Up @@ -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="":
Expand Down
15 changes: 11 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/eth/consensus/simple_consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 5 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,26 @@ 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
};

// Init consensus
let consensus: Arc<dyn Consensus> = 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
Expand Down

0 comments on commit 8dcb103

Please sign in to comment.