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): plug-in union-ibc #3257

Merged
merged 4 commits into from
Nov 14, 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
48 changes: 12 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"cosmwasm/ucs01-relay-api",
"cosmwasm/ucs02-nft",
"cosmwasm/union-ibc",
"cosmwasm/union-ibc-msg",

"devnet-compose",

Expand Down Expand Up @@ -75,7 +76,7 @@ members = [
"light-clients/cometbls-light-client",
"light-clients/cometbls-light-client/types",

"light-clients/ethereum-light-client",
# "light-clients/ethereum-light-client",
"light-clients/ethereum-light-client/types",

# "light-clients/evm-in-cosmos-light-client",
Expand Down Expand Up @@ -132,7 +133,7 @@ members = [

"drip",

"light-clients/movement-light-client",
# "light-clients/movement-light-client",
"light-clients/movement-light-client/types",

"lib/aptos-verifier",
Expand Down Expand Up @@ -181,7 +182,7 @@ scroll-light-client-types = { path = "light-clients/scroll-light-client/types",

contracts = { path = "generated/rust/contracts", default-features = false }

ethereum-light-client = { path = "light-clients/ethereum-light-client", default-features = false }
# ethereum-light-client = { path = "light-clients/ethereum-light-client", default-features = false }
ethereum-light-client-types = { path = "light-clients/ethereum-light-client/types", default-features = false }
ethereum-sync-protocol = { path = "lib/ethereum-sync-protocol", default-features = false }
evm-storage-verifier = { path = "lib/evm-storage-verifier", default-features = false }
Expand All @@ -201,8 +202,9 @@ linea-light-client-types = { path = "light-clients/linea-light-client/types", de
linea-verifier = { path = "lib/linea-verifier", default-features = false }
linea-zktrie = { path = "lib/linea-zktrie", default-features = false }

ibc-solidity = { path = "lib/ibc-solidity", default-features = false }
union-ibc = { path = "cosmwasm/union-ibc", default-features = false }
ibc-solidity = { path = "lib/ibc-solidity", default-features = false }
union-ibc = { path = "cosmwasm/union-ibc", default-features = false }
union-ibc-msg = { path = "cosmwasm/union-ibc-msg", default-features = false }

gnark-key-parser = { path = "lib/gnark-key-parser", default-features = false }
gnark-mimc = { path = "lib/gnark-mimc", default-features = false }
Expand Down
31 changes: 10 additions & 21 deletions cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmwasm_std::{Addr, Event, IbcPacket};
use cosmwasm_std::{to_json_string, Addr, Event, IbcPacket, StdError};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use unionlabs::{
id::{ChannelId, PortId},
id::PortId,
validated::{Validate, Validated},
};

Expand All @@ -16,12 +16,8 @@ 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";
pub const SRC_PACKET: &str = "src_packet";
pub const DEST_PACKET: &str = "dst_packet";

#[derive(Error, Debug, PartialEq)]
pub enum MiddlewareError {
Expand Down Expand Up @@ -71,21 +67,14 @@ pub struct InFlightPfmPacket {
/// This is the protocol of the channel between A -> B, such that if there is a failure between B -> C then we know how to write the acknowledgement for the origin channel.
pub origin_protocol_version: String,
pub origin_packet: IbcPacket,
pub forward_src_channel_id: String,
pub forward_src_port_id: String,

pub forward_timeout: u64,
pub forward_packet: IbcPacket,
}

impl InFlightPfmPacket {
pub fn create_hop_event(&self, sent_sequence: u64) -> Event {
Event::new(PFM_HOP_EVENT)
.add_attribute(RECV_SEQUENCE_ATTR, self.origin_packet.sequence.to_string())
.add_attribute(DEST_CHANNEL_ATTR, self.forward_src_channel_id.clone())
.add_attribute(DEST_PORT_ATTR, self.forward_src_port_id.clone())
.add_attribute(SENT_SEQUENCE_ATTR, sent_sequence.to_string())
.add_attribute(SRC_CHANNEL_ATTR, self.origin_packet.src.channel_id.clone())
.add_attribute(SRC_PORT_ATTR, self.origin_packet.src.port_id.clone())
pub fn create_hop_event(&self) -> Result<Event, StdError> {
Ok(Event::new(PFM_HOP_EVENT)
.add_attribute(SRC_PACKET, to_json_string(&self.origin_packet)?)
.add_attribute(DEST_PACKET, to_json_string(&self.forward_packet)?))
}
}

Expand All @@ -100,7 +89,7 @@ pub enum Memo {
pub struct PacketForward {
pub receiver: PfmReceiver,
pub port: PortId,
pub channel: ChannelId,
pub channel: String,
#[serde(default = "default_pfm_timeout")]
pub timeout: String,
#[serde(default = "default_pfm_retries")]
Expand Down
32 changes: 20 additions & 12 deletions cosmwasm/ucs01-relay-api/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::btree_map::Entry, fmt::Debug};

use cosmwasm_std::{
Addr, Attribute, Binary, CheckedMultiplyRatioError, Coin, CosmosMsg, Event, IbcBasicResponse,
IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, IbcReceiveResponse, Response,
SubMsg, Timestamp,
IbcOrder, IbcPacket, IbcPacketAckMsg, IbcReceiveResponse, IbcTimeout, Response, SubMsg,
Timestamp,
};
use thiserror::Error;
use unionlabs::encoding::{self, Decode, DecodeErrorOf, Encode};
Expand Down Expand Up @@ -138,14 +138,24 @@ pub trait TransferProtocol {

fn load_channel_protocol_version(&self, channel_id: &str) -> Result<String, Self::Error>;

fn channel_endpoint(&self) -> &IbcEndpoint;

fn caller(&self) -> &Addr;

fn self_addr(&self) -> &Addr;

fn self_addr_canonical(&self) -> Result<AddrOf<Self::Packet>, Self::Error>;

fn send_packet(
&self,
data: Binary,
timeout: IbcTimeout,
) -> Result<CosmosMsg<Self::CustomMsg>, Self::Error>;

fn write_acknowledgement(
&self,
packet: &IbcPacket,
ack: Binary,
) -> Result<CosmosMsg<Self::CustomMsg>, Self::Error>;

// TODO: Remove use of Encoding Error
fn common_to_protocol_packet(
&self,
Expand Down Expand Up @@ -210,14 +220,12 @@ pub trait TransferProtocol {
};

let tokens = packet.tokens();
let sub = SubMsg::reply_always(
IbcMsg::SendPacket {
channel_id: self.channel_endpoint().channel_id.clone(),
data: packet.encode().into(),
timeout: input.current_time.plus_seconds(input.timeout_delta).into(),
},
IBC_SEND_ID,
);
let send_packet_msg = self.send_packet(
packet.encode().into(),
input.current_time.plus_seconds(input.timeout_delta).into(),
)?;
let sub = SubMsg::reply_always(send_packet_msg, IBC_SEND_ID);

Ok(Response::new()
.add_messages(send_msgs)
.add_submessage(sub)
Expand Down
2 changes: 2 additions & 0 deletions cosmwasm/ucs01-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dlmalloc = { workspace = true, features = ["global"] }
ethabi = { workspace = true }
go-parse-duration = { workspace = true }
hex = { workspace = true }
ibc-solidity = { workspace = true, features = ["serde"] }
prost = { workspace = true }
protos = { workspace = true }
schemars = { workspace = true }
Expand All @@ -40,6 +41,7 @@ token-factory-api = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
ucs01-relay-api = { workspace = true }
union-ibc-msg = { workspace = true }
unionlabs = { workspace = true }

[dev-dependencies]
Expand Down
10 changes: 0 additions & 10 deletions cosmwasm/ucs01-relay/src/bin/schema.rs

This file was deleted.

Loading