From 3d6aa590357d8b0188cb48b562555d56a0f0aec4 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Tue, 30 Jan 2024 19:00:13 +0800 Subject: [PATCH] Fix get_unreceived_packets from NEAR --- crates/relayer/src/chain/counterparty.rs | 52 ----------------------- crates/relayer/src/chain/near/contract.rs | 2 +- crates/relayer/src/link/relay_path.rs | 21 +++------ 3 files changed, 8 insertions(+), 67 deletions(-) diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index 47c1ab1250..be9425aae2 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -445,37 +445,6 @@ pub fn packet_acknowledgements( Ok(Some((acked_sequences, response_height))) } -pub fn packet_acknowledgements1( - chain: &impl ChainHandle, - port_id: &PortId, - channel_id: &ChannelId, - mut commit_sequences: Vec, -) -> Result, Height)>, Error> { - // If there aren't any sequences to query for, return early. - // Otherwise we end up with the full list of acknowledgements on chain, - // which is potentially huge and extremely costly. - if commit_sequences.is_empty() { - return Ok(None); - } - - // Get the packet acknowledgments on counterparty/source chain - let (acked_sequences, response_height) = chain - .query_packet_acknowledgements(QueryPacketAcknowledgementsRequest { - port_id: port_id.clone(), - channel_id: channel_id.clone(), - pagination: Some(PageRequest::all()), - packet_commitment_sequences: commit_sequences.clone(), - }) - .map_err(Error::relayer)?; - - let acked_sequences_set = acked_sequences.iter().cloned().collect::>(); - - commit_sequences.retain(|s| !acked_sequences_set.contains(s)); - commit_sequences.sort_unstable(); - - Ok(Some((commit_sequences, response_height))) -} - /// Returns the sequences of the packets that were sent on the chain and for which: /// - `MsgRecvPacket`-s have been received on the counterparty chain but /// - `MsgAcknowledgement`-s have NOT been received by the chain @@ -539,27 +508,6 @@ pub fn unreceived_packets( Ok((packet_seq_nrs, h)) } -pub fn acknowledgements_on_chain1( - chain: &impl ChainHandle, - counterparty_chain: &impl ChainHandle, - path: &PathIdentifiers, -) -> Result, Height)>, Error> { - let (commitments_on_counterparty, _) = commitments_on_chain( - counterparty_chain, - &path.counterparty_port_id, - &path.counterparty_channel_id, - )?; - - let sequences_and_height = packet_acknowledgements1( - chain, - &path.port_id, - &path.channel_id, - commitments_on_counterparty, - )?; - - Ok(sequences_and_height) -} - pub fn acknowledgements_on_chain( chain: &impl ChainHandle, counterparty_chain: &impl ChainHandle, diff --git a/crates/relayer/src/chain/near/contract.rs b/crates/relayer/src/chain/near/contract.rs index 27b1208d06..35aff105d5 100644 --- a/crates/relayer/src/chain/near/contract.rs +++ b/crates/relayer/src/chain/near/contract.rs @@ -216,7 +216,7 @@ pub trait NearIbcContract { self.view( self.get_contract_id(), - "get_unreceipt_packet".into(), + "get_unreceived_packets".into(), json!({ "port_id": port_id, "channel_id": channel_id, diff --git a/crates/relayer/src/link/relay_path.rs b/crates/relayer/src/link/relay_path.rs index 20e948d67d..a5fb38f90e 100644 --- a/crates/relayer/src/link/relay_path.rs +++ b/crates/relayer/src/link/relay_path.rs @@ -24,7 +24,6 @@ use ibc_relayer_types::timestamp::Timestamp; use ibc_relayer_types::tx_msg::Msg; use ibc_relayer_types::Height; -use crate::chain::counterparty::acknowledgements_on_chain1; use crate::chain::counterparty::unreceived_acknowledgements; use crate::chain::counterparty::unreceived_packets; use crate::chain::endpoint::ChainStatus; @@ -1110,20 +1109,14 @@ impl RelayPath { ) .entered(); - let (sequences, src_response_height) = if self.ordered_channel() { - if let Some((seqs, height)) = - acknowledgements_on_chain1(self.dst_chain(), self.src_chain(), &self.path_id) - .map_err(LinkError::supervisor)? - { - (seqs, height) - } else { - return Ok(()); - } - } else { - // Pull the s.n. of all packets that the destination chain has not yet received. + // Pull the s.n. of all packets that the destination chain has not yet received. + let (sequences, src_response_height) = unreceived_packets(self.dst_chain(), self.src_chain(), &self.path_id) - .map_err(LinkError::supervisor)? - }; + .map_err(LinkError::supervisor)?; + warn!( + "ys-debug: unreceived_packets {:?} {:?}", + sequences, src_response_height + ); let query_height = opt_query_height.unwrap_or(src_response_height);