Skip to content

NRC client#1764

Merged
pietrodimarco-dfinity merged 21 commits intomainfrom
pmarco/nrc-client
Nov 5, 2025
Merged

NRC client#1764
pietrodimarco-dfinity merged 21 commits intomainfrom
pmarco/nrc-client

Conversation

@pietrodimarco-dfinity
Copy link
Contributor

@pietrodimarco-dfinity pietrodimarco-dfinity commented Oct 13, 2025

Note

Introduce a node-rewards CLI that queries and compares NRC vs Governance rewards with CSV export, plus docs, plotting script, and supporting canister client APIs.

  • CLI:
    • Add node-rewards command with modes ongoing and past-rewards <YYYY-MM>.
    • Fetch rewards from NRC and Governance, compare totals, and show daily summaries.
    • CSV export per provider (base_rewards.csv, base_rewards_type3.csv, rewards_summary.csv, node_metrics_by_day.csv, node_metrics_by_node.csv) plus global subnets_failure_rates.csv.
    • Provider filter and tabular console output.
  • Canister clients:
    • Add NodeRewardsCanisterWrapper to query get_node_providers_rewards_calculation.
    • Extend GovernanceCanisterWrapper with list_node_provider_rewards.
  • Docs:
    • New guide docs/node-rewards.md; linked in mkdocs.yml.
  • Tooling:
    • Add scripts/plot_subnet_failure_rates.py to visualize subnet failure rates from exported CSVs.
  • Deps/Config:
    • Add csv, csv_to_table, ic-node-rewards-canister-api, rust_decimal; wire into rs/cli and ic-canisters.
    • Update IC crate revisions; minor .gitignore tweak.

Written by Cursor Bugbot for commit e2626cd. This will update automatically on new commits. Configure here.

@pietrodimarco-dfinity pietrodimarco-dfinity requested a review from a team as a code owner October 13, 2025 16:35
cursor[bot]

This comment was marked as outdated.

Copy link
Collaborator

@sasa-tomic sasa-tomic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great to have, thanks Pietro! It would very useful to have a few pages of docs: what it is, how to use it, etc., if not too much work. I can get this going if you want, just let me know.

@dfinity dfinity deleted a comment from cursor bot Oct 20, 2025
cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 1

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

let nrc_xdr_permyriad: u64 = daily_rewards.iter().map(|(_, reward)| reward.rewards_total_xdr_permyriad.unwrap()).sum();
let principal: PrincipalId = provider_id.to_string().parse().unwrap();

let governance_icp = gov_rewards_map.remove(&principal).unwrap() / 100_000_000;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Governance Reward Missing Provider Causes Panic

Potential panic if provider exists in NRC results but not in governance rewards map. The code calls gov_rewards_map.remove(&principal).unwrap() which will panic if the provider ID is not found in the governance map. This can happen if a provider exists in the Node Rewards Canister but wasn't included in the governance snapshot (e.g., newly added providers, or data synchronization issues). The code should handle the missing case gracefully, either by skipping the provider with a warning or using a default value of 0 for governance rewards.

Fix in Cursor Fix in Web

let end_day = DateTime::from_timestamp(last.timestamp as i64, 0)
.unwrap()
.date_naive()
.pred_opt()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unchecked unwraps cause panics on timestamp parsing failure

Multiple unchecked unwrap() calls on DateTime::from_timestamp() and pred_opt(). If timestamp conversion fails or pred_opt() returns None, the code will panic instead of returning a proper error.

Fix in Cursor Fix in Web

.into_iter()
.map(|r| (r.node_provider.unwrap().id.unwrap(), r.amount_e8s))
.collect();
let xdr_permyriad_per_icp: u64 = last.xdr_conversion_rate.clone().unwrap().xdr_permyriad_per_icp.unwrap();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unchecked unwraps cause governance panic on None fields

Unchecked unwrap() calls on node_provider, id, xdr_conversion_rate, and xdr_permyriad_per_icp. If any of these Optional fields are None in the governance response, the code will panic.

Fix in Cursor Fix in Web

self.create_node_metrics_csv(&provider_dir, daily_rewards)?;
}

// Generate subnets failure rates CSV in the rewards directory
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Uncaught Panics on File System Operations Errors

Multiple unwrap() calls on file system operations (create_dir_all, Writer::from_path, write_record, flush) throughout csv_generator.rs. These operations can fail due to permission issues, disk space, etc., but failures will cause panics instead of returning proper errors.

Fix in Cursor Fix in Web

.and_utc()
.timestamp();
let start_day = DateTime::from_timestamp(last_rewards.timestamp as i64, 0).unwrap().date_naive();
let end_day = DateTime::from_timestamp(end_ts, 0).unwrap().date_naive();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unsafe unwrap on timestamp causes panic

The code calls .unwrap() on DateTime::from_timestamp() which will panic if the timestamp is out of range. This should use proper error handling with ? operator or ok_or_else().

Fix in Cursor Fix in Web

@pietrodimarco-dfinity pietrodimarco-dfinity merged commit fde2ff7 into main Nov 5, 2025
10 checks passed
@pietrodimarco-dfinity pietrodimarco-dfinity deleted the pmarco/nrc-client branch November 5, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants