Skip to content

Commit

Permalink
Remove ibc-relayer dependency (#499)
Browse files Browse the repository at this point in the history
* Add packet clearing and no packet clearing tests

* Update tracing subscriber initialisation to avoid crashing in tests

* Remove unnecessary generic Setup in init_preset_bootstraps

* Migrate packet timeout test

* Add packet filtering test

* Add test for acknowledgment relaying and fix acknowledgment relaying for cosmos chains

* Cleanup comments

* Remove tools crate and anything related to legacy tests

* Extract Keyring from Hermes v1 and remove ibc-relayer and ibc-relayer-telemetry dependencies
  • Loading branch information
ljoss17 authored Dec 16, 2024
1 parent 4cbb56f commit a0e6b3e
Show file tree
Hide file tree
Showing 58 changed files with 820 additions and 854 deletions.
580 changes: 30 additions & 550 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,41 @@ async-trait = { version = "0.1.83" }
ibc = { version = "0.56.0", default-features = false }
ibc-client-tendermint = { version = "0.56.0", default-features = false }
ibc-proto = { version = "0.51.1", default-features = false }
ibc-relayer = { version = "0.29.3" }
ibc-telemetry = { version = "0.29.3" }
tendermint = { version = "0.40" }
tendermint-proto = { version = "0.40" }
tendermint-rpc = { version = "0.40" }
tendermint-testgen = { version = "0.40" }
tendermint-light-client-verifier = { version = "0.40" }
tendermint-light-client = { version = "0.40" }
basecoin = { version = "0.2.0" }
bitcoin = { version = "0.31.2" }
cgp = { version = "0.2.0", default-features = false }
clap = { version = "4.5.20" }
dirs-next = { version = "2.0.0" }
num-bigint = { version = "0.4" }
num-rational = { version = "0.4.1" }
oneline-eyre = { version = "0.1.0" }
prost = { version = "0.13.3" }
prost-types = { version = "0.13.3" }
reqwest = { version = "0.12.9", features = ["json"] }
serde = { version = "1.0.210" }
serde_derive = { version = "1.0" }
ripemd = { version = "0.1.3" }
serde = { version = "1.0.214" }
serde_derive = { version = "1.0.104" }
serde_json = { version = "1.0" }
subtle-encoding = { version = "0.5.1" }
tiny-bip39 = { version = "1.0.0" }
tokio = { version = "1.40" }
tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.18" }
time = { version = "0.3.36" }
tonic = { version = "0.12" }
toml = { version = "0.8.15" }
digest = { version = "0.10.6" }
futures = { version = "0.3.30", default-features = false }
futures-core = { version = "0.3.30", default-features = false }
futures-util = { version = "0.3.30", default-features = false }
futures-channel = { version = "0.3.31", default-features = false }
generic-array = { version = "0.14.7" }
eyre = { version = "0.6.12" }
itertools = { version = "0.13" }
http = { version = "1.0.0" }
Expand All @@ -116,7 +121,7 @@ hdpath = { version = "0.6.3" }
rand = { version = "0.8.5" }
bech32 = { version = "0.9.1" }
sha2 = { version = "0.10.8" }
secp256k1 = { version = "0.27.0", features = ["rand", "bitcoin_hashes"] }
secp256k1 = { version = "0.28.2" }
ics23 = { version = "0.12" }

hermes-runtime-components = { version = "0.1.0" }
Expand Down Expand Up @@ -188,9 +193,6 @@ hermes-ibc-mock-chain = { version = "0.1.0" }
# cgp-run = { git = "https://github.com/contextgeneric/cgp.git" }
# cgp-inner = { git = "https://github.com/contextgeneric/cgp.git" }

ibc-relayer = { git = "https://github.com/informalsystems/hermes.git" }
ibc-telemetry = { git = "https://github.com/informalsystems/hermes.git" }

hermes-chain-components = { path = "./crates/chain/chain-components" }
hermes-chain-type-components = { path = "./crates/chain/chain-type-components" }

Expand Down
6 changes: 6 additions & 0 deletions crates/any/any-counterparty/src/impls/types/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ where
AnyClientState::Tendermint(cs) => cs.trusting_period < elapsed,
}
}

