Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/rustc 1 83 0 #12

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
Cargo.lock
.vscode
.env
.idea/
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions crates/dscvr-canister-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions crates/dscvr-canister-agent/src/agent_impl.rs
Original file line number Diff line number Diff line change
@@ -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_RETRIES: usize = 3;

pub mod embedded_canister_impl;
pub mod replica_impl;
pub mod state_machine_impl;
Expand All @@ -26,6 +30,12 @@ pub trait AgentImpl: Sync + Send {
fn get_principal(&self) -> Result<Principal>;
}

pub fn get_route_provider_and_client(url: &str) -> Result<(Arc<RoundRobinRouteProvider>, 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 {
Expand Down
11 changes: 8 additions & 3 deletions crates/dscvr-canister-agent/src/agent_impl/replica_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,8 +55,11 @@ impl AgentImpl for WrappedAgent {
}

async fn clone_with_identity(&self, identity: Arc<dyn Identity>) -> Result<Arc<dyn AgentImpl>> {
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_RETRIES)
.with_arc_identity(identity)
.with_verify_query_signatures(false)
.build()?;
Expand Down Expand Up @@ -89,8 +91,11 @@ pub async fn new<U: Into<String>>(
url: U,
) -> Result<Arc<dyn AgentImpl>> {
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_RETRIES)
.with_arc_identity(identity)
.with_verify_query_signatures(false)
.build()?;
Expand Down
2 changes: 2 additions & 0 deletions crates/dscvr-canister-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_RETRIES;

/// The content format stored in stable storage
/// TODO: autogenerate from did
Expand Down
5 changes: 2 additions & 3 deletions crates/dscvr-canister-config/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn generate_dfx_config_for_network(dscvr_cfg: &DSCVRConfig, network: &str) -
///
/// ### Returns
/// - `Result<Vec<CanisterInstance>>` - 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,
Expand Down Expand Up @@ -158,8 +158,7 @@ pub fn augment_canister_ids(canister: &str, network: &str) -> Result<()> {
///
/// ### Returns
/// - `Result<Vec<CanisterInstance>>` - Returns `Ok()` with a `Vec<CanisterInstance>`
/// 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,
Expand Down
4 changes: 2 additions & 2 deletions crates/dscvr-canister-config/src/schema/dscvr/allocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl DSCVRConfig {
///
/// ### Returns
/// - `Result<Vec<CanisterInstance, DSCVRGenerationError>` - 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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions crates/dscvr-canister-config/src/schema/dscvr/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<CanisterInstance>, 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/dscvr-canister-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a, State> ImmutableContext<'a, State> {
}
}

impl<'a, State> Clone for ImmutableContext<'a, State> {
impl<State> Clone for ImmutableContext<'_, State> {
#[inline]
fn clone(&self) -> Self {
Self {
Expand Down
8 changes: 4 additions & 4 deletions crates/ic-canister-io/src/movable_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ impl<'a, R: Read + Seek> MovableReader<'a, R> {
}
}

impl<'a, R: Read + Seek> Read for MovableReader<'a, R> {
impl<R: Read + Seek> Read for MovableReader<'_, R> {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
Read::read(&mut self.reader, buf)
}
}

impl<'a, R: Read + Seek> Seek for MovableReader<'a, R> {
impl<R: Read + Seek> Seek for MovableReader<'_, R> {
#[inline]
fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
Seek::seek(&mut self.reader, pos)
Expand All @@ -44,7 +44,7 @@ impl<'a, W: Write + Seek> MovableWriter<'a, W> {
}
}

impl<'a, W: Write + Seek> Write for MovableWriter<'a, W> {
impl<W: Write + Seek> Write for MovableWriter<'_, W> {
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Write::write(&mut self.writer, buf)
Expand All @@ -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<W: Write + Seek> Seek for MovableWriter<'_, W> {
#[inline]
fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
Seek::seek(&mut self.writer, pos)
Expand Down
10 changes: 5 additions & 5 deletions crates/ic-canister-stable-storage/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ 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)
}

/// Initialize the stable storage with the given length
#[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
Expand All @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions crates/ic-ingress-validator-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
7 changes: 5 additions & 2 deletions crates/ic-ingress-validator-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ic_agent::agent::http_transport::ReqwestTransport;
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;
Expand All @@ -10,8 +10,11 @@ use std::sync::Arc;
pub type IcHttpRequestVerifier = Arc<dyn HttpRequestVerifier<UserQuery> + Send + Sync>;

pub async fn try_new_ingress_verifier(url: &str) -> Result<IcHttpRequestVerifier> {
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_RETRIES)
.with_arc_identity(Arc::new(AnonymousIdentity))
.build()?;
agent.fetch_root_key().await?;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.79.0"
channel = "1.81.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]