Skip to content

Commit beea55e

Browse files
feat: config
1 parent e2ee926 commit beea55e

12 files changed

Lines changed: 371 additions & 87 deletions

File tree

Cargo.lock

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configs/default.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[network]
2+
target_url = "http://127.0.0.1:8545"
3+
total_connections = 10_000 # Limited by # of ephemeral ports.
4+
5+
batch_factor = 1
6+
7+
error_sleep_ms = 100
8+
tx_queue_empty_sleep_ms = 25
9+
10+
[transaction]
11+
chain_id = 1337
12+
num_accounts = 25_000 # Limited by the number in the genesis (see generate_genesis_alloc.rs)
13+
14+
token_contract_address = "0x2000000000000000000000000000000000000001"
15+
16+
gas_price = 100000000000 # 100 gwei
17+
gas_limit = 100_000
18+
19+
mnemonic = "test test test test test test test test test test test junk"
20+
21+
recipient_distribution_factor = 20 # 1/20 of accounts receive transfers.
22+
max_transfer_amount = 10
23+
24+
[rate_limiting]
25+
initial_ratelimit = 100 # txs/s
26+
27+
# Rate limit thresholds: [(threshold, rate_limit)]
28+
# threshold = number of transactions sent
29+
# rate_limit = new transactions per second limit
30+
ratelimit_thresholds = [
31+
[1_562, 250], # NUM_ACCOUNTS / 16
32+
[3_125, 500], # NUM_ACCOUNTS / 8
33+
[25_000, 1_000], # NUM_ACCOUNTS
34+
[50_000, 2_500], # NUM_ACCOUNTS * 2
35+
[100_000, 5_000], # NUM_ACCOUNTS * 4
36+
[200_000, 7_500], # NUM_ACCOUNTS * 8
37+
[250_000, 12_500], # NUM_ACCOUNTS * 10
38+
[300_000, 15_000], # NUM_ACCOUNTS * 12
39+
]
40+
41+
[worker]
42+
thread_pinning = true
43+
44+
tx_gen_worker_percentage = 0.1
45+
network_worker_percentage = 0.9
46+
47+
[reporting]
48+
tx_queue_report_interval_secs = 3
49+
network_stats_report_interval_secs = 3

crescendo/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ serde_json = "1.0"
2626
hex = "0.4"
2727
simple-tqdm = { version = "0.2.0", features = ["rayon"] }
2828
rand = "0.9.1"
29-
ratelimit = "0.10"
29+
ratelimit = "0.10"
30+
clap = { version = "4.5", features = ["derive", "env"] }
31+
toml = "0.8"

crescendo/src/config.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use std::path::PathBuf;
2+
use std::sync::OnceLock;
3+
4+
use serde::{Deserialize, Serialize};
5+
6+
/// Global configuration instance for the application.
7+
static CONFIG_INSTANCE: OnceLock<Config> = OnceLock::new();
8+
9+
/// Initialize the global configuration instance.
10+
pub fn init(config: Config) {
11+
CONFIG_INSTANCE.set(config).unwrap();
12+
}
13+
14+
/// Gets the global configuration instance's value,
15+
/// blocking until initialized if necessary.
16+
pub fn get() -> &'static Config {
17+
CONFIG_INSTANCE.wait()
18+
}
19+
20+
#[derive(Debug, Clone, Serialize, Deserialize)]
21+
pub struct Config {
22+
pub tx_gen_worker: TxGenWorkerConfig,
23+
pub network_worker: NetworkWorkerConfig,
24+
pub rate_limiting: RateLimitingConfig,
25+
26+
pub workers: WorkersConfig,
27+
pub reporters: ReportersConfig,
28+
}
29+
30+
impl Config {
31+
pub fn from_file(path: &PathBuf) -> Result<Self, Box<dyn std::error::Error>> {
32+
let config_str = std::fs::read_to_string(path)?;
33+
let config: Config = toml::from_str(&config_str)?;
34+
Ok(config)
35+
}
36+
}
37+
38+
#[derive(Debug, Clone, Serialize, Deserialize)]
39+
pub struct NetworkWorkerConfig {
40+
pub target_url: String,
41+
pub total_connections: u64,
42+
43+
pub batch_factor: usize,
44+
45+
pub error_sleep_ms: u64,
46+
pub tx_queue_empty_sleep_ms: u64,
47+
}
48+
49+
#[derive(Debug, Clone, Serialize, Deserialize)]
50+
pub struct TxGenWorkerConfig {
51+
pub chain_id: u64,
52+
53+
pub mnemonic: String,
54+
pub num_accounts: u32,
55+
56+
pub gas_price: u128,
57+
pub gas_limit: u64,
58+
59+
pub token_contract_address: String,
60+
pub recipient_distribution_factor: u32,
61+
pub max_transfer_amount: u64,
62+
}
63+
64+
#[derive(Debug, Clone, Serialize, Deserialize)]
65+
pub struct RateLimitingConfig {
66+
pub initial_ratelimit: u64,
67+
pub ratelimit_thresholds: Vec<(u32, u64)>,
68+
}
69+
70+
#[derive(Debug, Clone, Serialize, Deserialize)]
71+
pub struct WorkersConfig {
72+
pub thread_pinning: bool,
73+
pub tx_gen_worker_percentage: f64,
74+
pub network_worker_percentage: f64,
75+
}
76+
77+
#[derive(Debug, Clone, Serialize, Deserialize)]
78+
pub struct ReportersConfig {
79+
pub tx_queue_report_interval_secs: u64,
80+
pub network_stats_report_interval_secs: u64,
81+
}

0 commit comments

Comments
 (0)