Skip to content

Commit b12c744

Browse files
authored
feat(ucs01-relay): create pfm events st hubble can track outgoing hop packets (#2057)
- Add event for PFM hops (expected format below) - Cleanup existing PFM events - Remove uses of unwrap relevant to PFM ## PFM Hop Event Structure ``` packet_forward_hop: - recv_sequence: <u64> - dest_channel: <String> - dest_port: <String> - sent_sequence: <u64> - src_channel: <String> - src_port: <String> ``` ## Real Example Osmosis -> Union -> Ethereum ``` - attributes: - index: true key: _contract_address value: union1uvagqv5qy0d6udhj3wq74jxelqs8nl7rxdun4fdtymhv24d4zrcs9n97rr - index: true key: recv_sequence value: "1" - index: true key: dest_channel value: channel-0 - index: true key: dest_port value: wasm.union1uvagqv5qy0d6udhj3wq74jxelqs8nl7rxdun4fdtymhv24d4zrcs9n97rr - index: true key: sent_sequence value: "1" - index: true key: src_channel value: channel-0 - index: true key: src_port value: transfer - index: true key: msg_index value: "0" type: wasm-packet_forward_hop ```
2 parents e795c11 + 76c523a commit b12c744

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

cosmwasm/ucs01-relay-api/src/middleware.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{Addr, Binary, IbcPacket, IbcTimeout};
1+
use cosmwasm_std::{Addr, Binary, Event, IbcPacket, IbcTimeout};
22
use serde::{Deserialize, Serialize};
33
use thiserror::Error;
44
use unionlabs::{
@@ -8,8 +8,19 @@ use unionlabs::{
88

99
pub const DEFAULT_PFM_TIMEOUT: &str = "1m";
1010
pub const DEFAULT_PFM_RETRIES: u8 = 0;
11+
1112
pub const PFM_MODULE_NAME: &str = "packetforwardmiddleware";
1213

14+
pub const PFM_ERROR_EVENT: &str = "packet_forward_error";
15+
pub const PFM_HOP_EVENT: &str = "packet_forward_hop";
16+
17+
pub const RECV_SEQUENCE_ATTR: &str = "recv_sequence";
18+
pub const SENT_SEQUENCE_ATTR: &str = "sent_sequence";
19+
pub const DEST_CHANNEL_ATTR: &str = "dest_channel";
20+
pub const DEST_PORT_ATTR: &str = "dest_port";
21+
pub const SRC_CHANNEL_ATTR: &str = "src_channel";
22+
pub const SRC_PORT_ATTR: &str = "src_port";
23+
1324
#[derive(Error, Debug, PartialEq)]
1425
pub enum MiddlewareError {
1526
#[error("{0}")]
@@ -87,6 +98,16 @@ impl InFlightPfmPacket {
8798
forward_port_id,
8899
}
89100
}
101+
102+
pub fn create_hop_event(&self, sent_sequence: u64) -> Event {
103+
Event::new(PFM_HOP_EVENT)
104+
.add_attribute(RECV_SEQUENCE_ATTR, self.packet_sequence.to_string())
105+
.add_attribute(DEST_CHANNEL_ATTR, self.forward_channel_id.clone())
106+
.add_attribute(DEST_PORT_ATTR, self.forward_port_id.clone())
107+
.add_attribute(SENT_SEQUENCE_ATTR, sent_sequence.to_string())
108+
.add_attribute(SRC_CHANNEL_ATTR, self.packet_src_channel_id.clone())
109+
.add_attribute(SRC_PORT_ATTR, self.packet_src_port_id.clone())
110+
}
90111
}
91112

92113
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]

cosmwasm/ucs01-relay/src/ibc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ pub fn reply(
8383
.save(deps.storage, refund_packet_key.clone(), &in_flight_packet)
8484
.expect("infallible update");
8585

86-
Ok(Response::new()
87-
.add_attribute("pfm_store_inclusion", format!("{refund_packet_key:?}")))
86+
Ok(Response::new().add_event(in_flight_packet.create_hop_event(send_res.sequence)))
8887
}
8988
(_, result) => Err(ContractError::UnknownReply {
9089
id: reply.id,

cosmwasm/ucs01-relay/src/protocol.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use protos::{
1010
use sha2::{Digest, Sha256};
1111
use token_factory_api::TokenFactoryMsg;
1212
use ucs01_relay_api::{
13-
middleware::{InFlightPfmPacket, Memo, MiddlewareError, PacketForward, PacketForwardError},
13+
middleware::{
14+
InFlightPfmPacket, Memo, MiddlewareError, PacketForward, PacketForwardError,
15+
PFM_ERROR_EVENT,
16+
},
1417
protocol::{TransferProtocol, ATTR_ERROR, ATTR_SUCCESS, IBC_SEND_ID},
1518
types::{
1619
make_foreign_denom, DenomOrigin, EncodingError, GenericAck, Ics20Ack, Ics20Packet,
@@ -554,7 +557,7 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
554557
return IbcReceiveResponse::new(
555558
Binary::try_from(Self::ack_failure(e.to_string())).expect("impossible"),
556559
)
557-
.add_event(Event::new("forward_err").add_attribute("error", e.to_string()))
560+
.add_event(Event::new(PFM_ERROR_EVENT).add_attribute("error", e.to_string()))
558561
}
559562
};
560563

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

582585
// TODO: persist full memo
583586
let memo = match forward.next {
584-
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next }).unwrap(),
587+
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next })
588+
.expect("can convert pfm memo to json string"),
585589
None => "".to_owned(),
586590
};
587591

@@ -920,7 +924,7 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
920924
return IbcReceiveResponse::new(
921925
Binary::try_from(Self::ack_failure(e.to_string())).expect("impossible"),
922926
)
923-
.add_event(Event::new("forward_err").add_attribute("error", e.to_string()))
927+
.add_event(Event::new(PFM_ERROR_EVENT).add_attribute("error", e.to_string()))
924928
}
925929
};
926930

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

948952
// TODO: persist full memo
949953
let memo = match forward.next {
950-
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next }).unwrap(),
954+
Some(next) => serde_json_wasm::to_string(&Memo::Forward { forward: *next })
955+
.expect("can convert pfm memo to json string"),
951956
None => "".to_owned(),
952957
};
953958

0 commit comments

Comments
 (0)