Skip to content

Commit

Permalink
Add custom User-Agent to Hermes queries (informalsystems#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jun 5, 2024
1 parent a026d66 commit 591a920
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Use custom User-Agent for Hermes queries
([\#3979](https://github.com/informalsystems/hermes/issues/3979))
37 changes: 19 additions & 18 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ ibc-test-framework = { version = "0.28.0", path = "tools/test-framework" }
ibc-integration-test = { version = "0.28.0", path = "tools/integration-test" }

# Tendermint dependencies
tendermint = { version = "0.36.0", default-features = false }
tendermint-light-client = { version = "0.36.0", default-features = false }
tendermint-light-client-detector = { version = "0.36.0", default-features = false }
tendermint-light-client-verifier = { version = "0.36.0", default-features = false }
tendermint-proto = { version = "0.36.0" }
tendermint-rpc = { version = "0.36.0" }
tendermint-testgen = { version = "0.36.0" }
tendermint = { version = "0.37.0", default-features = false }
tendermint-light-client = { version = "0.37.0", default-features = false }
tendermint-light-client-detector = { version = "0.37.0", default-features = false }
tendermint-light-client-verifier = { version = "0.37.0", default-features = false }
tendermint-proto = { version = "0.37.0" }
tendermint-rpc = { version = "0.37.0" }
tendermint-testgen = { version = "0.37.0" }

# Other dependencies
abscissa_core = "=0.6.0"
Expand Down Expand Up @@ -72,7 +72,7 @@ hex = "0.4.3"
http = "0.2.9"
humantime = "2.1.0"
humantime-serde = "1.1.1"
ibc-proto = "0.44.0"
ibc-proto = "0.46.0"
ics23 = "0.11.1"
itertools = "0.12.1"
moka = "0.12.5"
Expand Down
1 change: 1 addition & 0 deletions crates/chain-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = """
"""

[dependencies]
ibc-relayer = { workspace = true }
ibc-relayer-types = { workspace = true }
ibc-proto = { workspace = true, features = ["serde"] }
tendermint-rpc = { workspace = true, features = ["http-client", "websocket-client"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/chain-registry/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tendermint_rpc::HttpClientUrl;
use tracing::{debug, info};

use ibc_proto::cosmos::bank::v1beta1::query_client::QueryClient;
use ibc_relayer::HERMES_VERSION;
use tendermint_rpc::{Client, Url};

use crate::error::RegistryError;
Expand Down Expand Up @@ -107,6 +108,7 @@ impl QueryContext for SimpleHermesRpcQuerier {
.map_err(|e| RegistryError::tendermint_url_parse_error(rpc_url.clone(), e))?;

let client = HttpClient::builder(url)
.user_agent(format!("hermes/{}", HERMES_VERSION))
.build()
.map_err(|e| RegistryError::rpc_connect_error(rpc_url.clone(), e))?;

Expand Down
10 changes: 8 additions & 2 deletions crates/relayer-cli/src/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ibc_relayer::{
error::Error,
event::source::EventSource,
util::compat_mode::compat_mode_from_version,
HERMES_VERSION,
};
use ibc_relayer_types::{core::ics24_host::identifier::ChainId, events::IbcEvent};

Expand Down Expand Up @@ -161,7 +162,9 @@ fn subscribe(
interval,
max_retries,
} => {
let mut rpc_client = HttpClient::new(config.rpc_addr.clone())
let mut rpc_client = HttpClient::builder(config.rpc_addr.clone().try_into()?)
.user_agent(format!("hermes/{}", HERMES_VERSION))
.build()
.map_err(|e| Error::rpc(config.rpc_addr.clone(), e))?;
rpc_client.set_compat_mode(compat_mode);

Expand Down Expand Up @@ -191,7 +194,10 @@ fn detect_compatibility_mode(
let rpc_addr = match config {
ChainConfig::CosmosSdk(config) => config.rpc_addr.clone(),
};
let client = HttpClient::new(rpc_addr)?;
let client = HttpClient::builder(rpc_addr.try_into()?)
.user_agent(format!("hermes/{}", HERMES_VERSION))
.build()?;

let status = rt.block_on(client.status())?;
let compat_mode = match config {
ChainConfig::CosmosSdk(config) => {
Expand Down
5 changes: 4 additions & 1 deletion crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ use crate::util::pretty::PrettySlice;
use crate::util::pretty::{
PrettyIdentifiedChannel, PrettyIdentifiedClientState, PrettyIdentifiedConnection,
};
use crate::HERMES_VERSION;

use self::gas::dynamic_gas_price;
use self::types::app_state::GenesisAppState;
Expand Down Expand Up @@ -980,7 +981,9 @@ impl ChainEndpoint for CosmosSdkChain {
return Err(Error::config(ConfigError::wrong_type()));
};

let mut rpc_client = HttpClient::new(config.rpc_addr.clone())
let mut rpc_client = HttpClient::builder(config.rpc_addr.clone().try_into().unwrap())
.user_agent(format!("hermes/{}", HERMES_VERSION))
.build()
.map_err(|e| Error::rpc(config.rpc_addr.clone(), e))?;

let node_info = rt.block_on(fetch_node_info(&rpc_client, &config))?;
Expand Down
2 changes: 2 additions & 0 deletions crates/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ pub mod transfer;
pub mod upgrade_chain;
pub mod util;
pub mod worker;

pub const HERMES_VERSION: &str = "1.9.0";
9 changes: 6 additions & 3 deletions crates/relayer/src/light_client/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use ibc_relayer_types::Height as ICSHeight;

use crate::{
chain::cosmos::config::CosmosSdkConfig,
chain::cosmos::CosmosSdkChain,
chain::cosmos::{config::CosmosSdkConfig, CosmosSdkChain},
client_state::AnyClientState,
error::Error,
misbehaviour::{AnyMisbehaviour, MisbehaviourEvidence},
HERMES_VERSION,
};

use super::{
Expand Down Expand Up @@ -255,7 +255,10 @@ fn io_for_addr(
peer_id: PeerId,
timeout: Option<Duration>,
) -> Result<ProdIo, Error> {
let rpc_client = rpc::HttpClient::new(addr.clone()).map_err(|e| Error::rpc(addr.clone(), e))?;
let rpc_client = rpc::HttpClient::builder(addr.clone().try_into().unwrap())
.user_agent(format!("hermes/{}", HERMES_VERSION))
.build()
.map_err(|e| Error::rpc(addr.clone(), e))?;
Ok(ProdIo::new(peer_id, rpc_client, timeout))
}

Expand Down

0 comments on commit 591a920

Please sign in to comment.