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

Deserialize ics20 v2 packet data with Protobuf #4165

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Deserialize ICS20 v2 packet data using Protobuf instead of JSON
([\#4098](https://github.com/informalsystems/hermes/issues/4098))
19 changes: 17 additions & 2 deletions crates/relayer/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Link<ChainA, ChainB> {
));
}

// Query the channel if it exists in order to retrieve the channel version.
// If the channel doesn't exist or the query fails, set the version to None.
let maybe_channel_a = a_chain.query_channel(
QueryChannelRequest {
port_id: opts.src_port_id.clone(),
channel_id: opts.src_channel_id.clone(),
height: QueryHeight::Latest,
},
IncludeProof::Yes,
);
let channel_version = match maybe_channel_a {
Ok((channel_a, _)) => Some(channel_a.version),
Err(_) => None,
};

let channel = Channel {
ordering: a_channel.ordering,
a_side: ChannelSide::new(
Expand All @@ -153,15 +168,15 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Link<ChainA, ChainB> {
a_connection_id,
opts.src_port_id.clone(),
Some(opts.src_channel_id.clone()),
None,
channel_version.clone(),
),
b_side: ChannelSide::new(
b_chain.clone(),
a_connection.counterparty().client_id().clone(),
a_connection.counterparty().connection_id().unwrap().clone(),
a_channel.counterparty().port_id.clone(),
Some(b_channel_id.clone()),
None,
channel_version,
),
connection_delay: a_connection.delay_period(),
};
Expand Down
12 changes: 7 additions & 5 deletions crates/relayer/src/link/relay_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use alloc::collections::BTreeMap as HashMap;
use alloc::collections::VecDeque;
use ibc_relayer_types::core::ics04_channel::packet::Sequence;
use ibc_relayer_types::core::ics04_channel::version::Version;
use prost::Message;
use serde::de::Error as _;
use serde_json::Error;
use std::ops::Sub;
use std::time::{Duration, Instant};

use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData;
use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketDataV2 as RawPacketDataV2;
use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData;
use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketDataV2;
use itertools::Itertools;
use tracing::{debug, error, info, span, trace, warn, Level};

Expand Down Expand Up @@ -2020,12 +2022,12 @@ fn extract_memo_and_receiver(
data: &[u8],
) -> Result<(String, String), Error> {
if channel_version.is_ics20_v2() {
match serde_json::from_slice::<RawPacketDataV2>(data) {
match FungibleTokenPacketDataV2::decode(data) {
Ok(packet_data) => Ok((packet_data.memo, packet_data.receiver)),
Err(e) => Err(e),
Err(e) => Err(Error::custom(e.to_string())),
}
} else {
match serde_json::from_slice::<RawPacketData>(data) {
match serde_json::from_slice::<FungibleTokenPacketData>(data) {
Ok(packet_data) => Ok((packet_data.memo, packet_data.receiver)),
Err(e) => Err(e),
}
Expand Down
20 changes: 17 additions & 3 deletions tools/integration-test/src/tests/ics20_filter/memo.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
use byte_unit::Byte;

use ibc_relayer::config::types::ics20_field_size_limit::Ics20FieldSizeLimit;
use ibc_relayer::{
channel::version::Version, config::types::ics20_field_size_limit::Ics20FieldSizeLimit,
};
use ibc_test_framework::prelude::*;

#[test]
fn test_memo_filter() -> Result<(), Error> {
run_binary_channel_test(&IbcMemoFilterTest)
run_binary_channel_test(&IbcMemoFilterTest { ics20_version: 1 })
}

#[cfg(any(doc, feature = "ics20-v2"))]
#[test]
fn test_memo_filter_ics20_v2() -> Result<(), Error> {
run_binary_channel_test(&IbcMemoFilterTest { ics20_version: 2 })
}

const MEMO_SIZE_LIMIT: usize = 2000;

pub struct IbcMemoFilterTest;
pub struct IbcMemoFilterTest {
pub ics20_version: u64,
}

impl TestOverrides for IbcMemoFilterTest {
fn modify_relayer_config(&self, config: &mut Config) {
Expand All @@ -19,6 +29,10 @@ impl TestOverrides for IbcMemoFilterTest {

config.mode.clients.misbehaviour = false;
}

fn channel_version(&self) -> Version {
Version::ics20(self.ics20_version)
}
}

impl BinaryChannelTest for IbcMemoFilterTest {
Expand Down
Loading