From cb7825ab6582820a8616f5bdbc7fd17192d0b9a6 Mon Sep 17 00:00:00 2001 From: Maximilian Summe Date: Fri, 28 Jun 2024 18:55:41 +0000 Subject: [PATCH] feat(registry): Add registry_version to NodeProvidersMonthlyXdrRewards --- rs/nns/governance/tests/fake.rs | 3 +- rs/registry/canister/canister/registry.did | 1 + .../ic_registry_canister/pb/v1/registry.proto | 2 ++ .../src/gen/ic_registry_canister.pb.v1.rs | 3 ++ .../get_node_providers_monthly_xdr_rewards.rs | 31 +++++++++++++------ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/rs/nns/governance/tests/fake.rs b/rs/nns/governance/tests/fake.rs index 4a13045138f..97c46ab94b0 100644 --- a/rs/nns/governance/tests/fake.rs +++ b/rs/nns/governance/tests/fake.rs @@ -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()); diff --git a/rs/registry/canister/canister/registry.did b/rs/registry/canister/canister/registry.did index 20715a7e669..14025b7f62b 100644 --- a/rs/registry/canister/canister/registry.did +++ b/rs/registry/canister/canister/registry.did @@ -231,6 +231,7 @@ type NodeOperatorRecord = record { type NodeProvidersMonthlyXdrRewards = record { rewards : vec record { text; nat64 }; + registry_version: opt nat64; }; type NodeRewardRate = record { diff --git a/rs/registry/canister/proto/ic_registry_canister/pb/v1/registry.proto b/rs/registry/canister/proto/ic_registry_canister/pb/v1/registry.proto index 24100cd8bc3..d8c6eaf05dc 100644 --- a/rs/registry/canister/proto/ic_registry_canister/pb/v1/registry.proto +++ b/rs/registry/canister/proto/ic_registry_canister/pb/v1/registry.proto @@ -91,6 +91,8 @@ message RegistryCanisterStableStorage { // rewarded for providing nodes to the Internet Computer for the month. message NodeProvidersMonthlyXdrRewards { map 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. diff --git a/rs/registry/canister/src/gen/ic_registry_canister.pb.v1.rs b/rs/registry/canister/src/gen/ic_registry_canister.pb.v1.rs index 8881273da5a..0973d292101 100644 --- a/rs/registry/canister/src/gen/ic_registry_canister.pb.v1.rs +++ b/rs/registry/canister/src/gen/ic_registry_canister.pb.v1.rs @@ -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, } /// 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. diff --git a/rs/registry/canister/src/get_node_providers_monthly_xdr_rewards.rs b/rs/registry/canister/src/get_node_providers_monthly_xdr_rewards.rs index b831821cd4c..ccefcf419e9 100644 --- a/rs/registry/canister/src/get_node_providers_monthly_xdr_rewards.rs +++ b/rs/registry/canister/src/get_node_providers_monthly_xdr_rewards.rs @@ -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 @@ -186,6 +186,8 @@ impl Registry { } } + rewards.registry_version = Some(self.latest_version()); + Ok(rewards) } } @@ -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}; @@ -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 @@ -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(),