From f9bb68a63e028e6f9346079311fd6c1565602e51 Mon Sep 17 00:00:00 2001 From: Pietro Date: Fri, 15 Nov 2024 19:51:19 +0100 Subject: [PATCH 1/3] Fix log level filtering rewarding lib --- Cargo.lock | 6 +++--- .../node-provider-rewards-lib/src/v1_logs.rs | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d983caa4..3b24f8d36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3135,7 +3135,7 @@ checksum = "dd8ecacd682fa05a985253592963306cb9799622d7b1cce4b1edb89c6ec85be1" dependencies = [ "candid", "ic-cdk-macros 0.16.0", - "ic0 0.23.0", + "ic0 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde_bytes", ] @@ -3147,7 +3147,7 @@ source = "git+https://github.com/dfinity/cdk-rs.git?rev=8f57d6d26b1d142b5be4b39e dependencies = [ "candid", "ic-cdk-macros 0.17.0", - "ic0 0.23.0", + "ic0 0.23.0 (git+https://github.com/dfinity/cdk-rs.git?rev=8f57d6d26b1d142b5be4b39ea8ade59d7c848cde)", "serde", "serde_bytes", ] @@ -3228,7 +3228,7 @@ source = "git+https://github.com/dfinity/cdk-rs.git?rev=8f57d6d26b1d142b5be4b39e dependencies = [ "futures", "ic-cdk 0.17.0", - "ic0 0.23.0", + "ic0 0.23.0 (git+https://github.com/dfinity/cdk-rs.git?rev=8f57d6d26b1d142b5be4b39ea8ade59d7c848cde)", "serde", "serde_bytes", "slotmap", diff --git a/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs b/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs index 1632a2592..aab11c59c 100644 --- a/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs +++ b/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs @@ -177,6 +177,7 @@ impl fmt::Display for LogEntry { } } +#[derive(Copy, Clone)] pub enum LogLevel { Info, Debug, @@ -212,15 +213,13 @@ impl RewardsLog { result } - pub fn get_log(&self) -> Vec { - let mut log = Vec::new(); - - for (level, entry) in self.entries.iter() { - match level { - LogLevel::Info => log.push(format!("{}: {} ", level, entry)), - _ => continue, - } - } - log + pub fn get_log(&self, level: LogLevel) -> Vec { + self.entries + .iter() + .filter_map(move |(entry_log_level, entry)| + match (level, entry_log_level) { + (LogLevel::Info, LogLevel::Debug) => None, + _ => Some(format!("{}: {} ", level, entry)), + }).collect_vec() } } From fbb86dd6683b14c578aef8dad5253db7a9342cde Mon Sep 17 00:00:00 2001 From: Pietro Date: Fri, 15 Nov 2024 19:54:09 +0100 Subject: [PATCH 2/3] Run rustfmt --- .../node-provider-rewards-lib/src/v1_logs.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs b/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs index aab11c59c..1a526baa5 100644 --- a/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs +++ b/rs/dre-canisters/node-provider-rewards-lib/src/v1_logs.rs @@ -216,10 +216,10 @@ impl RewardsLog { pub fn get_log(&self, level: LogLevel) -> Vec { self.entries .iter() - .filter_map(move |(entry_log_level, entry)| - match (level, entry_log_level) { - (LogLevel::Info, LogLevel::Debug) => None, - _ => Some(format!("{}: {} ", level, entry)), - }).collect_vec() + .filter_map(move |(entry_log_level, entry)| match (level, entry_log_level) { + (LogLevel::Info, LogLevel::Debug) => None, + _ => Some(format!("{}: {} ", level, entry)), + }) + .collect_vec() } } From 3fcdaa1eb7080f027592a043c8a17df144d59a62 Mon Sep 17 00:00:00 2001 From: Pietro Date: Sat, 16 Nov 2024 01:05:24 +0100 Subject: [PATCH 3/3] Run rustfmt --- .../src/trustworthy-node-metrics/src/rewards_manager.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics/src/rewards_manager.rs b/rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics/src/rewards_manager.rs index 083f2ebdd..7dafafd80 100644 --- a/rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics/src/rewards_manager.rs +++ b/rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics/src/rewards_manager.rs @@ -5,6 +5,7 @@ use ic_nns_governance_api::pb::v1::MonthlyNodeProviderRewards; use ic_protobuf::registry::node_rewards::{v2::NodeRewardRate, v2::NodeRewardsTable}; use ic_registry_keys::NODE_REWARDS_TABLE_KEY; use itertools::Itertools; +use node_provider_rewards_lib::v1_logs::LogLevel; use node_provider_rewards_lib::{ v1_rewards::{assigned_nodes_multiplier, calculate_rewards}, v1_types::{AHashMap, DailyNodeMetrics as NPRDailyNodeMetrics}, @@ -135,7 +136,7 @@ pub fn node_provider_rewards(node_provider_id: Principal, rewarding_period: Date node_provider_id, rewards_xdr_permyriad: rewards_ammount.xdr_permyriad, rewards_xdr_permyriad_no_reduction: rewards_ammount.xdr_permyriad_no_reduction, - computation_log: rewards.rewards_log_per_node_provider.get(&np_id).unwrap().get_log(), + computation_log: rewards.rewards_log_per_node_provider.get(&np_id).unwrap().get_log(LogLevel::Info), rewards_xdr_old, ts_distribution: latest_np_rewards.timestamp, xdr_conversion_rate: latest_np_rewards.xdr_conversion_rate.and_then(|rate| rate.xdr_permyriad_per_icp),