From 465b24c0bf69cf37f4761726b4181567912a049f Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 4 Jun 2024 05:37:02 -0700 Subject: [PATCH] Graceful handling of missing validator data in pcli (#4536) ## 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 --- crates/bin/pcli/src/command/view/staked.rs | 21 ++++++++++++++++----- crates/view/src/planner.rs | 7 ++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/bin/pcli/src/command/view/staked.rs b/crates/bin/pcli/src/command/view/staked.rs index 3eab00734d..f3c635094b 100644 --- a/crates/bin/pcli/src/command/view/staked.rs +++ b/crates/bin/pcli/src/command/view/staked.rs @@ -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() @@ -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 diff --git a/crates/view/src/planner.rs b/crates/view/src/planner.rs index 1c19f2d81e..336f37f17c 100644 --- a/crates/view/src/planner.rs +++ b/crates/view/src/planner.rs @@ -435,9 +435,10 @@ impl Planner { // 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());