Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions rs/cli/src/commands/node_rewards/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use csv::Writer;
use futures_util::future::join_all;
use ic_base_types::{PrincipalId, SubnetId};
use ic_canisters::node_rewards::NodeRewardsCanisterWrapper;
use ic_node_rewards_canister_api::DateUtc;
use ic_node_rewards_canister_api::provider_rewards_calculation::{DailyNodeFailureRate, DailyNodeProviderRewards, DailyResults};
use ic_node_rewards_canister_api::{DateUtc, RewardsCalculationAlgorithmVersion};
use icp_ledger::AccountIdentifier;
use itertools::Itertools;
use log::info;
Expand All @@ -18,6 +18,7 @@ use tabled::{Table, Tabled};
pub struct NodeRewardsCtx {
pub start_date: NaiveDate,
pub end_date: NaiveDate,
pub algorithm_version: Option<RewardsCalculationAlgorithmVersion>,
pub csv_detailed_output_path: Option<String>,
pub provider_id: Option<String>,
pub compare_with_governance: bool,
Expand Down Expand Up @@ -59,8 +60,11 @@ pub trait NodeRewardsDataFetcher {
println!("Fetching node rewards for all providers from NRC from {} to {}...", start_date, end_date);

let days: Vec<DateUtc> = start_date.iter_days().take_while(|day| day <= &end_date).map(DateUtc::from).collect();
let responses: Vec<anyhow::Result<DailyResults>> =
join_all(days.iter().map(|day| async move { node_rewards_client.get_rewards_daily(*day).await })).await;
let responses: Vec<anyhow::Result<DailyResults>> = join_all(
days.iter()
.map(|day| async move { node_rewards_client.get_rewards_daily(*day, ctx.algorithm_version).await }),
)
.await;

let mut providers_rewards: BTreeMap<PrincipalId, Vec<(DateUtc, DailyNodeProviderRewards)>> = BTreeMap::new();
let mut subnets_failure_rates: BTreeMap<SubnetId, Vec<(DateUtc, f64)>> = BTreeMap::new();
Expand Down
1 change: 1 addition & 0 deletions rs/cli/src/commands/node_rewards/ongoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl ExecutableCommand for Ongoing {
let rewards_ctx = NodeRewardsCtx {
start_date,
end_date,
algorithm_version: None,
csv_detailed_output_path: self.common.csv_detailed_output_path.clone(),
provider_id: self.common.provider_id.clone(),
governance_providers_rewards,
Expand Down
3 changes: 3 additions & 0 deletions rs/cli/src/commands/node_rewards/past_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::{DateTime, Datelike};
use clap::Args;
use ic_canisters::governance::GovernanceCanisterWrapper;
use ic_canisters::node_rewards::NodeRewardsCanisterWrapper;
use ic_node_rewards_canister_api::RewardsCalculationAlgorithmVersion;
use log::info;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -75,10 +76,12 @@ impl ExecutableCommand for PastRewards {
.ok_or_else(|| anyhow::anyhow!("Cannot get previous day"))?;

let node_providers = governance_client.get_node_providers().await?;
let algorithm_version = last.algorithm_version.map(|v| RewardsCalculationAlgorithmVersion { version: v });

let rewards_ctx = NodeRewardsCtx {
start_date,
end_date,
algorithm_version,
csv_detailed_output_path: self.common.csv_detailed_output_path.clone(),
provider_id: self.common.provider_id.clone(),
governance_providers_rewards,
Expand Down
17 changes: 9 additions & 8 deletions rs/ic-canisters/src/node_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::str::FromStr;

use crate::IcAgentCanisterClient;
use candid::Principal;
use ic_node_rewards_canister_api::provider_rewards_calculation::{
DailyResults, DateUtc, GetNodeProvidersRewardsCalculationRequest, GetNodeProvidersRewardsCalculationResponse,
use ic_node_rewards_canister_api::{
RewardsCalculationAlgorithmVersion,
provider_rewards_calculation::{DailyResults, DateUtc, GetNodeProvidersRewardsCalculationRequest, GetNodeProvidersRewardsCalculationResponse},
};

const NODE_REWARDS_CANISTER: &str = "sgymv-uiaaa-aaaaa-aaaia-cai";
Expand All @@ -23,16 +24,16 @@ impl NodeRewardsCanisterWrapper {
Self { agent }
}

pub async fn get_rewards_daily(&self, day: DateUtc) -> anyhow::Result<DailyResults> {
pub async fn get_rewards_daily(
&self,
day: DateUtc,
algorithm_version: Option<RewardsCalculationAlgorithmVersion>,
) -> anyhow::Result<DailyResults> {
self.agent
.query::<GetNodeProvidersRewardsCalculationResponse>(
&Principal::from_str(NODE_REWARDS_CANISTER).map_err(anyhow::Error::from)?,
"get_node_providers_rewards_calculation",
candid::encode_one(GetNodeProvidersRewardsCalculationRequest {
day,
// Use the default version
algorithm_version: None,
})?,
candid::encode_one(GetNodeProvidersRewardsCalculationRequest { day, algorithm_version })?,
)
.await?
.map_err(|e| anyhow::anyhow!(e))
Expand Down
Loading