fn client_state_chain_id(client_state: &AnyClientState) -> ChainId {
match client_state {
AnyClientState::Tendermint(cs) => cs.chain_id.clone(),
}
}
}
1 change: 0 additions & 1 deletion crates/celestia/celestia-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ hermes-cosmos-integration-tests = { workspace = true }
hermes-celestia-test-components = { workspace = true }

ibc = { workspace = true }
ibc-relayer = { workspace = true }

eyre = { workspace = true }
tokio = { workspace = true }
Expand Down
11 changes: 9 additions & 2 deletions crates/chain/chain-components/src/traits/types/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::time::Duration;

use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::chain_id::HasChainIdType;
pub use hermes_chain_type_components::traits::types::ibc::client_state::*;

use crate::traits::types::height::HasHeightType;
Expand All @@ -21,7 +22,7 @@ pub trait HasRawClientStateType: Async {
context: Chain,
}]
pub trait HasClientStateFields<Counterparty>:
HasHeightType + HasClientStateType<Counterparty>
HasHeightType + HasChainIdType + HasClientStateType<Counterparty>
{
/// The latest height of the client
fn client_state_latest_height(client_state: &Self::ClientState) -> Self::Height;
Expand All @@ -32,12 +33,14 @@ pub trait HasClientStateFields<Counterparty>:
/// Check if the client state will expired when `elapsed` time has passed
/// since the latest consensus state
fn client_state_has_expired(client_state: &Self::ClientState, elapsed: Duration) -> bool;

fn client_state_chain_id(client_state: &Self::ClientState) -> Self::ChainId;
}

impl<Chain, Counterparty, Components, Delegate> ClientStateFieldsGetter<Chain, Counterparty>
for UseDelegate<Components>
where
Chain: HasHeightType + HasClientStateType<Counterparty>,
Chain: HasHeightType + HasChainIdType + HasClientStateType<Counterparty>,
Components: DelegateComponent<Counterparty, Delegate = Delegate>,
Delegate: ClientStateFieldsGetter<Chain, Counterparty>,
{
Expand All @@ -52,4 +55,8 @@ where
fn client_state_has_expired(client_state: &Chain::ClientState, elapsed: Duration) -> bool {
Delegate::client_state_has_expired(client_state, elapsed)
}

fn client_state_chain_id(client_state: &Chain::ClientState) -> Chain::ChainId {
Delegate::client_state_chain_id(client_state)
}
}
1 change: 0 additions & 1 deletion crates/cli/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ hermes-encoding-components = { workspace = true }
hermes-protobuf-encoding-components = { workspace = true }

ibc = { workspace = true }
ibc-relayer = { workspace = true }

clap = { workspace = true, features = ["derive"] }
dirs-next = { workspace = true }
Expand Down
49 changes: 24 additions & 25 deletions crates/cli/cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig;
use hermes_cosmos_chain_components::types::key_types::keyring::KeyRing;
use hermes_cosmos_chain_components::types::key_types::secp256k1::Secp256k1KeyPair;
use ibc::core::host::types::identifiers::ChainId;
use ibc_relayer::keyring::{
AnySigningKeyPair, KeyRing, Secp256k1KeyPair, SigningKeyPair, SigningKeyPairSized, Store,
};
use oneline_eyre::eyre;
use oneline_eyre::eyre::{eyre, WrapErr};
use tracing::warn;
Expand Down Expand Up @@ -124,22 +123,24 @@ pub fn add_key(
file: &Path,
hd_path: &StandardHDPath,
overwrite: bool,
) -> eyre::Result<AnySigningKeyPair> {
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
) -> eyre::Result<Secp256k1KeyPair> {
let keyring = KeyRing::new_secp256k1(
&config.account_prefix,
&ChainId::new(&config.id)?.to_string().into(),
&ChainId::new(&config.id)?,
&config.key_store_folder,
)?;
);

check_key_exists(&keyring, key_name, overwrite);

let key_contents = fs::read_to_string(file).wrap_err("error reading the key file")?;
let key_pair = Secp256k1KeyPair::from_seed_file(&key_contents, hd_path)?;
let key_pair =
Secp256k1KeyPair::from_seed_file(&key_contents, hd_path).map_err(|e| eyre!("{e}"))?;

keyring.add_key(key_name, key_pair.clone())?;
keyring
.add_key(key_name, key_pair.clone())
.map_err(|e| eyre!("{e}"))?;

