Skip to content

Commit

Permalink
Merge branch 'msum/rewards-api-context' into 'master'
Browse files Browse the repository at this point in the history
feat(registry): Add registry_version to NodeProvidersMonthlyXdrRewards

This commit adds the registry_version used to calculate NodeProvidersMonthlyXdrRewards, to make it easier to audit node provider rewards. 

See merge request dfinity-lab/public/ic!20082
  • Loading branch information
max-dfinity committed Jun 28, 2024
2 parents 497c653 + cb7825a commit 41eef14
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion rs/nns/governance/tests/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ impl Environment for FakeDriver {
NodeProvidersMonthlyXdrRewards {
rewards: hashmap! {
PrincipalId::new_user_test_id(1).to_string() => NODE_PROVIDER_REWARD,
}
},
registry_version: Some(5)
}
))
.unwrap());
Expand Down
1 change: 1 addition & 0 deletions rs/registry/canister/canister/registry.did
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ type NodeOperatorRecord = record {

type NodeProvidersMonthlyXdrRewards = record {
rewards : vec record { text; nat64 };
registry_version: opt nat64;
};

type NodeRewardRate = record {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ message RegistryCanisterStableStorage {
// rewarded for providing nodes to the Internet Computer for the month.
message NodeProvidersMonthlyXdrRewards {
map<string, uint64> rewards = 1;
// Registry version at which rewards were calculated
optional uint64 registry_version = 2;
}

// Maps the supplied PrincipalId (of a canister) to the subnet to which the canister is assigned to.
Expand Down
3 changes: 3 additions & 0 deletions rs/registry/canister/src/gen/ic_registry_canister.pb.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub struct RegistryCanisterStableStorage {
pub struct NodeProvidersMonthlyXdrRewards {
#[prost(map = "string, uint64", tag = "1")]
pub rewards: ::std::collections::HashMap<::prost::alloc::string::String, u64>,
/// Registry version at which rewards were calculated
#[prost(uint64, optional, tag = "2")]
pub registry_version: ::core::option::Option<u64>,
}
/// Maps the supplied PrincipalId (of a canister) to the subnet to which the canister is assigned to.
/// There is no guarantee that the canister exists, even if a subnet ID is returned.
Expand Down
31 changes: 22 additions & 9 deletions rs/registry/canister/src/get_node_providers_monthly_xdr_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use crate::{pb::v1::NodeProvidersMonthlyXdrRewards, registry::Registry};
#[cfg(target_arch = "wasm32")]
use dfn_core::println;
use ic_nns_common::registry::decode_or_panic;
use ic_protobuf::registry::dc::v1::DataCenterRecord;
use ic_protobuf::registry::node_operator::v1::NodeOperatorRecord;
use ic_protobuf::registry::node_rewards::v2::{NodeRewardRate, NodeRewardsTable};
use ic_protobuf::registry::{
dc::v1::DataCenterRecord,
node_operator::v1::NodeOperatorRecord,
node_rewards::v2::{NodeRewardRate, NodeRewardsTable},
};
use ic_registry_keys::{
make_data_center_record_key, NODE_OPERATOR_RECORD_KEY_PREFIX, NODE_REWARDS_TABLE_KEY,
};
use ic_types::PrincipalId;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::str::from_utf8;
use std::{collections::HashMap, convert::TryFrom, str::from_utf8};

impl Registry {
/// Return a map from Node Provider IDs to the amount (in 10,000ths of an
Expand Down Expand Up @@ -186,6 +186,8 @@ impl Registry {
}
}

rewards.registry_version = Some(self.latest_version());

Ok(rewards)
}
}
Expand All @@ -198,9 +200,11 @@ mod tests {
TEST_USER1_PRINCIPAL, TEST_USER2_PRINCIPAL, TEST_USER3_PRINCIPAL, TEST_USER4_PRINCIPAL,
};
use ic_nns_test_utils::registry::invariant_compliant_mutation;
use ic_protobuf::registry::dc::v1::AddOrRemoveDataCentersProposalPayload;
use ic_protobuf::registry::node_rewards::v2::{
NodeRewardRate, NodeRewardRates, UpdateNodeRewardsTableProposalPayload,
use ic_protobuf::registry::{
dc::v1::AddOrRemoveDataCentersProposalPayload,
node_rewards::v2::{
NodeRewardRate, NodeRewardRates, UpdateNodeRewardsTableProposalPayload,
},
};
use ic_registry_keys::make_node_operator_record_key;
use ic_registry_transport::pb::v1::{registry_mutation, RegistryMutation};
Expand Down Expand Up @@ -394,6 +398,10 @@ mod tests {
let np1 = TEST_USER1_PRINCIPAL.to_string();
let np1_rewards = monthly_rewards.rewards.get(&np1).unwrap();
assert_eq!(*np1_rewards, 5); // 5 nodes at 1 XDR/month/node
assert_eq!(
monthly_rewards.registry_version,
Some(registry.latest_version())
);

///////////////////////////////
// Now add the reward table for type0 and type2 nodes and check that the values are properly used
Expand Down Expand Up @@ -503,6 +511,11 @@ mod tests {

let monthly_rewards = registry.get_node_providers_monthly_xdr_rewards().unwrap();

assert_eq!(
monthly_rewards.registry_version,
Some(registry.latest_version())
);

// NP1: the existence of type3 nodes should not impact the type0/type2 rewards
assert_eq!(
*monthly_rewards.rewards.get(&np1.to_string()).unwrap(),
Expand Down

0 comments on commit 41eef14

Please sign in to comment.