Skip to content

Commit 1bd76db

Browse files
authored
feat(relayer): reuse ConnectionEnd and ChannelEnd from ibc-rs (#197)
* felt to string and back * use ibc-rs client id * refactor for ibc-rs client id * use ibc-rs connection id * refactor for conneciton id * fixme comment * use ibc-rs channel id * fixme comment * refactor for channel id * use ibc-rs port id * refactor for port id * rename vars * use ibc-rs channel counterparty * use ibc-rs commitment prefix * use ibc-rs connection counterparty * refactor for commitment prefix and connection counterparty * use Duration for delay_period * use ibc-rs connection version * refactor for connection version * use ibc-rs connection state * use ibc-rs connection end * refactor for connection end * update fixme comment * use ibc-rs channel order * refactor for channel order * use ibc-rs channel state * use ibc-rs channel version * refactor for channel version * fix error strings * use ibc-rs channel end * refactor for channel end * rm redundant asserts * fix channel open try message
1 parent 01ffff4 commit 1bd76db

File tree

26 files changed

+610
-655
lines changed

26 files changed

+610
-655
lines changed

relayer/crates/starknet-chain-components/src/components/encoding/cairo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::time::Duration;
2+
13
use cgp::core::component::{UseContext, UseDelegate};
24
use cgp::prelude::*;
35
use hermes_cairo_encoding_components::components::encode_mut::*;
@@ -21,6 +23,7 @@ use crate::types::client_id::{ClientId, EncodeClientId};
2123
use crate::types::connection_id::{
2224
ConnectionCounterparty, ConnectionEnd, ConnectionId, ConnectionState,
2325
EncodeConnectionCounterparty, EncodeConnectionEnd, EncodeConnectionId, EncodeConnectionState,
26+
EncodeDuration,
2427
};
2528
use crate::types::cosmos::client_state::{
2629
ClientStatus, CometClientState, EncodeChainId, EncodeClientStatus, EncodeCometClientState,
@@ -127,6 +130,7 @@ delegate_components! {
127130
(ViaCairo, ClientId): EncodeClientId,
128131
(ViaCairo, ChainId): EncodeChainId,
129132
(ViaCairo, ConnectionId): EncodeConnectionId,
133+
(ViaCairo, Duration): EncodeDuration,
130134
(ViaCairo, ConnectionCounterparty): EncodeConnectionCounterparty,
131135
(ViaCairo, ConnectionState): EncodeConnectionState,
132136
(ViaCairo, ConnectionEnd): EncodeConnectionEnd,

relayer/crates/starknet-chain-components/src/impls/events/ack.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,10 @@ where
6464
) -> Result<Packet, Chain::Error> {
6565
let packet = Packet {
6666
seq_on_a: event.sequence_on_a.sequence.into(),
67-
port_id_on_a: event
68-
.port_id_on_a
69-
.port_id
70-
.parse()
71-
.map_err(Chain::raise_error)?,
72-
chan_id_on_a: event
73-
.channel_id_on_a
74-
.channel_id
75-
.parse()
76-
.map_err(Chain::raise_error)?,
77-
port_id_on_b: event
78-
.port_id_on_b
79-
.port_id
80-
.parse()
81-
.map_err(Chain::raise_error)?,
82-
chan_id_on_b: event
83-
.channel_id_on_b
84-
.channel_id
85-
.parse()
86-
.map_err(Chain::raise_error)?,
87-
67+
port_id_on_a: event.port_id_on_a.clone(),
68+
chan_id_on_a: event.channel_id_on_a.clone(),
69+
port_id_on_b: event.port_id_on_b.clone(),
70+
chan_id_on_b: event.channel_id_on_b.clone(),
8871
// FIXME: make the Cairo contract include these fields in the event
8972
data: Vec::new(),
9073
timeout_height_on_b: TimeoutHeight::Never,

relayer/crates/starknet-chain-components/src/impls/events/send_packet.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,10 @@ where
107107

108108
let packet = Packet {
109109
seq_on_a: event.sequence_on_a.sequence.into(),
110-
port_id_on_a: event
111-
.port_id_on_a
112-
.port_id
113-
.parse()
114-
.map_err(Chain::raise_error)?,
115-
chan_id_on_a: event
116-
.channel_id_on_a
117-
.channel_id
118-
.parse()
119-
.map_err(Chain::raise_error)?,
120-
port_id_on_b: event
121-
.port_id_on_b
122-
.port_id
123-
.parse()
124-
.map_err(Chain::raise_error)?,
125-
chan_id_on_b: event
126-
.channel_id_on_b
127-
.channel_id
128-
.parse()
129-
.map_err(Chain::raise_error)?,
110+
port_id_on_a: event.port_id_on_a.clone(),
111+
chan_id_on_a: event.channel_id_on_a.clone(),
112+
port_id_on_b: event.port_id_on_b.clone(),
113+
chan_id_on_b: event.channel_id_on_b.clone(),
130114
data: cosmos_packet_data,
131115
timeout_height_on_b,
132116
timeout_timestamp_on_b,

relayer/crates/starknet-chain-components/src/impls/messages/channel.rs

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ use starknet::macros::selector;
3333
use crate::impls::types::message::StarknetMessage;
3434
use crate::traits::queries::address::CanQueryContractAddress;
3535
use crate::types::channel_id::ChannelId as StarknetChannelId;
36-
use crate::types::connection_id::ConnectionId as StarknetConnectionId;
3736
use crate::types::cosmos::height::Height as CairoHeight;
3837
use crate::types::messages::ibc::channel::{
39-
AppVersion, ChannelOrdering, MsgChanOpenAck, MsgChanOpenConfirm, MsgChanOpenInit,
40-
MsgChanOpenTry, PortId as StarknetPortId,
38+
ChannelOrdering, MsgChanOpenAck, MsgChanOpenConfirm, MsgChanOpenInit, MsgChanOpenTry,
4139
};
4240
use crate::types::messages::ibc::packet::StateProof;
4341
pub struct BuildStarknetChannelHandshakeMessages;
@@ -62,27 +60,13 @@ where
6260
counterparty_port_id: &IbcPortId,
6361
init_channel_options: &CosmosInitChannelOptions,
6462
) -> Result<Chain::Message, Chain::Error> {
65-
let port_id_on_a = StarknetPortId {
66-
port_id: port_id.to_string(),
67-
};
68-
69-
let port_id_on_b = StarknetPortId {
70-
port_id: counterparty_port_id.to_string(),
71-
};
72-
7363
if init_channel_options.connection_hops.len() != 1 {
7464
return Err(Chain::raise_error(
7565
"Starknet only supports a single connection hop",
7666
));
7767
}
7868

79-
let conn_id_on_a = StarknetConnectionId {
80-
connection_id: init_channel_options.connection_hops[0].to_string(),
81-
};
82-
83-
let version_proposal = AppVersion {
84-
version: init_channel_options.channel_version.to_string(),
85-
};
69+
let conn_id_on_a = init_channel_options.connection_hops[0].clone();
8670

8771
let ordering = match init_channel_options.ordering {
8872
IbcOrder::None => {
@@ -93,10 +77,10 @@ where
9377
};
9478

9579
let chan_open_init_msg = MsgChanOpenInit {
96-
port_id_on_a,
80+
port_id_on_a: port_id.clone(),
9781
conn_id_on_a,
98-
port_id_on_b,
99-
version_proposal,
82+
port_id_on_b: counterparty_port_id.clone(),
83+
version_proposal: init_channel_options.channel_version.clone(),
10084
ordering,
10185
};
10286

@@ -147,31 +131,13 @@ where
147131
counterparty_channel_id: &ChannelId,
148132
counterparty_payload: ChannelOpenTryPayload<Counterparty, Chain>,
149133
) -> Result<Chain::Message, Chain::Error> {
150-
let port_id_on_b = StarknetPortId {
151-
port_id: port_id.to_string(),
152-
};
153-
154134
if counterparty_payload.channel_end.connection_hops.len() != 1 {
155135
return Err(Chain::raise_error(
156136
"Starknet only supports a single connection hop",
157137
));
158138
}
159139

160-
let conn_id_on_b = StarknetConnectionId {
161-
connection_id: counterparty_payload.channel_end.connection_hops[0].to_string(),
162-
};
163-
164-
let port_id_on_a = StarknetPortId {
165-
port_id: counterparty_port_id.to_string(),
166-
};
167-
168-
let chan_id_on_a = StarknetChannelId {
169-
channel_id: counterparty_channel_id.to_string(),
170-
};
171-
172-
let version_on_a = AppVersion {
173-
version: counterparty_payload.channel_end.version.to_string(),
174-
};
140+
let conn_id_on_b = counterparty_payload.channel_end.connection_hops[0].clone();
175141

176142
let proof_chan_end_on_a = StateProof {
177143
proof: vec![Felt::ONE],
@@ -191,11 +157,11 @@ where
191157
};
192158

193159
let chan_open_try_msg = MsgChanOpenTry {
194-
port_id_on_b,
160+
port_id_on_b: port_id.clone(),
195161
conn_id_on_b,
196-
port_id_on_a,
197-
chan_id_on_a,
198-
version_on_a,
162+
port_id_on_a: counterparty_port_id.clone(),
163+
chan_id_on_a: counterparty_channel_id.clone(),
164+
version_on_a: counterparty_payload.channel_end.version.clone(),
199165
proof_chan_end_on_a,
200166
proof_height_on_a,
201167
ordering,
@@ -248,18 +214,6 @@ where
248214
counterparty_channel_id: &ChannelId,
249215
counterparty_payload: ChannelOpenAckPayload<Counterparty, Chain>,
250216
) -> Result<Chain::Message, Chain::Error> {
251-
let port_id_on_a = StarknetPortId {
252-
port_id: port_id.to_string(),
253-
};
254-
255-
let chan_id_on_b = StarknetChannelId {
256-
channel_id: counterparty_channel_id.to_string(),
257-
};
258-
259-
let version_on_b = AppVersion {
260-
version: counterparty_payload.channel_end.version.to_string(),
261-
};
262-
263217
let proof_chan_end_on_b = StateProof {
264218
proof: vec![Felt::ONE],
265219
};
@@ -270,10 +224,10 @@ where
270224
};
271225

272226
let chan_open_ack_msg = MsgChanOpenAck {
273-
port_id_on_a,
227+
port_id_on_a: port_id.clone(),
274228
chan_id_on_a: channel_id.clone(),
275-
chan_id_on_b,
276-
version_on_b,
229+
chan_id_on_b: counterparty_channel_id.clone(),
230+
version_on_b: counterparty_payload.channel_end.version.clone(),
277231
proof_chan_end_on_b,
278232
proof_height_on_b,
279233
};
@@ -322,10 +276,6 @@ where
322276
channel_id: &StarknetChannelId,
323277
counterparty_payload: ChannelOpenConfirmPayload<Counterparty>,
324278
) -> Result<Chain::Message, Chain::Error> {
325-
let port_id_on_b = StarknetPortId {
326-
port_id: port_id.to_string(),
327-
};
328-
329279
let proof_chan_end_on_a = StateProof {
330280
proof: vec![Felt::ONE],
331281
};
@@ -336,7 +286,7 @@ where
336286
};
337287

338288
let chan_open_confirm_msg = MsgChanOpenConfirm {
339-
port_id_on_b,
289+
port_id_on_b: port_id.clone(),
340290
chan_id_on_b: channel_id.clone(),
341291
proof_chan_end_on_a,
342292
proof_height_on_a,

0 commit comments

Comments
 (0)