Ok(key_pair.into())
Ok(key_pair)
}

pub fn restore_key(
Expand All @@ -148,35 +149,33 @@ pub fn restore_key(
hdpath: &StandardHDPath,
config: &CosmosChainConfig,
overwrite: bool,
) -> eyre::Result<AnySigningKeyPair> {
) -> eyre::Result<Secp256k1KeyPair> {
let mnemonic_content =
fs::read_to_string(mnemonic).wrap_err("error reading the mnemonic file")?;

let mut keyring = KeyRing::new_secp256k1(
Store::Test,
let keyring = KeyRing::new_secp256k1(
&config.account_prefix,
&ChainId::new(&config.id)?.to_string().into(),
&ChainId::new(&config.id)?,
&config.key_store_folder,
)?;
);

check_key_exists(&keyring, key_name, overwrite);

let key_pair = Secp256k1KeyPair::from_mnemonic(
&mnemonic_content,
hdpath,
&ibc_relayer::config::AddressType::Cosmos,
keyring.account_prefix(),
)?;
let key_pair =
Secp256k1KeyPair::from_mnemonic(&mnemonic_content, hdpath, keyring.account_prefix())
.map_err(|e| eyre!("{e}"))?;

keyring.add_key(key_name, key_pair.clone())?;
keyring
.add_key(key_name, key_pair.clone())
.map_err(|e| eyre!("{e}"))?;

Ok(key_pair.into())
Ok(key_pair)
}

/// Check if the key with the given key name already exists.
/// If it already exists and overwrite is false, abort the command with an error.
/// If overwrite is true, output a warning message informing the key will be overwritten.
fn check_key_exists<S: SigningKeyPairSized>(keyring: &KeyRing<S>, key_name: &str, overwrite: bool) {
fn check_key_exists(keyring: &KeyRing, key_name: &str, overwrite: bool) {
if keyring.get_key(key_name).is_ok() {
if overwrite {
warn!("key {} will be overwritten", key_name);
Expand Down
20 changes: 8 additions & 12 deletions crates/cli/cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig;
use hermes_cosmos_chain_components::types::key_types::keyring::KeyRing;
use ibc::core::host::types::identifiers::ChainId;
use ibc_relayer::keyring::{KeyRing, Store};
use oneline_eyre::eyre::{eyre, Context};
use oneline_eyre::eyre::eyre;
use tracing::warn;

use crate::contexts::app::HermesApp;
Expand Down Expand Up @@ -120,28 +120,24 @@ impl CommandRunner<HermesApp> for KeysDeleteCmd {

fn delete_key(config: &CosmosChainConfig, key_name: &str) -> eyre::Result<()> {
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&ChainId::new(&config.id)?.to_string().into(),
&ChainId::new(&config.id)?,
&config.key_store_folder,
)?;
);

keyring.remove_key(key_name)?;
keyring.remove_key(key_name).map_err(|e| eyre!("{e}"))?;

Ok(())
}

fn delete_all_keys(config: &CosmosChainConfig) -> eyre::Result<()> {
let mut keyring = KeyRing::new_secp256k1(
Store::Test,
&config.account_prefix,
&ChainId::new(&config.id)?.to_string().into(),
&ChainId::new(&config.id)?,
&config.key_store_folder,
)?;
);

let keys = keyring
.keys()
.wrap_err("failed to fetch keys from keyring")?;
let keys = keyring.keys().map_err(|e| eyre!("{e}"))?;

for (key_name, _) in keys {
if let Err(e) = keyring.remove_key(&key_name) {
Expand Down
15 changes: 9 additions & 6 deletions crates/cli/cli/src/commands/keys/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::collections::BTreeMap;
use hermes_cli_components::traits::build::CanLoadBuilder;
use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::{json, Output};
use hermes_cosmos_chain_components::types::key_types::keyring::KeyRing;
use ibc::core::host::types::identifiers::ChainId;
use ibc_relayer::keyring::{KeyRing, SigningKeyPair, Store};
use oneline_eyre::eyre::eyre;

use crate::contexts::app::HermesApp;
Expand All @@ -32,18 +32,21 @@ impl CommandRunner<HermesApp> for KeysListCmd {
.ok_or_else(|| eyre!("chain `{}` not found in configuration file", self.chain_id))?;

let keyring = KeyRing::new_secp256k1(
Store::Test,
&chain_config.account_prefix,
&ChainId::new(&chain_config.id)?.to_string().into(),
&ChainId::new(&chain_config.id)?,
&chain_config.key_store_folder,
)?;
);

if json() {
let keys = keyring.keys()?.into_iter().collect::<BTreeMap<_, _>>();
let keys = keyring
.keys()
.map_err(|e| eyre!("{e}"))?
.into_iter()
.collect::<BTreeMap<_, _>>();
Output::success(keys).exit()
} else {
let mut msg = String::new();
for (name, key) in keyring.keys()? {
for (name, key) in keyring.keys().map_err(|e| eyre!("{e}"))? {
let _ = write!(msg, "\n- {} ({})", name, key.account());
}
Output::success_msg(msg).exit()
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/cli/src/commands/query/channel/ends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl CommandRunner<HermesApp> for QueryChannelEnds {
// channel end query path
let channel_end_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}");

let channel_end_bytes = chain
let channel_end_bytes: Vec<u8> = chain
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), &query_height)
.await?;

Expand Down
30 changes: 28 additions & 2 deletions crates/cli/cli/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::fs::File;
use std::io::Read;
use std::ops::Deref;
use std::path::Path;

use hermes_cli_framework::config::Config;
use ibc_relayer::config::{load as load_config, Config as RelayerConfig};
use hermes_cosmos_chain_components::impls::types::config::RelayerConfig;

pub struct HermesConfig {
pub config: RelayerConfig,
Expand All @@ -19,7 +22,30 @@ impl Config for HermesConfig {
fn load_from_path(
path: impl AsRef<std::path::Path>,
) -> Result<Self, Box<dyn std::error::Error>> {
let config = load_config(path)?;
let config = load_config(&path)?;
Ok(Self { config })
}
}

fn load_config(path: &impl AsRef<std::path::Path>) -> Result<RelayerConfig, String> {
let canonical_path = path
.as_ref()
.canonicalize()
.map_err(|e| format!("failed to canonicalize config path. Cause: {e}"))?;
load_toml_file(canonical_path.as_path())
}

fn load_toml_file(path: &Path) -> Result<RelayerConfig, String> {
let mut file =
File::open(path).map_err(|e| format!("failed to open config file. Cause: {e}"))?;

let mut toml_string = String::new();
file.read_to_string(&mut toml_string)
.map_err(|e| format!("failed to read toml file from string. Cause: {e}"))?;
load_toml(toml_string)
}

fn load_toml(toml_string: String) -> Result<RelayerConfig, String> {
toml::from_str(toml_string.as_ref())
.map_err(|e| format!("failed to convert String to toml. Cause: {e}"))
}
4 changes: 2 additions & 2 deletions crates/cli/cli/src/contexts/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use hermes_cli_components::traits::output::{
use hermes_cli_components::traits::parse::ArgParserComponent;
use hermes_cli_components::traits::types::config::ConfigTypeComponent;
use hermes_cli_framework::output::Output;
use hermes_cosmos_chain_components::impls::types::config::RelayerConfig;
use hermes_cosmos_chain_components::types::payloads::client::CosmosCreateClientOptions;
use hermes_cosmos_integration_tests::contexts::bootstrap::CosmosBootstrap;
use hermes_cosmos_relayer::contexts::build::CosmosBuilder;
Expand All @@ -65,7 +66,6 @@ use hermes_runtime::types::runtime::HermesRuntime;
use hermes_runtime_components::traits::runtime::{RuntimeGetterComponent, RuntimeTypeComponent};
use ibc::core::client::types::Height;
use ibc::core::host::types::identifiers::{ChainId, ClientId, ConnectionId};
use ibc_relayer::config::Config;
use serde::Serialize;

use crate::commands::bootstrap::chain::{BootstrapChainArgs, LoadCosmosBootstrap};
Expand Down Expand Up @@ -107,7 +107,7 @@ delegate_components! {
]:
ProvideHermesLogger,
ConfigTypeComponent:
WithType<Config>,
WithType<RelayerConfig>,
BootstrapTypeComponent:
WithType<CosmosBootstrap>,
BuilderTypeComponent:
Expand Down
Loading

0 comments on commit a0e6b3e

Please sign in to comment.