Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add near event filter #445

Open
wants to merge 1 commit into
base: v1.7.0-octopus
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ where
canister_id: CanisterIdConfig::default(),
canister_pem: PathBuf::new(),
near_ibc_address: ibc_relayer::config::NearIbcContractAddress::default(),
filter_near_event_height: None,
r#type: default::chain_type(),
rpc_addr: rpc_data.rpc_address,
grpc_addr: grpc_address,
Expand Down
3 changes: 3 additions & 0 deletions crates/relayer/src/chain/near/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ impl NearChain {
info!("initializing event monitor");
crate::time!("init_event_monitor");

let filter_near_event_height = self.config.filter_near_event_height;

let (event_monitor, monitor_tx) = NearEventMonitor::new(
self.config.id.clone(),
self.config.near_ibc_address.clone().into(),
self.config.rpc_addr.to_string(),
self.rt.clone(),
filter_near_event_height,
)
.map_err(Error::event_monitor)?;

Expand Down
3 changes: 3 additions & 0 deletions crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ pub struct ChainConfig {
#[serde(default = "default::near_ibc_contract_address")]
pub near_ibc_address: NearIbcContractAddress,

/// Filter near event Height
pub filter_near_event_height: Option<u64>,

/// The chain type
#[serde(default = "default::chain_type")]
pub r#type: ChainType,
Expand Down
29 changes: 23 additions & 6 deletions crates/relayer/src/event/near_event_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct NearEventMonitor {
/// The heights that have already been checked for IBC events.
checked_heights: Vec<u64>,
last_block_height: u64,
pub filter_near_event_height: Option<u64>,
}

impl NearIbcContract for NearEventMonitor {
Expand Down Expand Up @@ -108,6 +109,7 @@ impl NearEventMonitor {
near_ibc_address: AccountId,
rpc_addr: String,
rt: Arc<TokioRuntime>,
filter_near_event_height: Option<u64>,
) -> Result<(Self, TxMonitorCmd)> {
let (tx_cmd, rx_cmd) = channel::unbounded();

Expand All @@ -122,6 +124,7 @@ impl NearEventMonitor {
rx_cmd,
checked_heights: vec![],
last_block_height: 0,
filter_near_event_height,
};

Ok((monitor, TxMonitorCmd(tx_cmd)))
Expand Down Expand Up @@ -190,12 +193,26 @@ impl NearEventMonitor {
return Next::Continue;
}
}
let heights = self.get_ibc_events_heights();
let unchecked_heights = heights
.iter()
.map(|h| h.revision_height())
.filter(|h| !self.checked_heights.contains(h))
.collect::<Vec<u64>>();
let unchecked_heights = if let Some(value) = self.filter_near_event_height {
let heights = self.get_ibc_events_heights();
let mut unchecked_heights = heights
.iter()
.map(|h| h.revision_height())
.filter(|h| !self.checked_heights.contains(h))
.collect::<Vec<u64>>();
unchecked_heights.sort();
unchecked_heights.retain(|h| *h >= value);
unchecked_heights
} else {
let heights = self.get_ibc_events_heights();
let unchecked_heights = heights
.iter()
.map(|h| h.revision_height())
.filter(|h| !self.checked_heights.contains(h))
.collect::<Vec<u64>>();
unchecked_heights
};

if !unchecked_heights.is_empty() {
let height = unchecked_heights[0];
warn!("querying ibc events at height: {:?}", unchecked_heights);
Expand Down
2 changes: 2 additions & 0 deletions tools/test-framework/src/bootstrap/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn init_test() -> Result<TestConfig, Error> {
let canister_id = "bkyz2-fmaaa-aaaaa-qaaaq-cai".to_string();
let near_rpc_endpoint =
"https://near-testnet.infura.io/v3/272532ecf0b64d7782a03db0cbcf3c30".to_string();
let filter_near_event_height: Option<u64> = Some(142766166); // maybe change
Ok(TestConfig {
chain_command_paths,
chain_store_dir,
Expand All @@ -87,6 +88,7 @@ pub fn init_test() -> Result<TestConfig, Error> {
near_ibc_address,
canister_id,
near_rpc_endpoint,
filter_near_event_height,
})
}

Expand Down
2 changes: 2 additions & 0 deletions tools/test-framework/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ pub struct TestConfig {
pub canister_id: String,

pub near_rpc_endpoint: String,

pub filter_near_event_height: Option<u64>,
}
2 changes: 2 additions & 0 deletions tools/test-framework/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl FullNode {
canister_pem: test_config.canister_pem.clone(),
near_ibc_address: NearIbcContractAddress::from_str(&test_config.near_ibc_address)
.unwrap(),
filter_near_event_height: test_config.filter_near_event_height,
canister_id: CanisterIdConfig::from_str(&test_config.canister_id).unwrap(),
r#type: ChainType::CosmosSdk,
rpc_addr: Url::from_str(&self.chain_driver.rpc_address())?,
Expand Down Expand Up @@ -195,6 +196,7 @@ impl FullNode {

Ok(config::ChainConfig {
id: ChainId::from_str("near-0").unwrap(),
filter_near_event_height: None,
ic_endpoint: test_config.ic_endpoint.clone(),
canister_pem: test_config.canister_pem.clone(),
near_ibc_address: NearIbcContractAddress::from_str(&test_config.near_ibc_address)
Expand Down