-
Notifications
You must be signed in to change notification settings - Fork 7
feat(test-bins): show config options #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||||||||
use clap::Parser; | ||||||||||||||
use log::*; | ||||||||||||||
use magicblock_api::{ | ||||||||||||||
ledger, | ||||||||||||||
|
@@ -16,6 +17,44 @@ const TEST_KEYPAIR_BYTES: [u8; 64] = [ | |||||||||||||
202, 240, 105, 168, 157, 64, 233, 249, 100, 104, 210, 41, 83, 87, | ||||||||||||||
]; | ||||||||||||||
|
||||||||||||||
/// MagicBlock Validator CLI arguments | ||||||||||||||
#[derive(Parser, Debug)] | ||||||||||||||
#[command(name = "MagicBlock Validator")] | ||||||||||||||
#[command(version = env!("CARGO_PKG_VERSION"))] | ||||||||||||||
#[command(about = "Runs a MagicBlock validator node")] | ||||||||||||||
struct Cli { | ||||||||||||||
/// Path to the configuration file | ||||||||||||||
config: Option<String>, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clap shall support PathBuf. Also I would propose to consider |
||||||||||||||
|
||||||||||||||
/// Base58 encoded validator private key | ||||||||||||||
#[arg( | ||||||||||||||
short = 'k', | ||||||||||||||
long, | ||||||||||||||
value_name = "KEYPAIR", | ||||||||||||||
env = "VALIDATOR_KEYPAIR", | ||||||||||||||
help = "Base58 encoded private key for the validator." | ||||||||||||||
)] | ||||||||||||||
keypair: Option<String>, | ||||||||||||||
|
||||||||||||||
/// Disable geyser components (accounts,transactions) | ||||||||||||||
#[arg( | ||||||||||||||
long, | ||||||||||||||
value_name = "COMPONENTS", | ||||||||||||||
env = "GEYSER_DISABLE", | ||||||||||||||
help = "Specifies geyser components to disable. [default: (accounts,transactions)]" | ||||||||||||||
)] | ||||||||||||||
disable_geyser: Option<String>, | ||||||||||||||
|
||||||||||||||
/// Disable geyser cache components (accounts,transactions) | ||||||||||||||
#[arg( | ||||||||||||||
long, | ||||||||||||||
value_name = "COMPONENTS", | ||||||||||||||
env = "GEYSER_CACHE_DISABLE", | ||||||||||||||
help = "Specifies geyser cache components to disable. [default: (accounts,transactions)]" | ||||||||||||||
)] | ||||||||||||||
disable_geyser_cache: Option<String>, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn init_logger() { | ||||||||||||||
if let Ok(style) = std::env::var("RUST_LOG_STYLE") { | ||||||||||||||
use std::io::Write; | ||||||||||||||
|
@@ -60,8 +99,24 @@ async fn main() { | |||||||||||||
#[cfg(feature = "tokio-console")] | ||||||||||||||
console_subscriber::init(); | ||||||||||||||
|
||||||||||||||
let (file, config) = load_config_from_arg(); | ||||||||||||||
let cli = Cli::parse(); | ||||||||||||||
|
||||||||||||||
// Set environment variables from CLI arguments | ||||||||||||||
if let Some(keypair) = cli.keypair { | ||||||||||||||
std::env::set_var("VALIDATOR_KEYPAIR", keypair); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if let Some(disable_geyser) = cli.disable_geyser { | ||||||||||||||
std::env::set_var("GEYSER_DISABLE", disable_geyser); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if let Some(disable_cache) = cli.disable_geyser_cache { | ||||||||||||||
std::env::set_var("GEYSER_CACHE_DISABLE", disable_cache); | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: setting env vars after parsing them from CLI args could cause issues with override_from_envs() later picking up these modified values unexpectedly |
||||||||||||||
|
||||||||||||||
let (file, config) = load_config(cli.config); | ||||||||||||||
let config = config.override_from_envs(); | ||||||||||||||
|
||||||||||||||
match file { | ||||||||||||||
Some(file) => info!("Loading config from '{}'.", file), | ||||||||||||||
None => info!("Using default config. Override it by passing the path to a config file."), | ||||||||||||||
|
@@ -112,15 +167,16 @@ fn validator_keypair() -> Keypair { | |||||||||||||
if let Ok(keypair) = std::env::var("VALIDATOR_KEYPAIR") { | ||||||||||||||
Keypair::from_base58_string(&keypair) | ||||||||||||||
} else { | ||||||||||||||
Comment on lines
130
to
131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: from_base58_string() can panic - needs error handling for invalid base58 strings
Suggested change
|
||||||||||||||
warn!("Using default test keypair, provide one by setting 'VALIDATOR_KEYPAIR' env var to a base58 encoded private key"); | ||||||||||||||
warn!("Using default test keypair, provide one by setting the --keypair argument or the 'VALIDATOR_KEYPAIR' env var to a base58 encoded private key"); | ||||||||||||||
Keypair::from_bytes(&TEST_KEYPAIR_BYTES) | ||||||||||||||
// SAFETY: these bytes are compiled into the code, thus we know it is valid | ||||||||||||||
.unwrap() | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn load_config_from_arg() -> (Option<String>, EphemeralConfig) { | ||||||||||||||
let config_file = std::env::args().nth(1); | ||||||||||||||
fn load_config( | ||||||||||||||
config_file: Option<String>, | ||||||||||||||
) -> (Option<String>, EphemeralConfig) { | ||||||||||||||
match config_file { | ||||||||||||||
Some(config_file) => { | ||||||||||||||
let config = EphemeralConfig::try_load_from_file(&config_file) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: config parameter needs a long flag (--config) and better help text for discoverability