-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df42f86
commit 659d8e0
Showing
7 changed files
with
190 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
```shell | ||
cargo run -- --file-path source_data/scrape_4.csv single -p 50000000000000000 -d 100000000000000 -s 18963 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use clap::{ | ||
Parser, | ||
Subcommand, | ||
}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum SimulationArgs { | ||
Single { | ||
/// DA P component | ||
#[arg(short, long)] | ||
p_component: i64, | ||
/// DA D component | ||
#[arg(short, long)] | ||
d_component: i64, | ||
/// Latest gas price | ||
#[arg(short, long)] | ||
start_gas_price: u64, | ||
}, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Args { | ||
/// Which simulation mode to run | ||
#[command(subcommand)] | ||
pub simulation: SimulationArgs, | ||
/// Data source file | ||
#[arg(short, long)] | ||
pub file_path: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 59 additions & 50 deletions
109
crates/services/gas_price_service/simulation/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,82 @@ | ||
use crate::{ | ||
data::get_data, | ||
cli::{ | ||
Args, | ||
SimulationArgs, | ||
}, | ||
data::{ | ||
get_data, | ||
Data, | ||
}, | ||
display::display_results, | ||
service::get_service_controller, | ||
simulation::simulation, | ||
}; | ||
use clap::{ | ||
Parser, | ||
Subcommand, | ||
}; | ||
use itertools::Itertools; | ||
use plotters::prelude::*; | ||
use std::{ | ||
env, | ||
path::PathBuf, | ||
}; | ||
use tracing_subscriber::{ | ||
layer::SubscriberExt, | ||
util::SubscriberInitExt, | ||
EnvFilter, | ||
Layer, | ||
service::{ | ||
get_service_controller, | ||
ConfigValues, | ||
MetadataValues, | ||
}, | ||
simulation::{ | ||
single_simulation, | ||
SimulationResults, | ||
}, | ||
tracing::configure_tracing, | ||
}; | ||
use clap::Parser; | ||
|
||
pub mod cli; | ||
pub mod data; | ||
pub mod data_sources; | ||
pub mod display; | ||
pub mod service; | ||
pub mod simulation; | ||
pub mod tracing; | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum DataSource { | ||
/// Load data from a CSV file. | ||
File { | ||
#[arg(short, long)] | ||
path: PathBuf, | ||
}, | ||
/// Generate arbitrary data (not supported yet). | ||
Generated, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
struct Args { | ||
#[command(subcommand)] | ||
data_source: DataSource, | ||
pub async fn run_single_simulation(data: Data) -> anyhow::Result<SimulationResults> { | ||
let starting_height = data.starting_height(); | ||
let config_values = ConfigValues { | ||
min_da_gas_price: 1000, | ||
max_da_gas_price: u64::MAX, | ||
da_p_component: 50_000_000__000_000_000, | ||
da_d_component: 100_000__000_000_000, | ||
}; | ||
let metadata_values = MetadataValues::new(starting_height, 18_963); | ||
let mut service_controller = | ||
get_service_controller(config_values, metadata_values).await?; | ||
let results = single_simulation(&data, &mut service_controller).await?; | ||
Ok(results) | ||
} | ||
|
||
fn configure_tracing() { | ||
let filter = match env::var_os("RUST_LOG") { | ||
Some(_) => { | ||
EnvFilter::try_from_default_env().expect("Invalid `RUST_LOG` provided") | ||
pub async fn run_a_simulation( | ||
args: SimulationArgs, | ||
data: Data, | ||
) -> anyhow::Result<SimulationResults> { | ||
match args { | ||
SimulationArgs::Single { | ||
p_component, | ||
d_component, | ||
start_gas_price, | ||
} => { | ||
let starting_height = data.starting_height(); | ||
let config_values = ConfigValues { | ||
min_da_gas_price: 1000, | ||
max_da_gas_price: u64::MAX, | ||
da_p_component: p_component, | ||
da_d_component: d_component, | ||
}; | ||
let metadata_values = MetadataValues::new(starting_height, start_gas_price); | ||
let mut service_controller = | ||
get_service_controller(config_values, metadata_values).await?; | ||
let results = single_simulation(&data, &mut service_controller).await?; | ||
Ok(results) | ||
} | ||
None => EnvFilter::new("info"), | ||
}; | ||
|
||
let fmt = tracing_subscriber::fmt::Layer::default() | ||
.with_level(true) | ||
.boxed(); | ||
|
||
tracing_subscriber::registry().with(fmt).with(filter).init(); | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
configure_tracing(); | ||
|
||
let args = Args::parse(); | ||
let data = get_data(&args.data_source)?; | ||
let starting_height = data.starting_height(); | ||
let mut service_controller = get_service_controller(starting_height).await?; | ||
let results = simulation(&data, &mut service_controller).await?; | ||
let data = get_data(&args.file_path)?; | ||
let results = run_single_simulation(data).await?; | ||
display_results(results)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
crates/services/gas_price_service/simulation/src/tracing.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::env; | ||
use tracing_subscriber::{ | ||
layer::SubscriberExt, | ||
util::SubscriberInitExt, | ||
EnvFilter, | ||
Layer, | ||
}; | ||
|
||
pub fn configure_tracing() { | ||
let filter = match env::var_os("RUST_LOG") { | ||
Some(_) => { | ||
EnvFilter::try_from_default_env().expect("Invalid `RUST_LOG` provided") | ||
} | ||
None => EnvFilter::new("info"), | ||
}; | ||
|
||
let fmt = tracing_subscriber::fmt::Layer::default() | ||
.with_level(true) | ||
.boxed(); | ||
|
||
tracing_subscriber::registry().with(fmt).with(filter).init(); | ||
} |