Skip to content

Commit

Permalink
add NamadaChain
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Nov 21, 2023
1 parent 6895054 commit e35931e
Show file tree
Hide file tree
Showing 22 changed files with 6,540 additions and 1,140 deletions.
5,871 changes: 4,748 additions & 1,123 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crates/relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ pub fn add_key(
keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be added"));
}
};

Ok(key_pair)
Expand Down Expand Up @@ -256,6 +259,9 @@ pub fn restore_key(
keyring.add_key(key_name, key_pair.clone())?;
key_pair.into()
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be restored"));
}
};

Ok(key_pair)
Expand Down
8 changes: 6 additions & 2 deletions crates/relayer-cli/src/commands/keys/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ fn get_balance(chain: impl ChainHandle, key_name: Option<String>, denom: Option<
let key_name = key_name.unwrap_or_else(|| {
let chain_config = chain.config().unwrap_or_else(exit_with_unrecoverable_error);
match chain_config {
ChainConfig::CosmosSdk(chain_config) => chain_config.key_name,
ChainConfig::CosmosSdk(chain_config) | ChainConfig::Namada(chain_config) => {
chain_config.key_name
}
}
});

Expand All @@ -99,7 +101,9 @@ fn get_balances(chain: impl ChainHandle, key_name: Option<String>) {
let key_name = key_name.unwrap_or_else(|| {
let chain_config = chain.config().unwrap_or_else(exit_with_unrecoverable_error);
match chain_config {
ChainConfig::CosmosSdk(chain_config) => chain_config.key_name,
ChainConfig::CosmosSdk(chain_config) | ChainConfig::Namada(chain_config) => {
chain_config.key_name
}
}
});

Expand Down
6 changes: 6 additions & 0 deletions crates/relayer-cli/src/commands/keys/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ pub fn delete_key(config: &ChainConfig, key_name: &str) -> eyre::Result<()> {
)?;
keyring.remove_key(key_name)?;
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be deleted"));
}
}
Ok(())
}
Expand All @@ -141,6 +144,9 @@ pub fn delete_all_keys(config: &ChainConfig) -> eyre::Result<()> {
keyring.remove_key(&key_name)?;
}
}
ChainConfig::Namada(_) => {
return Err(eyre!("Namada key cannot be deleted"));
}
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer-cli/src/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn subscribe(
// Q: Should this be restricted only to backends that support it,
// or are all backends expected to support subscriptions?
match chain_config {
ChainConfig::CosmosSdk(config) => {
ChainConfig::CosmosSdk(config) | ChainConfig::Namada(config) => {
let (event_source, monitor_tx) = match &config.event_source {
EventSourceMode::Push { url, batch_delay } => EventSource::websocket(
chain_config.id().clone(),
Expand Down Expand Up @@ -178,12 +178,12 @@ fn detect_compatibility_mode(
) -> eyre::Result<CompatMode> {
// TODO(erwan): move this to the cosmos sdk endpoint implementation
let rpc_addr = match config {
ChainConfig::CosmosSdk(config) => config.rpc_addr.clone(),
ChainConfig::CosmosSdk(config) | ChainConfig::Namada(config) => config.rpc_addr.clone(),
};
let client = HttpClient::new(rpc_addr)?;
let status = rt.block_on(client.status())?;
let compat_mode = match config {
ChainConfig::CosmosSdk(config) => {
ChainConfig::CosmosSdk(config) | ChainConfig::Namada(config) => {
compat_mode_from_version(&config.compat_mode, status.node_info.version)?.into()
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Runnable for TxUpdateClientCmd {
if let Some(restart_params) = self.genesis_restart_params() {
match config.find_chain_mut(&reference_chain_id) {
Some(chain_config) => match chain_config {
ChainConfig::CosmosSdk(chain_config) => {
ChainConfig::CosmosSdk(chain_config) | ChainConfig::Namada(chain_config) => {
chain_config.genesis_restart = Some(restart_params)
}
},
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-types/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl FromStr for IbcEventType {
}

/// Events created by the IBC component of a chain, destined for a relayer.
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, PartialEq)]
pub enum IbcEvent {
NewBlock(NewBlock),

Expand Down
3 changes: 3 additions & 0 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ ibc-proto = { version = "0.39.0", features = ["serde"] }
ibc-telemetry = { version = "0.26.1", path = "../telemetry", optional = true }
ibc-relayer-types = { version = "0.26.1", path = "../relayer-types", features = ["mocks"] }

namada = { git = "https://github.com/anoma/namada", rev = "63f2e4be022ded03ce0639f4a2a20945c3719080" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "63f2e4be022ded03ce0639f4a2a20945c3719080", features = ["std", "async-client"] }

subtle-encoding = "0.5"
humantime-serde = "1.1.1"
serde = "1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod cosmos;
pub mod counterparty;
pub mod endpoint;
pub mod handle;
pub mod namada;
pub mod requests;
pub mod runtime;
pub mod tracking;
7 changes: 5 additions & 2 deletions crates/relayer/src/chain/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ impl ClientSettings {
//
// TODO: extract Tendermint-related configs into a separate substructure
// that can be used both by CosmosSdkConfig and configs for nonSDK chains.
use ChainConfig::CosmosSdk as Csdk;
use ChainConfig::{CosmosSdk as Csdk, Namada};
match (src_chain_config, dst_chain_config) {
(Csdk(src_chain_config), Csdk(dst_chain_config)) => {
(Csdk(src_chain_config), Csdk(dst_chain_config))
| (Namada(src_chain_config), Namada(dst_chain_config))
| (Csdk(src_chain_config), Namada(dst_chain_config))
| (Namada(src_chain_config), Csdk(dst_chain_config)) => {
ClientSettings::Tendermint(cosmos::client::Settings::for_create_command(
options,
src_chain_config,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/cosmos/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl CosmosSdkConfig {
/// a) non-zero
/// b) greater or equal to 1/3
/// c) strictly less than 1
fn validate_trust_threshold(
pub fn validate_trust_threshold(
id: &ChainId,
trust_threshold: TrustThreshold,
) -> Result<(), Diagnostic<ConfigError>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/cosmos/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async fn update_tx_sync_result(
Ok(())
}

fn all_tx_results_found(tx_sync_results: &[TxSyncResult]) -> bool {
pub fn all_tx_results_found(tx_sync_results: &[TxSyncResult]) -> bool {
tx_sync_results
.iter()
.all(|r| matches!(r.status, TxStatus::ReceivedResponse))
Expand Down
Loading

0 comments on commit e35931e

Please sign in to comment.