Skip to content

agave-validator: add args tests for run (part 2) #6667

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

Merged
merged 15 commits into from
Jul 10, 2025

Conversation

yihau
Copy link
Member

@yihau yihau commented Jun 20, 2025

Problem

#4082

Summary of Changes

--no-genesis-fetch

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

--no-snapshot-fetch

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

--entrypoint

split the method chain and use IndexSet in the middle steps for ensuring the input order

--check-vote-account

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

--known-validator

port validators_set without an exit func

--only-known-rpc

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

--max-genesis-archive-unpacked-size

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

--no-incremental-snapshots

extract to ./validator/src/commands/run/args/rpc_bootstrap_config.rs

misc

  • introduce pretty_assertions

@yihau yihau force-pushed the add-args-run-part-2-new branch 2 times, most recently from 48ea50a to 0b8c2be Compare June 20, 2025 13:56
@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2025

Codecov Report

Attention: Patch coverage is 97.58242% with 11 lines in your changes missing coverage. Please review.

Project coverage is 83.3%. Comparing base (9595527) to head (8716726).
Report is 36 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #6667    +/-   ##
========================================
  Coverage    83.3%    83.3%            
========================================
  Files         853      854     +1     
  Lines      378266   378684   +418     
========================================
+ Hits       315409   315813   +404     
- Misses      62857    62871    +14     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yihau yihau marked this pull request as ready for review June 20, 2025 15:14
@yihau yihau requested a review from steviez June 20, 2025 15:14
Copy link

@steviez steviez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally got to an actual full review on this

@@ -46,7 +46,7 @@ pub mod tests {
{
let matches = app.get_matches_from(vec);
let result = T::from_clap_arg_match(&matches);
assert_eq!(result.unwrap(), expected_arg);
pretty_assertions::assert_eq!(result.unwrap(), expected_arg);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this makes debugging things easier ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it makes the diff much clearer

Comment on lines 62 to 72
let entrypoints = values_t!(matches, "entrypoint", String).unwrap_or_default();
let mut parsed_entrypoints = IndexSet::new();
for entrypoint in entrypoints {
let parsed = solana_net_utils::parse_host_port(&entrypoint).map_err(|err| {
Box::<dyn std::error::Error>::from(format!(
"failed to parse entrypoint address: {err}"
))
})?;
parsed_entrypoints.insert(parsed);
}
let entrypoints = parsed_entrypoints.into_iter().collect();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testability, we just need consistent ordering. How about this ?

let mut entrypoints = values_t!(matches, "entrypoint", String).unwrap_or_default();
// sort() + dedup() to yield a vector of unique elements
entrypoints.sort();
entrypoints.dedup();
let entrypoints = entrypoints.into_iter().map(|entrypoint| solana_net_utils::parse_host_port(...).map_err(...)).collect();

Technically may be less efficient, but this is a one-time-cost at startup and avoid bringing in another dependency

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 6 to 14
#[derive(Debug, PartialEq, Clone)]
pub struct RpcBootstrapConfig {
pub no_genesis_fetch: bool,
pub no_snapshot_fetch: bool,
pub check_vote_account: Option<String>,
pub only_known_rpc: bool,
pub max_genesis_archive_unpacked_size: u64,
pub no_incremental_snapshots: bool,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm debating whether we actually need this type or not. It looks just about identical to:

#[derive(Debug)]
pub struct RpcBootstrapConfig {
pub no_genesis_fetch: bool,
pub no_snapshot_fetch: bool,
pub only_known_rpc: bool,
pub max_genesis_archive_unpacked_size: u64,
pub check_vote_account: Option<String>,
pub incremental_snapshot_fetch: bool,
}

The only difference is the final field, no_incremental_snapshots vs. incremental_snapshot_fetch. IMO, the struct should yield incremental_snapshot_fetch and do the below "conversion" in FromClapArgMatches impl:

incremental_snapshot_fetch: !run_args.rpc_bootstrap_config.no_incremental_snapshots,

If we make that change, we can seemingly just implement FromClapArgMatches on the existing struct directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my idea is that all RunArgs related structs should be used strictly for input purposes. this ensures that changes to input won’t affect the core logic, and vice versa. if we use a shared argument struct for both input and core functionality, we’ll eventually run into issues where changes are only intended for one side. 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my idea is that all RunArgs related structs should be used strictly for input purposes. this ensures that changes to input won’t affect the core logic, and vice versa

I'm struggling to think of a scenario where we'd want or need this separation. Do you see any situations in our codebase today that would necessitate the separation ?

if we use a shared argument struct for both input and core functionality, we’ll eventually run into issues where changes are only intended for one side

I think of the pre existing struct that I linked is the "input" struct. More so, I think that this config struct should be very simple and have the sole purpose of passing config down to the relevant service. And I have this belief for all the similar structs such as BlockstoreOptions, SnapshotConfig, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. I moved RpcBootstrapConfig into args.rs and removed the existing one. 754e36d just want to emphasize that this is intended as an input argument specifically for the run command

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. I moved RpcBootstrapConfig into args.rs and removed the existing one

Did it have to move ? I thought we could implement the trait on it while keeping it in the original location. I don't see us moving BlockstoreOptions or AccountsDbConfig to be defined in agave-validator crate

just want to emphasize that this is intended as an input argument specifically for the run command

Let's hop on a call to get on the same page here, that will probably be quicker than more GH comments back and forth

@yihau yihau force-pushed the add-args-run-part-2-new branch from 0b8c2be to 23b13ed Compare July 3, 2025 13:24
Copy link

@steviez steviez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this one through; think the subsequent ones will be easier now that we have decided on a "pattern"

@yihau yihau merged commit 2546ea6 into anza-xyz:master Jul 10, 2025
52 checks passed
@yihau yihau deleted the add-args-run-part-2-new branch July 10, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants