From f2970ee6bc63bae688a04e287fd7a15965c74f04 Mon Sep 17 00:00:00 2001 From: "rust.dev" <102041955+RustNinja@users.noreply.github.com> Date: Sat, 16 Sep 2023 00:10:19 +0100 Subject: [PATCH] Relayer skip tokens depends on config value: skip_tokens_list (#409) --- Cargo.lock | 1 + hyperspace/core/Cargo.toml | 1 + hyperspace/core/src/packets.rs | 15 +++++++++++++++ hyperspace/cosmos/src/client.rs | 3 +++ hyperspace/primitives/src/lib.rs | 3 +++ hyperspace/testsuite/tests/parachain_cosmos.rs | 1 + 6 files changed, 24 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7deb9c930..1f1982e6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4364,6 +4364,7 @@ dependencies = [ "scale-decode", "scale-encode", "serde", + "serde_json", "sp-beefy", "sp-core 7.0.0", "sp-keyring", diff --git a/hyperspace/core/Cargo.toml b/hyperspace/core/Cargo.toml index 252e6f749..f78a74c0f 100644 --- a/hyperspace/core/Cargo.toml +++ b/hyperspace/core/Cargo.toml @@ -60,6 +60,7 @@ subxt-generated = { path = "../../utils/subxt/generated" } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } prost = { version = "0.11", default-features = false } +serde_json = "1.0.74" [dev-dependencies] derive_more = "0.99.17" diff --git a/hyperspace/core/src/packets.rs b/hyperspace/core/src/packets.rs index 0b3d745cd..daa46714d 100644 --- a/hyperspace/core/src/packets.rs +++ b/hyperspace/core/src/packets.rs @@ -30,6 +30,7 @@ use crate::packets::utils::{ get_timeout_proof_height, verify_delay_passed, VerifyDelayOn, }; use ibc::{ + applications::transfer::packet::PacketData, core::{ ics02_client::client_state::ClientState as ClientStateT, ics03_connection::connection::ConnectionEnd, @@ -348,6 +349,20 @@ pub async fn query_ready_and_timed_out_packets( return Ok(None) } + let list = &source.common_state().skip_tokens_list; + + let decoded_dara: PacketData = serde_json::from_str(&String::from_utf8_lossy(packet.data.as_ref())).map_err(|e| { + Error::Custom(format!( + "Failed to decode packet data for packet {:?}: {:?}", + packet, e + )) + })?; + + if list.iter().any(|skiped_denom| decoded_dara.token.denom.base_denom.as_str() == skiped_denom) { + log::info!(target: "hyperspace", "Skipping packet as uosmo packet: {:?}", packet); + return Ok(None) + } + let msg = construct_recv_message(&**source, &**sink, packet, proof_height).await?; Ok(Some(Right(msg))) }); diff --git a/hyperspace/cosmos/src/client.rs b/hyperspace/cosmos/src/client.rs index acd2f67bb..a42818c5f 100644 --- a/hyperspace/cosmos/src/client.rs +++ b/hyperspace/cosmos/src/client.rs @@ -240,6 +240,8 @@ pub struct CosmosClientConfig { /// Common client config #[serde(flatten)] pub common: CommonClientConfig, + /// List of tokens to skip uosmo etc + pub skip_tokens_list: Option>, } impl CosmosClient @@ -304,6 +306,7 @@ where initial_rpc_call_delay: rpc_call_delay, misbehaviour_client_msg_queue: Arc::new(AsyncMutex::new(vec![])), max_packets_to_process: config.common.max_packets_to_process as usize, + skip_tokens_list: config.skip_tokens_list.unwrap_or_default(), }, join_handles: Arc::new(TokioMutex::new(vec![ws_driver_jh])), }) diff --git a/hyperspace/primitives/src/lib.rs b/hyperspace/primitives/src/lib.rs index 3d80e5f18..ce02acd65 100644 --- a/hyperspace/primitives/src/lib.rs +++ b/hyperspace/primitives/src/lib.rs @@ -132,6 +132,8 @@ pub struct CommonClientState { pub initial_rpc_call_delay: Duration, pub misbehaviour_client_msg_queue: Arc>>, pub max_packets_to_process: usize, + + pub skip_tokens_list: Vec, } impl Default for CommonClientState { @@ -144,6 +146,7 @@ impl Default for CommonClientState { initial_rpc_call_delay: rpc_call_delay, misbehaviour_client_msg_queue: Arc::new(Default::default()), max_packets_to_process: 100, + skip_tokens_list: vec![], } } } diff --git a/hyperspace/testsuite/tests/parachain_cosmos.rs b/hyperspace/testsuite/tests/parachain_cosmos.rs index 398e00194..204e0d143 100644 --- a/hyperspace/testsuite/tests/parachain_cosmos.rs +++ b/hyperspace/testsuite/tests/parachain_cosmos.rs @@ -112,6 +112,7 @@ async fn setup_clients() -> (AnyChain, AnyChain) { skip_optional_client_updates: true, max_packets_to_process: 200, }, + skip_tokens_list: vec![], }; let chain_b = CosmosClient::::new(config_b.clone()).await.unwrap();