Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 3bf00e4

Browse files
cli: sort option for validators by version (#24237)
(cherry picked from commit 91993d8) # Conflicts: # Cargo.lock # cli-output/Cargo.toml # programs/bpf/Cargo.lock Co-authored-by: Trent Nelson <trent@solana.com>
1 parent c289cd2 commit 3bf00e4

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

Cargo.lock

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

cli-output/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ clap = "2.33.0"
1717
console = "0.15.0"
1818
humantime = "2.0.1"
1919
indicatif = "0.16.2"
20+
semver = "1.0.6"
2021
serde = "1.0.136"
2122
serde_json = "1.0.79"
2223
solana-account-decoder = { path = "../account-decoder", version = "=1.10.9" }

cli-output/src/cli_output.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub enum CliValidatorsSortOrder {
356356
SkipRate,
357357
Stake,
358358
VoteAccount,
359+
Version,
359360
}
360361

361362
#[derive(Serialize, Deserialize)]
@@ -494,6 +495,22 @@ impl fmt::Display for CliValidators {
494495
CliValidatorsSortOrder::Stake => {
495496
sorted_validators.sort_by_key(|a| a.activated_stake);
496497
}
498+
CliValidatorsSortOrder::Version => {
499+
sorted_validators.sort_by(|a, b| {
500+
use std::cmp::Ordering;
501+
let a_version = semver::Version::parse(a.version.as_str()).ok();
502+
let b_version = semver::Version::parse(b.version.as_str()).ok();
503+
match (a_version, b_version) {
504+
(None, None) => a.version.cmp(&b.version),
505+
(None, Some(_)) => Ordering::Less,
506+
(Some(_), None) => Ordering::Greater,
507+
(Some(va), Some(vb)) => match va.cmp(&vb) {
508+
Ordering::Equal => a.activated_stake.cmp(&b.activated_stake),
509+
ordering => ordering,
510+
},
511+
}
512+
});
513+
}
497514
}
498515

499516
if self.validators_reverse_sort {

cli/src/cluster_query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ impl ClusterQuerySubCommands for App<'_, '_> {
379379
"root",
380380
"skip-rate",
381381
"stake",
382+
"version",
382383
"vote-account",
383384
])
384385
.default_value("stake")
@@ -650,6 +651,7 @@ pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo,
650651
"skip-rate" => CliValidatorsSortOrder::SkipRate,
651652
"stake" => CliValidatorsSortOrder::Stake,
652653
"vote-account" => CliValidatorsSortOrder::VoteAccount,
654+
"version" => CliValidatorsSortOrder::Version,
653655
_ => unreachable!(),
654656
};
655657

programs/bpf/Cargo.lock

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

0 commit comments

Comments
 (0)