Skip to content

Commit

Permalink
Use local registry in NPR App (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrodimarco-dfinity authored Nov 14, 2024
1 parent 4d305a7 commit dee4d21
Show file tree
Hide file tree
Showing 15 changed files with 2,147 additions and 1,818 deletions.
2,639 changes: 1,304 additions & 1,335 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

799 changes: 392 additions & 407 deletions Cargo.lock

Large diffs are not rendered by default.

77 changes: 39 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,47 @@ self_update = { version = "0.41.0", default-features = false, features = [
"archive-tar",
"rustls",
] }
ic-async-utils = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-base-types = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-canister-client-sender = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-async-utils = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-base-types = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-canister-client-sender = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-canisters = { path = "rs/ic-canisters" }
ic-nervous-system-common-test-keys = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nervous-system-common-test-keys = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-cdk = { git = "https://github.com/dfinity/cdk-rs.git", rev = "8f57d6d26b1d142b5be4b39ea8ade59d7c848cde" }
ic-config = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-http-endpoints-metrics = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-interfaces-registry = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-config = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-http-endpoints-metrics = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-interfaces-registry = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-management-backend = { path = "rs/ic-management-backend" }
ic-management-canister-types = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-management-canister-types = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-management-types = { path = "rs/ic-management-types" }
ic-metrics = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nns-common = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nns-constants = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nns-governance = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nns-governance-api = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-protobuf = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-client = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-client-fake = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-client-helpers = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-common-proto = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-keys = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-local-registry = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-local-store = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-local-store-artifacts = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-nns-data-provider = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-subnet-type = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-registry-transport = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-sys = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-types = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-nervous-system-clients = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-icrc1-test-utils = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
rosetta-core = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
icrc-ledger-types = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
ic-metrics = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nns-common = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nns-constants = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nns-governance = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nns-governance-api = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-protobuf = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-client = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-client-fake = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-client-helpers = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-common-proto = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-keys = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-local-registry = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-local-store = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-local-store-artifacts = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-nns-data-provider = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-subnet-type = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-registry-transport = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-sys = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-types = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-nervous-system-clients = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-icrc1-test-utils = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
rosetta-core = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
icrc-ledger-types = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
ic-transport-types = "0.39.1"
ic-utils = "0.39.0"
itertools = "0.13.0"
Expand All @@ -155,7 +156,7 @@ prost = "0.13"
rand = { version = "0.8.5", features = ["std_rng"] }
rand_seeder = "0.3.0"
regex = "1.11.1"
registry-canister = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
registry-canister = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls-webpki-roots",
"blocking",
Expand Down Expand Up @@ -198,7 +199,7 @@ mockall = "0.13.0"
ic-cdk-timers = { git = "https://github.com/dfinity/cdk-rs.git", rev = "8f57d6d26b1d142b5be4b39ea8ade59d7c848cde" }
ic-cdk-macros = { git = "https://github.com/dfinity/cdk-rs.git", rev = "8f57d6d26b1d142b5be4b39ea8ade59d7c848cde" }
ic-stable-structures = "0.6.5"
dfn_core = { git = "https://github.com/dfinity/ic.git", rev = "3c3d9cd3600c744a44405749eff7cf187ef8d75d" }
dfn_core = { git = "https://github.com/dfinity/ic.git", rev = "132c2452bea8a9df83c54cd02835d64451f67250" }
node-provider-rewards-lib = { path = "rs/dre-canisters/node-provider-rewards-lib" }

# dre-airflow deps, should be replaced with dre-airflow once
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ aspect_bazel_lib_dependencies()

aspect_bazel_lib_register_toolchains()

IC_REPO_VERSION = "3c3d9cd3600c744a44405749eff7cf187ef8d75d"
IC_REPO_VERSION = "132c2452bea8a9df83c54cd02835d64451f67250"

http_archive(
name = "ic_repo",
Expand Down
5 changes: 5 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ crate = "ic-registry-canister-api"
expression = "LicenseRef-IC-1.0"
license-files = [{ path = "../../../../LICENSE", hash = 0xbd0eed23 }]

[[licenses.clarify]]
crate = "ic-registry-canister-client"
expression = "LicenseRef-IC-1.0"
license-files = [{ path = "../../../LICENSE", hash = 0xbd0eed23 }]

[[licenses.clarify]]
crate = "ic-registry-client"
expression = "LicenseRef-IC-1.0"
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENV CARGO_HOME=/cargo
COPY docker /docker

# Download ic-admin
ARG ic_git_revision=3c3d9cd3600c744a44405749eff7cf187ef8d75d
ARG ic_git_revision=132c2452bea8a9df83c54cd02835d64451f67250
RUN curl --fail https://download.dfinity.systems/ic/${ic_git_revision}/release/ic-admin.gz -o - | gunzip -c >| /usr/bin/ic-admin && \
chmod +x /usr/bin/ic-admin

Expand Down
2 changes: 1 addition & 1 deletion ic-revisions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"https://github.com/dfinity/ic.git": {
"commit": "3c3d9cd3600c744a44405749eff7cf187ef8d75d",
"commit": "132c2452bea8a9df83c54cd02835d64451f67250",
"ref": "refs/heads/master"
},
"https://github.com/dfinity/cdk-rs.git": {
Expand Down
2 changes: 1 addition & 1 deletion pylib/ic_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ def canister_version(agent: Agent, canister_principal: str) -> str:

if __name__ == "__main__":
# One can run some simple one-off tests here, e.g.:
ic_admin = IcAdmin("https://ic0.app", git_revision="3c3d9cd3600c744a44405749eff7cf187ef8d75d")
ic_admin = IcAdmin("https://ic0.app", git_revision="132c2452bea8a9df83c54cd02835d64451f67250")

print(ic_admin.get_subnet_replica_versions())
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ impl Storable for NodeMetadataStored {
};
}

#[derive(Debug, Deserialize, Serialize, CandidType, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct RegistryKey {
pub version: u64,
pub key: String,
}

const MAX_VALUE_SIZE_BYTES_REGISTRY_KEY: u32 = 200;

impl Storable for RegistryKey {
fn to_bytes(&self) -> std::borrow::Cow<[u8]> {
Cow::Owned(Encode!(self).unwrap())
}

fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self {
Decode!(bytes.as_ref(), Self).unwrap()
}

const BOUND: Bound = Bound::Bounded {
max_size: MAX_VALUE_SIZE_BYTES_REGISTRY_KEY,
is_fixed_size: false,
};
}

#[derive(Debug, Deserialize, Serialize, CandidType, Clone)]
pub struct NodeMetadataStoredV2 {
pub node_operator_id: Principal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ dfn_core = { workspace = true }
trustworthy-node-metrics-types = { workspace = true }
ic-base-types = { workspace = true }
ic-registry-keys = { workspace = true }
ic-registry-transport = { workspace = true }
ic-types = { workspace = true }
rust_decimal = { workspace = true }
rust_decimal_macros = { workspace = true }
num-traits = { workspace = true }
ic-nns-constants = { workspace = true }
ic-nns-governance-api = { workspace = true }
ic-registry-canister-client = { workspace = true }
lazy_static = { workspace = true }
prost = { workspace = true }
ic-interfaces-registry = { workspace = true }
node-provider-rewards-lib = { workspace = true }
chrono = { version = "0.4", default-features = false, features = ["std"] }
ahash = { version = "0.8.11", default-features = false, features = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,42 @@ use candid::Principal;
use chrono_utils::DateTimeRange;
use ic_cdk_macros::*;
use itertools::Itertools;
use std::collections::{btree_map::Entry, BTreeMap};
use local_registry::LocalRegistry;
use registry_querier::RegistryQuerier;
use std::{
cell::RefCell,
collections::{btree_map::Entry, BTreeMap},
rc::Rc,
};
use trustworthy_node_metrics_types::types::{
NodeMetadata, NodeMetrics, NodeMetricsStored, NodeMetricsStoredKey, NodeProviderRewards, NodeProviderRewardsArgs, NodeRewardsArgs,
NodeRewardsMultiplier, SubnetNodeMetricsArgs, SubnetNodeMetricsResponse,
};
mod chrono_utils;
mod local_registry;
mod metrics_manager;
mod registry_querier;
mod rewards_manager;
mod stable_memory;

// Management canisters updates node metrics every day
const TIMER_INTERVAL_SEC: u64 = 60 * 60 * 24;

thread_local! {
static LOCAL_REGISTRY: RefCell<Rc<LocalRegistry>> = RefCell::new(Rc::new(Default::default()));
}

async fn update_metrics_task() {
let local_registry = LOCAL_REGISTRY.with_borrow(|local_registry| local_registry.clone());
match local_registry.sync_registry_stored().await {
Ok(_) => {
ic_cdk::println!("Successfully sync_registry_stored");
}
Err(e) => {
ic_cdk::println!("Error sync_registry_stored: {}", e);
}
}

match metrics_manager::update_metrics().await {
Ok(_) => {
ic_cdk::println!("Successfully updated metrics");
Expand Down Expand Up @@ -120,6 +142,8 @@ fn node_rewards(args: NodeRewardsArgs) -> NodeRewardsMultiplier {
fn node_provider_rewards(args: NodeProviderRewardsArgs) -> NodeProviderRewards {
let rewarding_period = DateTimeRange::new(args.from_ts, args.to_ts);
let node_provider_id = args.node_provider_id;

rewards_manager::node_provider_rewards(node_provider_id, rewarding_period)
let registry_querier = RegistryQuerier {
local_registry: LOCAL_REGISTRY.with_borrow(|local_registry| local_registry.clone()),
};
rewards_manager::node_provider_rewards(node_provider_id, rewarding_period, registry_querier)
}
Loading

0 comments on commit dee4d21

Please sign in to comment.