From fdbe31d41ac647d405ce52cdc6d21c7c7cc9a198 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Wed, 22 Jan 2025 19:42:44 +0800 Subject: [PATCH 1/2] fix(cli): handle non-existing actors gracefully in F3 power proportion CLI --- src/cli/subcommands/f3_cmd.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cli/subcommands/f3_cmd.rs b/src/cli/subcommands/f3_cmd.rs index 8021e39695c..ff81700adc2 100644 --- a/src/cli/subcommands/f3_cmd.rs +++ b/src/cli/subcommands/f3_cmd.rs @@ -11,12 +11,12 @@ use crate::{ f3::{F3Instant, F3Manifest, F3PowerEntry, FinalityCertificate}, prelude::*, }, + shim::fvm_shared_latest::ActorID, }; use ahash::HashSet; use anyhow::Context as _; use cid::Cid; use clap::{Subcommand, ValueEnum}; -use itertools::Itertools as _; use sailfish::TemplateSimple; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; @@ -263,21 +263,18 @@ impl F3PowerTableCommands { .fold(num::BigInt::ZERO, |acc, entry| acc + &entry.power); let mut scaled_total = 0; let mut scaled_sum = 0; - let mut actor_id_set = HashSet::from_iter(actor_ids); + let actor_id_set = HashSet::from_iter(actor_ids); + let mut not_found = vec![]; for entry in power_table.iter() { let scaled_power = scale_power(&entry.power, &total)?; scaled_total += scaled_power; - if actor_id_set.remove(&entry.id) { + if actor_id_set.contains(&entry.id) { scaled_sum += scaled_power; + } else { + not_found.push(entry.id); } } - anyhow::ensure!( - actor_id_set.is_empty(), - "actor ID {} not found in power table", - actor_id_set.into_iter().map(|i| i.to_string()).join(",") - ); - let result = F3PowerTableGetProportionCommandResult { instance, from_ec: ec, @@ -287,6 +284,7 @@ impl F3PowerTableCommands { }, scaled_sum, proportion: (scaled_sum as f64) / (scaled_total as f64), + not_found, }; println!("{}", serde_json::to_string_pretty(&result)?); } @@ -374,6 +372,7 @@ pub struct F3PowerTableGetProportionCommandResult { power_table: F3PowerTableCliMinimalJson, scaled_sum: i64, proportion: f64, + not_found: Vec, } #[serde_as] From 31eff36317104c1c82382dd65251840d9a0179dc Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Wed, 22 Jan 2025 19:53:12 +0800 Subject: [PATCH 2/2] fix --- src/cli/subcommands/f3_cmd.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cli/subcommands/f3_cmd.rs b/src/cli/subcommands/f3_cmd.rs index ff81700adc2..36c6c349daf 100644 --- a/src/cli/subcommands/f3_cmd.rs +++ b/src/cli/subcommands/f3_cmd.rs @@ -263,15 +263,12 @@ impl F3PowerTableCommands { .fold(num::BigInt::ZERO, |acc, entry| acc + &entry.power); let mut scaled_total = 0; let mut scaled_sum = 0; - let actor_id_set = HashSet::from_iter(actor_ids); - let mut not_found = vec![]; + let mut actor_id_set = HashSet::from_iter(actor_ids); for entry in power_table.iter() { let scaled_power = scale_power(&entry.power, &total)?; scaled_total += scaled_power; - if actor_id_set.contains(&entry.id) { + if actor_id_set.remove(&entry.id) { scaled_sum += scaled_power; - } else { - not_found.push(entry.id); } } @@ -284,7 +281,7 @@ impl F3PowerTableCommands { }, scaled_sum, proportion: (scaled_sum as f64) / (scaled_total as f64), - not_found, + not_found: actor_id_set.into_iter().collect(), }; println!("{}", serde_json::to_string_pretty(&result)?); }