Skip to content

Commit

Permalink
feat: configuration improvements (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Apr 1, 2024
1 parent ff56df1 commit 4a58113
Show file tree
Hide file tree
Showing 20 changed files with 337 additions and 200 deletions.
13 changes: 12 additions & 1 deletion config/importer-offline.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
CHAIN_ID=2008
CHAIN_ID=2008
EVMS=1

PERM_STORAGE=inmemory
PERM_STORAGE_CONNECTIONS=1
PERM_STORAGE_TIMEOUT=1000

TEMP_STORAGE=sled

EXTERNAL_RPC_STORAGE=postgres://postgres:123@localhost:5432/stratus
EXTERNAL_RPC_STORAGE_CONNECTIONS=1
EXTERNAL_RPC_STORAGE_TIMEOUT=1000
1 change: 0 additions & 1 deletion config/importer-offline.env.production

This file was deleted.

11 changes: 10 additions & 1 deletion config/importer-online.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
CHAIN_ID=2008
CHAIN_ID=2008
EVMS=1

EXTERNAL_RPC=http://spec.testnet.cloudwalk.network:9934/

PERM_STORAGE=inmemory
PERM_STORAGE_CONNECTIONS=1
PERM_STORAGE_TIMEOUT=1000

TEMP_STORAGE=inmemory
1 change: 0 additions & 1 deletion config/importer-online.env.production

This file was deleted.

5 changes: 5 additions & 0 deletions config/rpc-downloader.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXTERNAL_RPC=http://spec.testnet.cloudwalk.network:9934/

EXTERNAL_RPC_STORAGE=inmemory
EXTERNAL_RPC_STORAGE_CONNECTIONS=1
EXTERNAL_RPC_STORAGE_TIMEOUT=1000
8 changes: 8 additions & 0 deletions config/state-validator.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
METHOD=http://spec.testnet.cloudwalk.network:9934/

# storages
PERM_STORAGE=inmemory
PERM_STORAGE_CONNECTIONS=1
PERM_STORAGE_TIMEOUT=1000

TEMP_STORAGE=inmemory
9 changes: 8 additions & 1 deletion config/stratus.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
CHAIN_ID=2008
CHAIN_ID=2008
EVMS=1

PERM_STORAGE=inmemory
PERM_STORAGE_CONNECTIONS=1
PERM_STORAGE_TIMEOUT=1000

TEMP_STORAGE=inmemory
1 change: 0 additions & 1 deletion config/stratus.env.production

This file was deleted.

12 changes: 12 additions & 0 deletions config/test.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CHAIN_ID=2008
EVMS=1

TEMP_STORAGE=inmemory

PERM_STORAGE=inmemory
PERM_STORAGE_CONNECTIONS=1
PERM_STORAGE_TIMEOUT=1000

EXTERNAL_RPC_STORAGE=postgres://postgres:123@localhost:5432/stratus
EXTERNAL_RPC_STORAGE_CONNECTIONS=1
EXTERNAL_RPC_STORAGE_TIMEOUT=1000
18 changes: 7 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export RUST_BACKTRACE := "1"
export RUST_LOG := env("RUST_LOG", "stratus=info,rpc-downloader=info,importer-offline=info,importer-online=info,state-validator=info")

# Default URLs that can be passed as argument.
external_rpc_url := env("EXTERNAL_RPC_URL", "http://spec.testnet.cloudwalk.network:9934/")
external_rpc_storage := env("EXTERNAL_RPC_STORAGE", "postgres://postgres:[email protected]:5432/stratus")
perm_storage := env("PERM_STORAGE", "inmemory")
temp_storage := env("TEMP_STORAGE", "inmemory")
wait_service_timeout := env("WAIT_SERVICE_TIMEOUT", "1200")

# Project: Show available tasks
Expand Down Expand Up @@ -118,22 +114,22 @@ db-load-csv:

# Bin: Download external RPC blocks and receipts to temporary storage
bin-rpc-downloader *args="":
cargo run --bin rpc-downloader --features dev --release -- --external-rpc-storage {{external_rpc_storage}} --external-rpc {{external_rpc_url}} {{args}}
cargo run --bin rpc-downloader --features dev --release -- {{args}}
alias rpc-downloader := bin-rpc-downloader

# Bin: Import external RPC blocks from temporary storage to Stratus storage
bin-importer-offline *args="":
cargo run --bin importer-offline --features dev --release -- --external-rpc-storage {{external_rpc_storage}} --perm-storage {{perm_storage}} {{args}}
cargo run --bin importer-offline --features dev --release -- {{args}}
alias importer-offline := bin-importer-offline

# Bin: Import external RPC blocks from external RPC endpoint to Stratus storage
bin-importer-online *args="":
cargo run --bin importer-online --features dev --release -- --external-rpc {{external_rpc_url}} --perm-storage {{perm_storage}} {{args}}
cargo run --bin importer-online --features dev --release -- {{args}}
alias importer-online := bin-importer-online

# Bin: Validate Stratus storage slots matches reference slots
bin-state-validator *args="":
cargo run --bin state-validator --features dev --release -- --method {{external_rpc_url}} {{args}}
cargo run --bin state-validator --features dev --release -- {{args}}
alias state-validator := bin-state-validator

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -252,7 +248,7 @@ e2e-stratus-postgres test="":
wait-service --tcp 0.0.0.0:5432 -t {{ wait_service_timeout }} -- echo

echo "-> Starting Stratus"
RUST_LOG=debug just run -a 0.0.0.0:3000 --perm-storage {{perm_storage}} > stratus.log &
RUST_LOG=debug just run -a 0.0.0.0:3000 > stratus.log &

echo "-> Waiting Stratus to start"
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo
Expand Down Expand Up @@ -310,7 +306,7 @@ e2e-flamegraph:

# Run cargo flamegraph with necessary environment variables
echo "Running cargo flamegraph"
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin importer-online --deterministic --features dev,perf -- --external-rpc=http://localhost:3003/rpc --perm-storage={{perm_storage}}
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin importer-online --deterministic --features dev,perf -- --external-rpc=http://localhost:3003/rpc

# ------------------------------------------------------------------------------
# Contracts tasks
Expand Down Expand Up @@ -381,7 +377,7 @@ contracts-test-stratus-postgres *args="":
wait-service --tcp 0.0.0.0:5432 -t {{ wait_service_timeout }} -- echo

echo "-> Starting Stratus"
RUST_LOG=debug just run-release -a 0.0.0.0:3000 --perm-storage {{perm_storage}} > stratus.log &
RUST_LOG=debug just run-release -a 0.0.0.0:3000 > stratus.log &

echo "-> Waiting Stratus to start"
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo
Expand Down
13 changes: 8 additions & 5 deletions src/bin/importer_offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ const CSV_CHUNKING_BLOCKS_INTERVAL: u64 = 250_000;

type BacklogTask = (Vec<ExternalBlock>, Vec<ExternalReceipt>);

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// init services
fn main() -> anyhow::Result<()> {
let config: ImporterOfflineConfig = init_global_services();
let runtime = config.init_runtime();
runtime.block_on(run(config))
}

async fn run(config: ImporterOfflineConfig) -> anyhow::Result<()> {
let rpc_storage = config.rpc_storage.init().await?;
let stratus_storage = config.init_stratus_storage().await?;
let executor = config.init_executor(Arc::clone(&stratus_storage));
let stratus_storage = config.stratus_storage.init().await?;
let executor = config.executor.init(Arc::clone(&stratus_storage));

let block_start = match config.block_start {
Some(start) => BlockNumber::from(start),
Expand Down
14 changes: 9 additions & 5 deletions src/bin/importer_online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ use stratus::log_and_err;
/// Number of transactions receipts that can be fetched in parallel.
const RECEIPTS_PARALELLISM: usize = 10;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
// init services
fn main() -> anyhow::Result<()> {
let config: ImporterOnlineConfig = init_global_services();
let runtime = config.init_runtime();
runtime.block_on(run(config))
}

async fn run(config: ImporterOnlineConfig) -> anyhow::Result<()> {
// init services
let chain = BlockchainClient::new(&config.external_rpc).await?;
let storage = Arc::new(config.init_stratus_storage().await?);
let executor = config.init_executor(Arc::clone(&storage));
let storage = Arc::new(config.stratus_storage.init().await?);
let executor = config.executor.init(Arc::clone(&storage));

// start from last imported block
let mut number = storage.read_mined_block_number().await?;
Expand Down
9 changes: 6 additions & 3 deletions src/bin/rpc_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ use stratus::log_and_err;
/// Number of blocks each parallel download will process.
const BLOCKS_BY_TASK: usize = 1_000;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
// init services
fn main() -> anyhow::Result<()> {
let config: RpcDownloaderConfig = init_global_services();
let runtime = config.init_runtime();
runtime.block_on(run(config))
}

async fn run(config: RpcDownloaderConfig) -> anyhow::Result<()> {
let rpc_storage = config.rpc_storage.init().await?;
let chain = Arc::new(BlockchainClient::new(&config.external_rpc).await?);

Expand Down
11 changes: 7 additions & 4 deletions src/bin/state_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ use stratus::infra::BlockchainClient;
use stratus::init_global_services;
use tokio::task::JoinSet;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
// init services
fn main() -> anyhow::Result<()> {
let config: StateValidatorConfig = init_global_services();
let storage = config.init_stratus_storage().await?;
let runtime = config.init_runtime();
runtime.block_on(run(config))
}

async fn run(config: StateValidatorConfig) -> anyhow::Result<()> {
let storage = config.stratus_storage.init().await?;

let interval = BlockNumber::from(config.interval);

Expand Down
Loading

0 comments on commit 4a58113

Please sign in to comment.