Skip to content

Commit

Permalink
fix: Add a time for all agent-rs (canister) clients (#435)
Browse files Browse the repository at this point in the history
We observed that the NNS proposal notification bot got stuck while checking for failed proposals.
  • Loading branch information
sasa-tomic authored May 29, 2024
1 parent cd61ab0 commit 0c4fa3e
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 242 deletions.
352 changes: 159 additions & 193 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

57 changes: 30 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ humantime = "2.1.0"
humantime-serde = "1.1.1"
hyper = { version = "1.3.1" }
hyper-tls = "0.6.0"
ic-agent = "0.34.0"
ic-agent = "0.35.0"
ic-async-utils = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-base-types = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-canister-client-sender = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-canisters = { path = "rs/ic-canisters" }
ic-cdk = "0.13.1"
ic-cdk = "0.14.0"
ic-config = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-http-endpoints-metrics = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-identity-hsm = "0.34.0"
ic-identity-hsm = "0.35.0"
ic-interfaces = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-interfaces-registry = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-management-backend = { path = "rs/ic-management-backend" }
Expand Down Expand Up @@ -131,9 +131,9 @@ ic-nervous-system-root = { git = "https://github.com/dfinity/ic.git", rev = "5ba
ic-nervous-system-clients = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-utils = "0.34.0"
ic-utils = "0.35.0"
include_dir = "0.7.3"
itertools = "0.12.0"
itertools = "0.13.0"
keyring = "2.0.2"
lazy_static = "1.4.0"
log = "0.4.21"
Expand Down
1 change: 1 addition & 0 deletions rs/ic-canisters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ic-utils = { workspace = true }
log = { workspace = true }
pkcs11 = { workspace = true }
prost = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
simple_asn1 = { workspace = true }
Expand Down
11 changes: 8 additions & 3 deletions rs/ic-canisters/src/governance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use candid::Decode;
use ic_agent::agent::http_transport::ReqwestTransport;
use ic_agent::Agent;
use ic_nns_common::pb::v1::NeuronId;
use ic_nns_common::pb::v1::ProposalId;
Expand All @@ -12,6 +13,7 @@ use ic_nns_governance::pb::v1::ProposalInfo;
use log::warn;
use serde::{self, Serialize};
use std::str::FromStr;
use std::time::Duration;
use url::Url;

use crate::CanisterClient;
Expand All @@ -23,10 +25,13 @@ pub struct GovernanceCanisterVersion {
}

pub async fn governance_canister_version(nns_urls: &[Url]) -> Result<GovernanceCanisterVersion, anyhow::Error> {
let client = reqwest::Client::builder()
.use_rustls_tls()
.timeout(Duration::from_secs(30))
.build()
.expect("Could not create HTTP client.");
let canister_agent = Agent::builder()
.with_transport(ic_agent::agent::http_transport::reqwest_transport::ReqwestHttpReplicaV2Transport::create(
nns_urls[0].clone(),
)?)
.with_transport(ReqwestTransport::create_with_client(nns_urls[0].clone(), client)?)
.with_verify_query_signatures(false)
.build()?;

Expand Down
19 changes: 12 additions & 7 deletions rs/ic-canisters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use serde::Deserialize;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Mutex;
use std::time::Duration;
use url::Url;

pub mod governance;
Expand Down Expand Up @@ -83,13 +84,17 @@ impl IcAgentCanisterClient {
}

fn build_agent(url: Url, identity: Box<dyn Identity>) -> anyhow::Result<Self> {
Ok(Self {
agent: Agent::builder()
.with_identity(identity)
.with_transport(ReqwestTransport::create(url)?)
.with_verify_query_signatures(false)
.build()?,
})
let client = reqwest::Client::builder()
.use_rustls_tls()
.timeout(Duration::from_secs(30))
.build()
.expect("Could not create HTTP client.");
let agent = Agent::builder()
.with_identity(identity)
.with_transport(ReqwestTransport::create_with_client(url, client)?)
.with_verify_query_signatures(false)
.build()?;
Ok(Self { agent })
}
}

Expand Down
12 changes: 10 additions & 2 deletions rs/ic-management-backend/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::time::Duration;

use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;
use candid::{Decode, Encode};

use futures_util::future::try_join_all;
use ic_agent::agent::http_transport::reqwest_transport::ReqwestHttpReplicaV2Transport;
use ic_agent::agent::http_transport::ReqwestTransport;
use ic_agent::Agent;
use ic_management_types::UpdateElectedHostosVersionsProposal;
use ic_management_types::UpdateElectedReplicaVersionsProposal;
Expand Down Expand Up @@ -85,11 +87,17 @@ pub struct UpdateUnassignedNodesProposal {
#[allow(dead_code)]
impl ProposalAgent {
pub fn new(nns_urls: &[Url]) -> Self {
let client = reqwest::Client::builder()
.use_rustls_tls()
.timeout(Duration::from_secs(30))
.build()
.expect("Could not create HTTP client.");
let agent = Agent::builder()
.with_transport(ReqwestHttpReplicaV2Transport::create(nns_urls[0].clone()).expect("failed to create transport"))
.with_transport(ReqwestTransport::create_with_client(nns_urls[0].clone(), client).expect("Failed to create transport"))
.with_verify_query_signatures(false)
.build()
.expect("failed to build the agent");

Self { agent }
}

Expand Down
1 change: 1 addition & 0 deletions rs/ic-observability/obs-canister-clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ic-agent = { workspace = true }
candid = { workspace = true }
serde = { workspace = true }
rand = { workspace = true }
reqwest = { workspace = true }
url = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::Duration;

use candid::{CandidType, Decode, Encode};
use ic_agent::agent::http_transport::ReqwestTransport;
use ic_agent::{export::Principal, identity::AnonymousIdentity, Agent};
use rand::seq::SliceRandom;
use serde::Deserialize;
Expand Down Expand Up @@ -45,12 +48,17 @@ impl NodeStatusCanister {
agent: url
.iter()
.map(|url| {
let client = reqwest::Client::builder()
.use_rustls_tls()
.timeout(Duration::from_secs(30))
.build()
.expect("Could not create HTTP client.");
Agent::builder()
.with_url(url.as_str())
.with_transport(ReqwestTransport::create_with_client(url.as_str(), client).expect("Failed to create transport"))
.with_identity(AnonymousIdentity)
.with_verify_query_signatures(false)
.build()
.unwrap()
.expect("Failed to build agent")
})
.collect(),
}
Expand Down
Loading

0 comments on commit 0c4fa3e

Please sign in to comment.