From 685ebf76541cdb7132c89a8b26b5bf6199ac3c6c Mon Sep 17 00:00:00 2001 From: Leif Brockman Date: Tue, 10 Dec 2024 09:25:15 -0700 Subject: [PATCH 1/3] chore: update rustc 1.83.0 --- .gitignore | 2 ++ Cargo.toml | 15 ++++++++------- crates/dscvr-canister-agent/Cargo.toml | 1 + crates/dscvr-canister-agent/src/agent_impl.rs | 10 ++++++++++ .../src/agent_impl/replica_impl.rs | 11 ++++++++--- crates/dscvr-canister-agent/src/lib.rs | 2 ++ .../ic-canister-stable-storage/src/interface.rs | 10 +++++----- crates/ic-ingress-validator-util/Cargo.toml | 5 +++++ crates/ic-ingress-validator-util/src/lib.rs | 7 +++++-- rust-toolchain.toml | 2 +- 10 files changed, 47 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index c8e9e48..8320548 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target Cargo.lock .vscode +.env +.idea/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 0feba94..8190f4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,26 +33,27 @@ deepsize = { git = "https://github.com/dscvr-one/deepsize.git", tag = "dscvr-202 "std", ] } derive_more = "0.99" -enum-iterator = "1.2.0" +enum-iterator = "2.1.0" flate2 = "1.0" futures = "0.3.25" -ic-agent = { version = "0.34.0", features = ["pem"] } -ic-cdk = "0.13" +ic-agent = { version = "0.39.1", features = ["pem", "ring"] } +ic-cdk = "0.17.0" lazy_static = "1.4" num-traits = "0.2.15" -ring = "0.17" +reqwest = { version = "~0.12.9", features = ["blocking", "json", "rustls-tls-webpki-roots", "stream" ] } +ring = { version = "0.17", features = ["std"] } rmp-serde = "1.1" -rustc-hash = { version = "1.1" } +rustc-hash = { version = "2.1" } serde = "1.0" serde_bytes = "0.11" serde_json = "1.0" -thiserror = "1.0" +thiserror = "~2.0.6" time = "0.3.17" tokio = "1.0" tokio-retry = "0.3" tracing = "0.1" tracing-error = { version = "0.2", features = ["traced-error"] } -tracing-stackdriver = "0.8" +tracing-stackdriver = "0.10.0" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [patch.crates-io] diff --git a/crates/dscvr-canister-agent/Cargo.toml b/crates/dscvr-canister-agent/Cargo.toml index 601d24e..13c1a76 100644 --- a/crates/dscvr-canister-agent/Cargo.toml +++ b/crates/dscvr-canister-agent/Cargo.toml @@ -16,6 +16,7 @@ futures.workspace = true garcon = "0.2.3" hex = "0.4" ic-agent.workspace = true +reqwest.workspace = true serde_bytes.workspace = true serde.workspace = true thiserror.workspace = true diff --git a/crates/dscvr-canister-agent/src/agent_impl.rs b/crates/dscvr-canister-agent/src/agent_impl.rs index 9425ad2..36ea9ea 100644 --- a/crates/dscvr-canister-agent/src/agent_impl.rs +++ b/crates/dscvr-canister-agent/src/agent_impl.rs @@ -1,8 +1,12 @@ use candid::Principal; +use ic_agent::agent::route_provider::RoundRobinRouteProvider; use ic_agent::Identity; use instrumented_error::Result; +use reqwest::Client; use std::sync::Arc; +pub const MAX_ERROR_RETIRES: usize = 3; + pub mod embedded_canister_impl; pub mod replica_impl; pub mod state_machine_impl; @@ -26,6 +30,12 @@ pub trait AgentImpl: Sync + Send { fn get_principal(&self) -> Result; } +pub fn get_route_provider_and_client(url: &str) -> Result<(Arc, Client)> { + let route_provider = Arc::new(RoundRobinRouteProvider::new(vec![url])?); + let client = Client::builder().use_rustls_tls().build()?; + Ok((route_provider, client)) +} + #[allow(dead_code)] #[derive(Clone, Copy)] pub enum AgentImplType { diff --git a/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs b/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs index 53d9bb8..7880942 100644 --- a/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs +++ b/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use std::time::Duration; use candid::Principal; -use ic_agent::agent::http_transport::reqwest_transport::ReqwestHttpReplicaV2Transport; use ic_agent::Agent; use ic_agent::Identity; use instrumented_error::IntoInstrumentedError; @@ -56,8 +55,11 @@ impl AgentImpl for WrappedAgent { } async fn clone_with_identity(&self, identity: Arc) -> Result> { + let (route_provider, client) = super::get_route_provider_and_client(&self.url)?; let agent = Agent::builder() - .with_transport(ReqwestHttpReplicaV2Transport::create(&self.url)?) + .with_arc_route_provider(route_provider) + .with_http_client(client) + .with_max_tcp_error_retries(super::MAX_ERROR_RETIRES) .with_arc_identity(identity) .with_verify_query_signatures(false) .build()?; @@ -89,8 +91,11 @@ pub async fn new>( url: U, ) -> Result> { let url_string: String = url.into(); + let (route_provider, client) = super::get_route_provider_and_client(&url_string)?; let agent = Agent::builder() - .with_transport(ReqwestHttpReplicaV2Transport::create(url_string.clone())?) + .with_arc_route_provider(route_provider) + .with_http_client(client) + .with_max_tcp_error_retries(super::MAX_ERROR_RETIRES) .with_arc_identity(identity) .with_verify_query_signatures(false) .build()?; diff --git a/crates/dscvr-canister-agent/src/lib.rs b/crates/dscvr-canister-agent/src/lib.rs index ce179d0..e7c711b 100644 --- a/crates/dscvr-canister-agent/src/lib.rs +++ b/crates/dscvr-canister-agent/src/lib.rs @@ -23,7 +23,9 @@ mod module_hash; mod stable_storage_restore_backup; mod stats; +pub use agent_impl::get_route_provider_and_client; pub use agent_impl::AgentImpl; +pub use agent_impl::MAX_ERROR_RETIRES; /// The content format stored in stable storage /// TODO: autogenerate from did diff --git a/crates/ic-canister-stable-storage/src/interface.rs b/crates/ic-canister-stable-storage/src/interface.rs index 107cc34..d6f1f1e 100644 --- a/crates/ic-canister-stable-storage/src/interface.rs +++ b/crates/ic-canister-stable-storage/src/interface.rs @@ -28,7 +28,7 @@ pub fn stable_storage_info() -> (Header, Transient) { #[inline] pub fn backup_stable_storage(offset: u64, limit: usize) -> ByteBuf { let mut bytes = vec![0; limit]; - ic_cdk::api::stable::stable64_read(offset, &mut bytes); + ic_cdk::api::stable::stable_read(offset, &mut bytes); ByteBuf::from(bytes) } @@ -36,17 +36,17 @@ pub fn backup_stable_storage(offset: u64, limit: usize) -> ByteBuf { #[inline] pub fn init_stable_storage(len: u64) { let page_count = len / WASM_PAGE_SIZE_IN_BYTES as u64 + 1; - let current = ic_cdk::api::stable::stable64_size(); + let current = ic_cdk::api::stable::stable_size(); if page_count > current { info!("Growing stable storage from {} to {}", current, page_count); - ic_cdk::api::stable::stable64_grow(page_count).unwrap(); + ic_cdk::api::stable::stable_grow(page_count).unwrap(); } } /// Restore the stable storage #[inline] pub fn restore_stable_storage(offset: u64, bytes: ByteBuf) { - ic_cdk::api::stable::stable64_write(offset, &bytes.into_vec()); + ic_cdk::api::stable::stable_write(offset, &bytes.into_vec()); } /// Restore the stable storage from a compressed array of byte buffers @@ -57,7 +57,7 @@ pub fn restore_stable_storage_compressed(mut offset: u64, compressed_bytes_vec: flate2::read::GzDecoder::new(&bytes.into_vec()[..]) .read_to_end(&mut read_buffer) .unwrap(); - ic_cdk::api::stable::stable64_write(offset, &read_buffer); + ic_cdk::api::stable::stable_write(offset, &read_buffer); offset += read_buffer.len() as u64; read_buffer.clear(); } diff --git a/crates/ic-ingress-validator-util/Cargo.toml b/crates/ic-ingress-validator-util/Cargo.toml index 0a8aecc..64d1573 100644 --- a/crates/ic-ingress-validator-util/Cargo.toml +++ b/crates/ic-ingress-validator-util/Cargo.toml @@ -11,5 +11,10 @@ ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", ic-types = { git = "https://github.com/dfinity/ic.git", rev = "release-2024-04-17_23-01-query-stats", package = "ic-types" } ic-validator-ingress-message = { git = "https://github.com/dfinity/ic.git", rev = "release-2024-04-17_23-01-query-stats", package = "ic-validator-ingress-message" } +hex = "0.4.3" ic-identity-util = { path = "../ic-identity-util" } instrumented-error = { path = "../instrumented-error" } +thiserror.workspace = true + +#internal +dscvr-canister-agent = { path = "../dscvr-canister-agent" } diff --git a/crates/ic-ingress-validator-util/src/lib.rs b/crates/ic-ingress-validator-util/src/lib.rs index f12474a..d42ec4d 100644 --- a/crates/ic-ingress-validator-util/src/lib.rs +++ b/crates/ic-ingress-validator-util/src/lib.rs @@ -1,4 +1,4 @@ -use ic_agent::agent::http_transport::ReqwestTransport; +use dscvr_canister_agent::MAX_ERROR_RETIRES; use ic_agent::identity::AnonymousIdentity; use ic_agent::Agent; use ic_crypto_utils_threshold_sig_der::parse_threshold_sig_key_from_der; @@ -10,8 +10,11 @@ use std::sync::Arc; pub type IcHttpRequestVerifier = Arc + Send + Sync>; pub async fn try_new_ingress_verifier(url: &str) -> Result { + let (route_provider, client) = dscvr_canister_agent::get_route_provider_and_client(url)?; let agent: Agent = Agent::builder() - .with_transport(ReqwestTransport::create(url)?) + .with_arc_route_provider(route_provider) + .with_http_client(client) + .with_max_tcp_error_retries(MAX_ERROR_RETIRES) .with_arc_identity(Arc::new(AnonymousIdentity)) .build()?; agent.fetch_root_key().await?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 756e027..0af9708 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.79.0" +channel = "1.83.0" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"] From 403af98821cfc54d77ec8ed4057fe32d3bef162c Mon Sep 17 00:00:00 2001 From: Leif Brockman Date: Tue, 10 Dec 2024 09:39:44 -0700 Subject: [PATCH 2/3] chore: clippy --- crates/dscvr-canister-config/src/schema.rs | 5 ++--- .../src/schema/dscvr/allocate.rs | 4 ++-- .../src/schema/dscvr/provision.rs | 12 ++++++------ crates/dscvr-canister-context/src/lib.rs | 2 +- crates/ic-canister-io/src/movable_io.rs | 8 ++++---- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/crates/dscvr-canister-config/src/schema.rs b/crates/dscvr-canister-config/src/schema.rs index eab01cb..f823029 100644 --- a/crates/dscvr-canister-config/src/schema.rs +++ b/crates/dscvr-canister-config/src/schema.rs @@ -84,7 +84,7 @@ pub fn generate_dfx_config_for_network(dscvr_cfg: &DSCVRConfig, network: &str) - /// /// ### Returns /// - `Result>` - returns `Ok()` with a copy of the -/// newly available canister instances on success. +/// newly available canister instances on success. pub fn allocate_canisters( canister: &str, network: &str, @@ -158,8 +158,7 @@ pub fn augment_canister_ids(canister: &str, network: &str) -> Result<()> { /// /// ### Returns /// - `Result>` - Returns `Ok()` with a `Vec` -/// that were provisioned. These can be used to perform canister operations. - +/// that were provisioned. These can be used to perform canister operations. pub fn provision_canisters( config: &mut DSCVRConfig, canister: &str, diff --git a/crates/dscvr-canister-config/src/schema/dscvr/allocate.rs b/crates/dscvr-canister-config/src/schema/dscvr/allocate.rs index fab6ea4..9d92884 100644 --- a/crates/dscvr-canister-config/src/schema/dscvr/allocate.rs +++ b/crates/dscvr-canister-config/src/schema/dscvr/allocate.rs @@ -12,7 +12,7 @@ impl DSCVRConfig { /// /// ### Returns /// - `Result` - Returns `Ok()` with a copy - /// of the newly available canisters if successful. + /// of the newly available canisters if successful. pub(crate) fn add_available_canisters( &mut self, canister_name: &str, @@ -63,7 +63,7 @@ impl DSCVRConfig { /// /// ### Returns /// - `Result<(), DSCVRGenerationErr>` - Returns `Ok()` if able to update canister - /// instances. + /// instances. pub(crate) fn register_available_canisters( &mut self, canister_name: &str, diff --git a/crates/dscvr-canister-config/src/schema/dscvr/provision.rs b/crates/dscvr-canister-config/src/schema/dscvr/provision.rs index 4be089c..7087189 100644 --- a/crates/dscvr-canister-config/src/schema/dscvr/provision.rs +++ b/crates/dscvr-canister-config/src/schema/dscvr/provision.rs @@ -8,17 +8,17 @@ impl DSCVRConfig { /// /// ### Inputs /// - `canister_name: &str` - Name of the canister to provision - /// instances for. + /// instances for. /// - `network: &str` - The network to provision instances in. /// - `count: usize` - The number of instances to provision. If - /// this is greater than the number of availble instances for the - /// specified `canister & network`, will throw an error. + /// this is greater than the number of availble instances for the + /// specified `canister & network`, will throw an error. /// /// ### Returns /// - `Result, DSCVRGenerationError>` - returns - /// `Ok()` with the `provisioned_instances` if successful. These are - /// the instances that should be passed to the `dfx canister install` - /// command. + /// `Ok()` with the `provisioned_instances` if successful. These are + /// the instances that should be passed to the `dfx canister install` + /// command. pub(crate) fn provision_canisters( &mut self, canister_name: &str, diff --git a/crates/dscvr-canister-context/src/lib.rs b/crates/dscvr-canister-context/src/lib.rs index 870ee3d..495534f 100644 --- a/crates/dscvr-canister-context/src/lib.rs +++ b/crates/dscvr-canister-context/src/lib.rs @@ -60,7 +60,7 @@ impl<'a, State> ImmutableContext<'a, State> { } } -impl<'a, State> Clone for ImmutableContext<'a, State> { +impl Clone for ImmutableContext<'_, State> { #[inline] fn clone(&self) -> Self { Self { diff --git a/crates/ic-canister-io/src/movable_io.rs b/crates/ic-canister-io/src/movable_io.rs index 333ab58..704fa50 100644 --- a/crates/ic-canister-io/src/movable_io.rs +++ b/crates/ic-canister-io/src/movable_io.rs @@ -16,14 +16,14 @@ impl<'a, R: Read + Seek> MovableReader<'a, R> { } } -impl<'a, R: Read + Seek> Read for MovableReader<'a, R> { +impl Read for MovableReader<'_, R> { #[inline] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { Read::read(&mut self.reader, buf) } } -impl<'a, R: Read + Seek> Seek for MovableReader<'a, R> { +impl Seek for MovableReader<'_, R> { #[inline] fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result { Seek::seek(&mut self.reader, pos) @@ -44,7 +44,7 @@ impl<'a, W: Write + Seek> MovableWriter<'a, W> { } } -impl<'a, W: Write + Seek> Write for MovableWriter<'a, W> { +impl Write for MovableWriter<'_, W> { #[inline] fn write(&mut self, buf: &[u8]) -> std::io::Result { Write::write(&mut self.writer, buf) @@ -56,7 +56,7 @@ impl<'a, W: Write + Seek> Write for MovableWriter<'a, W> { } } -impl<'a, W: Write + Seek> Seek for MovableWriter<'a, W> { +impl Seek for MovableWriter<'_, W> { #[inline] fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result { Seek::seek(&mut self.writer, pos) From fa54375a6154a5741e04303c7ce7d1871e3498c1 Mon Sep 17 00:00:00 2001 From: Leif Brockman Date: Tue, 10 Dec 2024 10:49:47 -0700 Subject: [PATCH 3/3] fix: review feedback rustc to 1_81_0 --- crates/dscvr-canister-agent/src/agent_impl.rs | 2 +- crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs | 4 ++-- crates/dscvr-canister-agent/src/lib.rs | 2 +- crates/ic-ingress-validator-util/src/lib.rs | 4 ++-- rust-toolchain.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/dscvr-canister-agent/src/agent_impl.rs b/crates/dscvr-canister-agent/src/agent_impl.rs index 36ea9ea..0abbb41 100644 --- a/crates/dscvr-canister-agent/src/agent_impl.rs +++ b/crates/dscvr-canister-agent/src/agent_impl.rs @@ -5,7 +5,7 @@ use instrumented_error::Result; use reqwest::Client; use std::sync::Arc; -pub const MAX_ERROR_RETIRES: usize = 3; +pub const MAX_ERROR_RETRIES: usize = 3; pub mod embedded_canister_impl; pub mod replica_impl; diff --git a/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs b/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs index 7880942..c795a29 100644 --- a/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs +++ b/crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs @@ -59,7 +59,7 @@ impl AgentImpl for WrappedAgent { let agent = Agent::builder() .with_arc_route_provider(route_provider) .with_http_client(client) - .with_max_tcp_error_retries(super::MAX_ERROR_RETIRES) + .with_max_tcp_error_retries(super::MAX_ERROR_RETRIES) .with_arc_identity(identity) .with_verify_query_signatures(false) .build()?; @@ -95,7 +95,7 @@ pub async fn new>( let agent = Agent::builder() .with_arc_route_provider(route_provider) .with_http_client(client) - .with_max_tcp_error_retries(super::MAX_ERROR_RETIRES) + .with_max_tcp_error_retries(super::MAX_ERROR_RETRIES) .with_arc_identity(identity) .with_verify_query_signatures(false) .build()?; diff --git a/crates/dscvr-canister-agent/src/lib.rs b/crates/dscvr-canister-agent/src/lib.rs index e7c711b..6c37ea0 100644 --- a/crates/dscvr-canister-agent/src/lib.rs +++ b/crates/dscvr-canister-agent/src/lib.rs @@ -25,7 +25,7 @@ mod stats; pub use agent_impl::get_route_provider_and_client; pub use agent_impl::AgentImpl; -pub use agent_impl::MAX_ERROR_RETIRES; +pub use agent_impl::MAX_ERROR_RETRIES; /// The content format stored in stable storage /// TODO: autogenerate from did diff --git a/crates/ic-ingress-validator-util/src/lib.rs b/crates/ic-ingress-validator-util/src/lib.rs index d42ec4d..689c1cb 100644 --- a/crates/ic-ingress-validator-util/src/lib.rs +++ b/crates/ic-ingress-validator-util/src/lib.rs @@ -1,4 +1,4 @@ -use dscvr_canister_agent::MAX_ERROR_RETIRES; +use dscvr_canister_agent::MAX_ERROR_RETRIES; use ic_agent::identity::AnonymousIdentity; use ic_agent::Agent; use ic_crypto_utils_threshold_sig_der::parse_threshold_sig_key_from_der; @@ -14,7 +14,7 @@ pub async fn try_new_ingress_verifier(url: &str) -> Result