Skip to content

Commit

Permalink
First pass at client filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Dec 13, 2024
1 parent ef4ba24 commit 6057148
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 35 deletions.
39 changes: 26 additions & 13 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ibc_relayer::{
config::{
default,
dynamic_gas::DynamicGasPrice,
filter::{FilterPattern, PacketFilter},
filter::{ClientFilter, FilterPattern, PacketFilter},
gas_multiplier::GasMultiplier,
types::{MaxMsgNum, MaxTxSize, Memo, TrustThreshold},
AddressType, ChainConfig, EventSourceMode, GasPrice,
Expand All @@ -36,34 +36,40 @@ use tracing::{error, trace};

const MAX_HEALTHY_QUERY_RETRIES: u8 = 5;

/// Generate packet filters from Vec<IBCPath> and load them in a Map(chain_name -> filter).
fn construct_packet_filters(ibc_paths: Vec<IBCPath>) -> HashMap<String, PacketFilter> {
let mut packet_filters: HashMap<_, Vec<_>> = HashMap::new();
/// Generate packet and client filters from Vec<IBCPath> and load them in a Map(chain_name -> (packet_filters, client_filters)).
fn construct_filters(ibc_paths: Vec<IBCPath>) -> HashMap<String, (PacketFilter, ClientFilter)> {
let mut filters: HashMap<_, (Vec<_>, Vec<_>)> = HashMap::new();

for path in ibc_paths {
for channel in path.channels {
let chain_1 = path.chain_1.chain_name.to_owned();
let chain_2 = path.chain_2.chain_name.to_owned();

let filters_1 = packet_filters.entry(chain_1).or_default();
let filters_1 = filters.entry(chain_1).or_default();

filters_1.push((
filters_1.0.push((
FilterPattern::Exact(channel.chain_1.port_id.clone()),
FilterPattern::Exact(channel.chain_1.channel_id.clone()),
));
filters_1
.1
.push(FilterPattern::Exact(path.chain_1.client_id.clone()));

let filters_2 = packet_filters.entry(chain_2).or_default();
let filters_2 = filters.entry(chain_2).or_default();

filters_2.push((
filters_2.0.push((
FilterPattern::Exact(channel.chain_2.port_id.clone()),
FilterPattern::Exact(channel.chain_2.channel_id.clone()),
));
filters_2
.1
.push(FilterPattern::Exact(path.chain_2.client_id.clone()));
}
}

packet_filters
filters
.into_iter()
.map(|(k, v)| (k, PacketFilter::allow(v)))
.map(|(k, v)| (k, (PacketFilter::allow(v.0), ClientFilter::allow(v.1))))
.collect()
}

Expand All @@ -72,6 +78,7 @@ async fn hermes_config<GrpcQuerier, RpcQuerier, GrpcFormatter>(
chain_data: ChainData,
assets: AssetList,
packet_filter: Option<PacketFilter>,
client_filter: Option<ClientFilter>,
) -> Result<ChainConfig, RegistryError>
where
GrpcQuerier:
Expand Down Expand Up @@ -171,6 +178,7 @@ where
denom: asset.base.to_owned(),
},
packet_filter: packet_filter.unwrap_or_default(),
client_filter: client_filter.unwrap_or_default(),
address_type: AddressType::default(),
sequential_batch_tx: false,
extension_options: Vec::new(),
Expand Down Expand Up @@ -341,19 +349,24 @@ pub async fn get_configs(
})
.collect();

let mut packet_filters = construct_packet_filters(path_data);
let mut filters = construct_filters(path_data);

// Construct ChainConfig
let config_handles: Vec<_> = chain_data_array
.into_iter()
.zip(asset_lists.into_iter())
.map(|((chain_name, chain_data), (_, assets))| {
let packet_filter = packet_filters.remove(&chain_name);
let (packet_filter, client_filter) = match filters.remove(&chain_name) {
Some(filters) => (Some(filters.0), Some(filters.1)),
None => (None, None),
};
let handle = tokio::spawn(hermes_config::<
GrpcHealthCheckQuerier,
SimpleHermesRpcQuerier,
SimpleGrpcFormatter,
>(chain_data, assets, packet_filter));
>(
chain_data, assets, packet_filter, client_filter
));

(chain_name, handle)
})
Expand Down
4 changes: 4 additions & 0 deletions crates/relayer/src/chain/cosmos/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
compat_mode::CompatMode,
default,
dynamic_gas::DynamicGasPrice,
filter::ClientFilter,
gas_multiplier::GasMultiplier,
types::{MaxMsgNum, MaxTxSize, Memo, TrustThreshold},
AddressType, EventSourceMode, ExtensionOption, GasPrice, GenesisRestart, PacketFilter,
Expand Down Expand Up @@ -144,6 +145,9 @@ pub struct CosmosSdkConfig {
#[serde(default)]
pub packet_filter: PacketFilter,

#[serde(default)]
pub client_filter: ClientFilter,

#[serde(default)]
pub dynamic_gas_price: DynamicGasPrice,

Expand Down
7 changes: 5 additions & 2 deletions crates/relayer/src/chain/penumbra/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde_derive::{Deserialize, Serialize};
use tendermint_rpc::Url;

use crate::config::{
compat_mode::CompatMode, default, types::TrustThreshold, EventSourceMode, GenesisRestart,
PacketFilter, RefreshRate,
compat_mode::CompatMode, default, filter::ClientFilter, types::TrustThreshold, EventSourceMode,
GenesisRestart, PacketFilter, RefreshRate,
};

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
Expand Down Expand Up @@ -42,6 +42,9 @@ pub struct PenumbraConfig {
/// Controls which packets will be relayed.
#[serde(default)]
pub packet_filter: PacketFilter,
/// Controls which connections will be scanned.
#[serde(default)]
pub client_filter: ClientFilter,
pub clear_interval: Option<u64>,
/// How many packets to fetch at once from the chain when clearing packets
#[serde(default = "default::query_packets_chunk_size")]
Expand Down
14 changes: 13 additions & 1 deletion crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use core::{
str::FromStr,
time::Duration,
};
use filter::ClientFilter;
use std::{
borrow::Cow,
fs::{self, File},
Expand All @@ -42,7 +43,10 @@ use tendermint_rpc::{Url, WebSocketClientUrl};

pub use crate::config::Error as ConfigError;
use crate::{
chain::{cosmos::config::CosmosSdkConfig, penumbra::config::PenumbraConfig},
chain::{
cosmos::config::{self, CosmosSdkConfig},

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (ibc-go-v8-simapp, simd, cosmos, stake, ica,ics29-fee)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (ibc-go-v7-simapp, simd, cosmos, stake, ica,ics29-fee)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (ibc-go-v6-simapp, simd, cosmos, stake, ica,ics29-fee)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-ica (.#gaia13 .#stride-consumer, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-ica (.#gaia13 .#stride-consumer, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-ica (.#gaia14 .#stride-consumer, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-ica (.#gaia14 .#stride-consumer, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-icq (.#gaia13 .#stride-consumer-no-admin, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-icq (.#gaia13 .#stride-consumer-no-admin, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-icq (.#gaia14 .#stride-consumer-no-admin, gaiad,strided, cosmos,stride)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-icq (.#gaia14 .#stride-consumer-no-admin, gaiad,strided, cosmos,stride)

unused import: `self`

Check failure on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / test-stable

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / model-based-test (gaia6)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / light-client-attack (gaia14, gaiad, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / light-client-attack (gaia14, gaiad, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-no-ica (.#gaia13 .#neutron, gaiad,neutrond, cosmos,neutron)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-no-ica (.#gaia13 .#neutron, gaiad,neutrond, cosmos,neutron)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-no-ica (.#gaia14 .#neutron, gaiad,neutrond, cosmos,neutron)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / interchain-security-no-ica (.#gaia14 .#neutron, gaiad,neutrond, cosmos,neutron)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / template-checker

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / template-checker

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-double-sign (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-double-sign (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-light-client-attack-freeze (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-light-client-attack-freeze (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-light-client-attack (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ics-light-client-attack (interchain-security, cosmos)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ordered-channel-test

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / ordered-channel-test

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / celestia-to-gaia (.#celestia .#gaia14, celestia-appd,gaiad, celestia,cosmos, utia,stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / celestia-to-gaia (.#celestia .#gaia14, celestia-appd,gaiad, celestia,cosmos, utia,stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / celestia-to-gaia (.#celestia .#gaia13, celestia-appd,gaiad, celestia,cosmos, utia,stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / celestia-to-gaia (.#celestia .#gaia13, celestia-appd,gaiad, celestia,cosmos, utia,stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (migaloo, migalood, migaloo, stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (migaloo, migalood, migaloo, stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (wasmd, wasmd, wasm, stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (wasmd, wasmd, wasm, stake)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (osmosis, osmosisd, osmo, stake, dynamic-gas-fee)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (osmosis, osmosisd, osmo, stake, dynamic-gas-fee)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (provenance, provenanced, pb, nhash, fee-grant,async-icq)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (provenance, provenanced, pb, nhash, fee-grant,async-icq)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (gaia13, gaiad, cosmos, stake, forward-packet,clean-workers)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (gaia13, gaiad, cosmos, stake, forward-packet,clean-workers)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (gaia14, gaiad, cosmos, stake, forward-packet,clean-workers)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (gaia14, gaiad, cosmos, stake, forward-packet,clean-workers)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (injective, injectived, inj, stake, forward-packet,fee-grant)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (injective, injectived, inj, stake, forward-packet,fee-grant)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (juno, junod, juno, stake, juno,forward-packet)

unused import: `self`

Check warning on line 47 in crates/relayer/src/config.rs

View workflow job for this annotation

GitHub Actions / integration-test (juno, junod, juno, stake, juno,forward-packet)

unused import: `self`
penumbra::config::PenumbraConfig,
},
config::types::{ics20_field_size_limit::Ics20FieldSizeLimit, TrustThreshold},
error::Error as RelayerError,
extension_options::ExtensionOptionDynamicFeeTx,
Expand Down Expand Up @@ -677,6 +681,14 @@ impl ChainConfig {
}
}

pub fn client_filter(&self) -> &ClientFilter {
match self {
Self::CosmosSdk(config) => &config.client_filter,
Self::Astria(config) => &config.client_filter,
Self::Penumbra(config) => &config.client_filter,
}
}

pub fn packet_filter(&self) -> &PacketFilter {
match self {
Self::CosmosSdk(config) => &config.packet_filter,
Expand Down
Loading

0 comments on commit 6057148

Please sign in to comment.