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

feat(ucs01-relay): create pfm events st hubble can track outgoing hop packets #2057

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
23 changes: 22 additions & 1 deletion cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Binary, IbcPacket, IbcTimeout};
use cosmwasm_std::{Addr, Binary, Event, IbcPacket, IbcTimeout};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use unionlabs::{
Expand All @@ -8,8 +8,19 @@ use unionlabs::{

pub const DEFAULT_PFM_TIMEOUT: &str = "1m";
pub const DEFAULT_PFM_RETRIES: u8 = 0;

pub const PFM_MODULE_NAME: &str = "packetforwardmiddleware";

pub const PFM_ERROR_EVENT: &str = "packet_forward_error";
pub const PFM_HOP_EVENT: &str = "packet_forward_hop";

pub const RECV_SEQUENCE_ATTR: &str = "recv_sequence";
pub const SENT_SEQUENCE_ATTR: &str = "sent_sequence";
pub const DEST_CHANNEL_ATTR: &str = "dest_channel";
pub const DEST_PORT_ATTR: &str = "dest_port";
pub const SRC_CHANNEL_ATTR: &str = "src_channel";
pub const SRC_PORT_ATTR: &str = "src_port";

#[derive(Error, Debug, PartialEq)]
pub enum MiddlewareError {
#[error("{0}")]
Expand Down Expand Up @@ -87,6 +98,16 @@ impl InFlightPfmPacket {
forward_port_id,
}
}

pub fn create_hop_event(&self, sent_sequence: u64) -> Event {
Event::new(PFM_HOP_EVENT)
.add_attribute(RECV_SEQUENCE_ATTR, self.packet_sequence.to_string())
.add_attribute(DEST_CHANNEL_ATTR, self.forward_channel_id.clone())
.add_attribute(DEST_PORT_ATTR, self.forward_port_id.clone())
.add_attribute(SENT_SEQUENCE_ATTR, sent_sequence.to_string())
.add_attribute(SRC_CHANNEL_ATTR, self.packet_src_channel_id.clone())
.add_attribute(SRC_PORT_ATTR, self.packet_src_port_id.clone())
}
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
Expand Down
3 changes: 1 addition & 2 deletions cosmwasm/ucs01-relay/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ pub fn reply(
.save(deps.storage, refund_packet_key.clone(), &in_flight_packet)
.expect("infallible update");

Ok(Response::new()
.add_attribute("pfm_store_inclusion", format!("{refund_packet_key:?}")))
Ok(Response::new().add_event(in_flight_packet.create_hop_event(send_res.sequence)))
}
(_, result) => Err(ContractError::UnknownReply {
id: reply.id,
Expand Down
15 changes: 10 additions & 5 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use protos::{
use sha2::{Digest, Sha256};
use token_factory_api::TokenFactoryMsg;
use ucs01_relay_api::{
middleware::{InFlightPfmPacket, Memo, MiddlewareError, PacketForward, PacketForwardError},
middleware::{
InFlightPfmPacket, Memo, MiddlewareError, PacketForward, PacketForwardError,
PFM_ERROR_EVENT,
},
protocol::{TransferProtocol, ATTR_ERROR, ATTR_SUCCESS, IBC_SEND_ID},
types::{
make_foreign_denom, DenomOrigin, EncodingError, GenericAck, Ics20Ack, Ics20Packet,
Expand Down Expand Up @@ -554,7 +557,7 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
return IbcReceiveResponse::new(
Binary::try_from(Self::ack_failure(e.to_string())).expect("impossible"),
)
.add_event(Event::new("forward_err").add_attribute("error", e.to_string()))
.add_event(Event::new(PFM_ERROR_EVENT).add_attribute("error", e.to_string()))
}
};

Expand All @@ -581,7 +584,8 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {

// TODO: persist full memo
let memo = match forward.next {
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next }).unwrap(),
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next })
.expect("can convert pfm memo to json string"),
None => "".to_owned(),
};

Expand Down Expand Up @@ -920,7 +924,7 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
return IbcReceiveResponse::new(
Binary::try_from(Self::ack_failure(e.to_string())).expect("impossible"),
)
.add_event(Event::new("forward_err").add_attribute("error", e.to_string()))
.add_event(Event::new(PFM_ERROR_EVENT).add_attribute("error", e.to_string()))
}
};

Expand All @@ -947,7 +951,8 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {

// TODO: persist full memo
let memo = match forward.next {
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next }).unwrap(),
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next })
.expect("can convert pfm memo to json string"),
None => "".to_owned(),
};

Expand Down
Loading