Skip to content

Commit

Permalink
Fix get_unreceived_packets from NEAR
Browse files Browse the repository at this point in the history
  • Loading branch information
en committed Jan 30, 2024
1 parent 60a6e6c commit 3d6aa59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 67 deletions.
52 changes: 0 additions & 52 deletions crates/relayer/src/chain/counterparty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sequence>,
) -> Result<Option<(Vec<Sequence>, 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::<HashSet<_>>();

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
Expand Down Expand Up @@ -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<Option<(Vec<Sequence>, 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer/src/chain/near/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub trait NearIbcContract {

self.view(
self.get_contract_id(),
"get_unreceipt_packet".into(),
"get_unreceived_packets".into(),

This comment has been minimized.

Copy link
@Ngovantuan9997

Ngovantuan9997 Sep 14, 2024

Ok 200k

json!({
"port_id": port_id,
"channel_id": channel_id,
Expand Down
21 changes: 7 additions & 14 deletions crates/relayer/src/link/relay_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1110,20 +1109,14 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> RelayPath<ChainA, ChainB> {
)
.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);

Expand Down

1 comment on commit 3d6aa59

@Ngovantuan9997
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.