Skip to content

Commit

Permalink
sort stashes by identity
Browse files Browse the repository at this point in the history
  • Loading branch information
paulormart committed Apr 26, 2024
1 parent 8431d93 commit 7d1605c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add tip for block author optional with `--tx-tip`
- Add transaction mortal optional with `--tx-mortal-period`
- Add github personal access token with `--github-pat` to grant access to a list of stashes defined in a private github repo
- Sort stashes by identity, no-identity and push warnings to bottom

## Changed
- Review no bonded controller message
Expand Down
32 changes: 31 additions & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct Validator {
pub stash: AccountId32,
pub controller: Option<AccountId32>,
pub name: String,
pub has_identity: bool,
pub is_active: bool,
pub is_previous_era_already_claimed: bool,
pub claimed: Vec<(EraIndex, PageIndex)>,
Expand All @@ -72,6 +73,7 @@ impl Validator {
stash,
controller: None,
name: "".to_string(),
has_identity: false,
is_active: false,
is_previous_era_already_claimed: false,
claimed: Vec::new(),
Expand Down Expand Up @@ -269,8 +271,36 @@ impl From<RawData> for Report {
warn!("{}", warning);
}

// Sort validators by identity, than by non-identity and push the stashes
// with warnings to bottom
let mut validators_with_warnings = data
.validators
.clone()
.into_iter()
.filter(|v| v.warnings.len() > 0)
.collect::<Vec<Validator>>();

validators_with_warnings.sort_by(|a, b| a.name.partial_cmp(&b.name).unwrap());

let validators_with_no_identity = data
.validators
.clone()
.into_iter()
.filter(|v| v.warnings.len() == 0 && !v.has_identity)
.collect::<Vec<Validator>>();

let mut validators = data
.validators
.into_iter()
.filter(|v| v.warnings.len() == 0 && v.has_identity)
.collect::<Vec<Validator>>();

validators.sort_by(|a, b| a.name.partial_cmp(&b.name).unwrap());
validators.extend(validators_with_no_identity);
validators.extend(validators_with_warnings);

// Validators info
for validator in data.validators {
for validator in validators {
report.add_break();
let is_active_desc = if validator.is_active { "🟢" } else { "🔴" };
report.add_raw_text(format!(
Expand Down
13 changes: 7 additions & 6 deletions src/runtimes/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub async fn try_crunch(crunch: &Crunch) -> Result<(), CrunchError> {
let seed_account_id: AccountId32 = signer_keypair.public_key().into();

// Get signer account identity
let signer_name = get_display_name(&crunch, &seed_account_id, None).await?;
let (signer_name, _) = get_display_name(&crunch, &seed_account_id, None).await?;
let mut signer_details = SignerDetails {
account: seed_account_id.clone(),
name: signer_name,
Expand Down Expand Up @@ -675,7 +675,8 @@ async fn collect_validators_data(
Some(controller) => controller,
None => {
let mut v = Validator::new(stash.clone());
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) =
get_display_name(&crunch, &stash, None).await?;
v.warnings = vec![format!("No controller bonded!")];
validators.push(v);
continue;
Expand All @@ -689,7 +690,7 @@ async fn collect_validators_data(
v.controller = Some(controller.clone());

// Get validator name
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) = get_display_name(&crunch, &stash, None).await?;

// Check if validator is in active set
v.is_active = if let Some(ref av) = active_validators {
Expand Down Expand Up @@ -862,7 +863,7 @@ async fn get_display_name(
crunch: &Crunch,
stash: &AccountId32,
sub_account_name: Option<String>,
) -> Result<String, CrunchError> {
) -> Result<(String, bool), CrunchError> {
let api = crunch.client().clone();

let identity_of_addr = node_runtime::storage().identity().identity_of(stash);
Expand All @@ -880,7 +881,7 @@ async fn get_display_name(
Some(child) => format!("{}/{}", parent, child),
None => parent,
};
Ok(name)
Ok((name, true))
}
None => {
let super_of_addr = node_runtime::storage().identity().super_of(stash);
Expand All @@ -900,7 +901,7 @@ async fn get_display_name(
.await;
} else {
let s = &stash.to_string();
Ok(format!("{}...{}", &s[..6], &s[s.len() - 6..]))
Ok((format!("{}...{}", &s[..6], &s[s.len() - 6..]), false))
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/runtimes/paseo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub async fn try_crunch(crunch: &Crunch) -> Result<(), CrunchError> {
let seed_account_id: AccountId32 = signer_keypair.public_key().into();

// Get signer account identity
let signer_name = get_display_name(&crunch, &seed_account_id, None).await?;
let (signer_name, _) = get_display_name(&crunch, &seed_account_id, None).await?;
let mut signer_details = SignerDetails {
account: seed_account_id.clone(),
name: signer_name,
Expand Down Expand Up @@ -675,7 +675,7 @@ async fn collect_validators_data(
Some(controller) => controller,
None => {
let mut v = Validator::new(stash.clone());
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) = get_display_name(&crunch, &stash, None).await?;
v.warnings = vec![format!("No controller bonded!")];
validators.push(v);
continue;
Expand All @@ -689,7 +689,7 @@ async fn collect_validators_data(
v.controller = Some(controller.clone());

// Get validator name
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) = get_display_name(&crunch, &stash, None).await?;

// Check if validator is in active set
v.is_active = if let Some(ref av) = active_validators {
Expand Down Expand Up @@ -822,7 +822,7 @@ async fn get_display_name(
crunch: &Crunch,
stash: &AccountId32,
sub_account_name: Option<String>,
) -> Result<String, CrunchError> {
) -> Result<(String, bool), CrunchError> {
let api = crunch.client().clone();

let identity_of_addr = node_runtime::storage().identity().identity_of(stash);
Expand All @@ -840,7 +840,7 @@ async fn get_display_name(
Some(child) => format!("{}/{}", parent, child),
None => parent,
};
Ok(name)
Ok((name, true))
}
None => {
let super_of_addr = node_runtime::storage().identity().super_of(stash);
Expand All @@ -860,7 +860,7 @@ async fn get_display_name(
.await;
} else {
let s = &stash.to_string();
Ok(format!("{}...{}", &s[..6], &s[s.len() - 6..]))
Ok((format!("{}...{}", &s[..6], &s[s.len() - 6..]), false))
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/runtimes/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub async fn try_crunch(crunch: &Crunch) -> Result<(), CrunchError> {
let seed_account_id: AccountId32 = signer_keypair.public_key().into();

// Get signer account identity
let signer_name = get_display_name(&crunch, &seed_account_id, None).await?;
let (signer_name, _) = get_display_name(&crunch, &seed_account_id, None).await?;
let mut signer_details = SignerDetails {
account: seed_account_id.clone(),
name: signer_name,
Expand Down Expand Up @@ -675,7 +675,8 @@ async fn collect_validators_data(
Some(controller) => controller,
None => {
let mut v = Validator::new(stash.clone());
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) =
get_display_name(&crunch, &stash, None).await?;
v.warnings = vec![format!("No controller bonded!")];
validators.push(v);
continue;
Expand All @@ -689,7 +690,7 @@ async fn collect_validators_data(
v.controller = Some(controller.clone());

// Get validator name
v.name = get_display_name(&crunch, &stash, None).await?;
(v.name, v.has_identity) = get_display_name(&crunch, &stash, None).await?;

// Check if validator is in active set
v.is_active = if let Some(ref av) = active_validators {
Expand Down Expand Up @@ -862,7 +863,7 @@ async fn get_display_name(
crunch: &Crunch,
stash: &AccountId32,
sub_account_name: Option<String>,
) -> Result<String, CrunchError> {
) -> Result<(String, bool), CrunchError> {
let api = crunch.client().clone();

let identity_of_addr = node_runtime::storage().identity().identity_of(stash);
Expand All @@ -880,7 +881,7 @@ async fn get_display_name(
Some(child) => format!("{}/{}", parent, child),
None => parent,
};
Ok(name)
Ok((name, true))
}
None => {
let super_of_addr = node_runtime::storage().identity().super_of(stash);
Expand All @@ -900,7 +901,7 @@ async fn get_display_name(
.await;
} else {
let s = &stash.to_string();
Ok(format!("{}...{}", &s[..6], &s[s.len() - 6..]))
Ok((format!("{}...{}", &s[..6], &s[s.len() - 6..]), false))
}
}
}
Expand Down

0 comments on commit 7d1605c

Please sign in to comment.