Skip to content

Commit

Permalink
Graceful handling of missing validator data in pcli (#4536)
Browse files Browse the repository at this point in the history
## Issue ticket number and link

#4533 

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > only changes client code
  • Loading branch information
hdevalence authored and conorsch committed Jun 4, 2024
1 parent 2633ea3 commit 465b24c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
21 changes: 16 additions & 5 deletions crates/bin/pcli/src/command/view/staked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ impl StakedCmd {
continue;
};

let info = validators
.iter()
.find(|v| v.validator.identity_key == dt.validator())
.expect("validator info exists in returned data");

let delegation = Value {
amount: notes_by_address
.values()
Expand All @@ -78,6 +73,22 @@ impl StakedCmd {
asset_id: dt.id(),
};

let info = match validators
.iter()
.find(|v| v.validator.identity_key == dt.validator())
{
Some(info) => info,
None => {
table.add_row(vec![
"missing data".to_string(),
"missing data".to_string(),
"missing data".to_string(),
delegation.format(&asset_cache),
]);
continue;
}
};

let unbonded = Value {
amount: info
.rate_data
Expand Down
7 changes: 4 additions & 3 deletions crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,10 @@ impl<R: RngCore + CryptoRng> Planner<R> {

// 1. Create a DelegatorVotePlan for each votable note.
for (record, ik) in &voting_notes {
let validator_start_rate_data = start_rate_data
.get(&ik)
.ok_or_else(|| anyhow!("missing rate data for votable note delegated to {}", ik))?;
let Some(validator_start_rate_data) = start_rate_data.get(&ik) else {
tracing::debug!("missing rate data for votable note delegated to {}", ik);
continue;
};

let voting_power_at_vote_start =
validator_start_rate_data.unbonded_amount(record.note.amount());
Expand Down

0 comments on commit 465b24c

Please sign in to comment.