-
Notifications
You must be signed in to change notification settings - Fork 589
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
Conversation
48ea50a
to
0b8c2be
Compare
Codecov ReportAttention: Patch coverage is
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:
|
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.
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); |
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.
I'm guessing this makes debugging things easier ?
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.
yeah, it makes the diff much clearer
validator/src/commands/run/args.rs
Outdated
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(); |
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.
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
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.
#[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, | ||
} |
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.
I'm debating whether we actually need this type or not. It looks just about identical to:
agave/validator/src/bootstrap.rs
Lines 59 to 67 in 898b76e
#[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
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.
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. 🤔
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.
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.
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.
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
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.
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
0b8c2be
to
23b13ed
Compare
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.
Thanks for pushing this one through; think the subsequent ones will be easier now that we have decided on a "pattern"
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
pretty_assertions