Skip to content

Commit

Permalink
Relayer skip tokens depends on config value: skip_tokens_list (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja authored Sep 15, 2023
1 parent 7a48716 commit f2970ee
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions hyperspace/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions hyperspace/core/src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
});
Expand Down
3 changes: 3 additions & 0 deletions hyperspace/cosmos/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
}

impl<H> CosmosClient<H>
Expand Down Expand Up @@ -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])),
})
Expand Down
3 changes: 3 additions & 0 deletions hyperspace/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub struct CommonClientState {
pub initial_rpc_call_delay: Duration,
pub misbehaviour_client_msg_queue: Arc<AsyncMutex<Vec<AnyClientMessage>>>,
pub max_packets_to_process: usize,

pub skip_tokens_list: Vec<String>,
}

impl Default for CommonClientState {
Expand All @@ -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![],
}
}
}
Expand Down
1 change: 1 addition & 0 deletions hyperspace/testsuite/tests/parachain_cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DefaultConfig>::new(config_b.clone()).await.unwrap();
Expand Down

0 comments on commit f2970ee

Please sign in to comment.