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

Use packet_ack_hex event attribute instead of deprecated packet_ack attribute to decode WriteAck event #3922

Merged
merged 2 commits into from
Apr 2, 2024
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 @@
- Use `packet_ack_hex` event attribute instead of deprecated `packet_ack` attribute to decode `WriteAck` event
([\#3921](https://github.com/informalsystems/hermes/issues/3921))
8 changes: 8 additions & 0 deletions crates/relayer-types/src/core/ics04_channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ define_error! {
format_args!("Invalid packet data, not a valid hex-encoded string: {}", e.data)
},

InvalidPacketAck
{
ack: String,
}
| e | {
format_args!("Invalid packet ack, not a valid hex-encoded string: {}", e.ack)
},

LowPacketHeight
{
chain_height: Height,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-types/src/core/ics04_channel/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const PKT_DST_PORT_ATTRIBUTE_KEY: &str = "packet_dst_port";
pub const PKT_DST_CHANNEL_ATTRIBUTE_KEY: &str = "packet_dst_channel";
pub const PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY: &str = "packet_timeout_height";
pub const PKT_TIMEOUT_TIMESTAMP_ATTRIBUTE_KEY: &str = "packet_timeout_timestamp";
pub const PKT_ACK_ATTRIBUTE_KEY: &str = "packet_ack";
pub const PKT_ACK_ATTRIBUTE_KEY: &str = "packet_ack_hex";

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct Attributes {
Expand Down
4 changes: 4 additions & 0 deletions crates/relayer-types/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ define_error! {
{ data: String }
| e | { format_args!("error decoding hex-encoded packet data: {}", e.data) },

InvalidPacketAck
{ ack: String }
| e | { format_args!("error decoding hex-encoded packet ack: {}", e.ack) },

MissingActionString
| _ | { "missing action string" },

Expand Down
7 changes: 5 additions & 2 deletions crates/relayer/src/chain/cosmos/types/events/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ impl TryFrom<RawObject<'_>> for WriteAcknowledgement {
type Error = EventError;

fn try_from(obj: RawObject<'_>) -> Result<Self, Self::Error> {
let ack = extract_attribute(&obj, &format!("{}.{}", obj.action, PKT_ACK_ATTRIBUTE_KEY))?
.into_bytes();
let ack_str =
extract_attribute(&obj, &format!("{}.{}", obj.action, PKT_ACK_ATTRIBUTE_KEY))?;

let ack = hex::decode(ack_str.to_lowercase())
.map_err(|_| EventError::invalid_packet_ack(ack_str))?;

let packet = Packet::try_from(obj)?;

Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ pub fn extract_packet_and_write_ack_from_tx(
.map_err(|_| ChannelError::invalid_packet_data(value.to_string()))?;
}
channel_events::PKT_ACK_ATTRIBUTE_KEY => {
write_ack = Vec::from(value.as_bytes());
write_ack = hex::decode(value.to_lowercase())
.map_err(|_| ChannelError::invalid_packet_ack(value.to_string()))?;
}
_ => {}
}
Expand Down
Loading