Skip to content

Commit 0c4fa3e

Browse files
authored
fix: Add a time for all agent-rs (canister) clients (#435)
We observed that the NNS proposal notification bot got stuck while checking for failed proposals.
1 parent cd61ab0 commit 0c4fa3e

File tree

11 files changed

+244
-242
lines changed

11 files changed

+244
-242
lines changed

Cargo.Bazel.lock

Lines changed: 159 additions & 193 deletions
Large diffs are not rendered by default.

Cargo.lock

Lines changed: 30 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ humantime = "2.1.0"
9393
humantime-serde = "1.1.1"
9494
hyper = { version = "1.3.1" }
9595
hyper-tls = "0.6.0"
96-
ic-agent = "0.34.0"
96+
ic-agent = "0.35.0"
9797
ic-async-utils = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
9898
ic-base-types = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
9999
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
100100
ic-canister-client-sender = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
101101
ic-canisters = { path = "rs/ic-canisters" }
102-
ic-cdk = "0.13.1"
102+
ic-cdk = "0.14.0"
103103
ic-config = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
104104
ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
105105
ic-http-endpoints-metrics = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
106-
ic-identity-hsm = "0.34.0"
106+
ic-identity-hsm = "0.35.0"
107107
ic-interfaces = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
108108
ic-interfaces-registry = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
109109
ic-management-backend = { path = "rs/ic-management-backend" }
@@ -131,9 +131,9 @@ ic-nervous-system-root = { git = "https://github.com/dfinity/ic.git", rev = "5ba
131131
ic-nervous-system-clients = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
132132
ic-sns-wasm = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
133133
cycles-minting-canister = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
134-
ic-utils = "0.34.0"
134+
ic-utils = "0.35.0"
135135
include_dir = "0.7.3"
136-
itertools = "0.12.0"
136+
itertools = "0.13.0"
137137
keyring = "2.0.2"
138138
lazy_static = "1.4.0"
139139
log = "0.4.21"

rs/ic-canisters/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ic-utils = { workspace = true }
2626
log = { workspace = true }
2727
pkcs11 = { workspace = true }
2828
prost = { workspace = true }
29+
reqwest = { workspace = true }
2930
serde = { workspace = true }
3031
sha2 = { workspace = true }
3132
simple_asn1 = { workspace = true }

rs/ic-canisters/src/governance.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use candid::Decode;
2+
use ic_agent::agent::http_transport::ReqwestTransport;
23
use ic_agent::Agent;
34
use ic_nns_common::pb::v1::NeuronId;
45
use ic_nns_common::pb::v1::ProposalId;
@@ -12,6 +13,7 @@ use ic_nns_governance::pb::v1::ProposalInfo;
1213
use log::warn;
1314
use serde::{self, Serialize};
1415
use std::str::FromStr;
16+
use std::time::Duration;
1517
use url::Url;
1618

1719
use crate::CanisterClient;
@@ -23,10 +25,13 @@ pub struct GovernanceCanisterVersion {
2325
}
2426

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

rs/ic-canisters/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use serde::Deserialize;
1515
use std::path::PathBuf;
1616
use std::str::FromStr;
1717
use std::sync::Mutex;
18+
use std::time::Duration;
1819
use url::Url;
1920

2021
pub mod governance;
@@ -83,13 +84,17 @@ impl IcAgentCanisterClient {
8384
}
8485

8586
fn build_agent(url: Url, identity: Box<dyn Identity>) -> anyhow::Result<Self> {
86-
Ok(Self {
87-
agent: Agent::builder()
88-
.with_identity(identity)
89-
.with_transport(ReqwestTransport::create(url)?)
90-
.with_verify_query_signatures(false)
91-
.build()?,
92-
})
87+
let client = reqwest::Client::builder()
88+
.use_rustls_tls()
89+
.timeout(Duration::from_secs(30))
90+
.build()
91+
.expect("Could not create HTTP client.");
92+
let agent = Agent::builder()
93+
.with_identity(identity)
94+
.with_transport(ReqwestTransport::create_with_client(url, client)?)
95+
.with_verify_query_signatures(false)
96+
.build()?;
97+
Ok(Self { agent })
9398
}
9499
}
95100

rs/ic-management-backend/src/proposal.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use std::time::Duration;
2+
13
use anyhow::Result;
24
use backon::ExponentialBuilder;
35
use backon::Retryable;
46
use candid::{Decode, Encode};
57

68
use futures_util::future::try_join_all;
7-
use ic_agent::agent::http_transport::reqwest_transport::ReqwestHttpReplicaV2Transport;
9+
use ic_agent::agent::http_transport::ReqwestTransport;
810
use ic_agent::Agent;
911
use ic_management_types::UpdateElectedHostosVersionsProposal;
1012
use ic_management_types::UpdateElectedReplicaVersionsProposal;
@@ -85,11 +87,17 @@ pub struct UpdateUnassignedNodesProposal {
8587
#[allow(dead_code)]
8688
impl ProposalAgent {
8789
pub fn new(nns_urls: &[Url]) -> Self {
90+
let client = reqwest::Client::builder()
91+
.use_rustls_tls()
92+
.timeout(Duration::from_secs(30))
93+
.build()
94+
.expect("Could not create HTTP client.");
8895
let agent = Agent::builder()
89-
.with_transport(ReqwestHttpReplicaV2Transport::create(nns_urls[0].clone()).expect("failed to create transport"))
96+
.with_transport(ReqwestTransport::create_with_client(nns_urls[0].clone(), client).expect("Failed to create transport"))
9097
.with_verify_query_signatures(false)
9198
.build()
9299
.expect("failed to build the agent");
100+
93101
Self { agent }
94102
}
95103

rs/ic-observability/obs-canister-clients/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ ic-agent = { workspace = true }
1010
candid = { workspace = true }
1111
serde = { workspace = true }
1212
rand = { workspace = true }
13+
reqwest = { workspace = true }
1314
url = { workspace = true }

rs/ic-observability/obs-canister-clients/src/node_status_canister_client.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::time::Duration;
2+
13
use candid::{CandidType, Decode, Encode};
4+
use ic_agent::agent::http_transport::ReqwestTransport;
25
use ic_agent::{export::Principal, identity::AnonymousIdentity, Agent};
36
use rand::seq::SliceRandom;
47
use serde::Deserialize;
@@ -45,12 +48,17 @@ impl NodeStatusCanister {
4548
agent: url
4649
.iter()
4750
.map(|url| {
51+
let client = reqwest::Client::builder()
52+
.use_rustls_tls()
53+
.timeout(Duration::from_secs(30))
54+
.build()
55+
.expect("Could not create HTTP client.");
4856
Agent::builder()
49-
.with_url(url.as_str())
57+
.with_transport(ReqwestTransport::create_with_client(url.as_str(), client).expect("Failed to create transport"))
5058
.with_identity(AnonymousIdentity)
5159
.with_verify_query_signatures(false)
5260
.build()
53-
.unwrap()
61+
.expect("Failed to build agent")
5462
})
5563
.collect(),
5664
}

0 commit comments

Comments
 (0)