Skip to content

Commit

Permalink
rm channel handshakes
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Oct 23, 2024
1 parent d5d4c9d commit bbef5ed
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 230 deletions.
10 changes: 1 addition & 9 deletions ibc-eureka-core/ics04-channel/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! ICS4 (channel) context.
use ibc_eureka_core_channel_types::channel::ChannelEnd;
use ibc_eureka_core_channel_types::commitment::PacketCommitment;
use ibc_eureka_core_client::context::prelude::*;
use ibc_eureka_core_handler_types::events::IbcEvent;
use ibc_eureka_core_host::types::error::HostError;
use ibc_eureka_core_host::types::identifiers::Sequence;
use ibc_eureka_core_host::types::path::{ChannelEndPath, CommitmentPath, SeqSendPath};
use ibc_eureka_core_host::types::path::{CommitmentPath, SeqSendPath};
use ibc_eureka_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;

Expand All @@ -17,9 +16,6 @@ pub trait SendPacketValidationContext {
/// Retrieve the context that implements all clients' `ValidationContext`.
fn get_client_validation_context(&self) -> &Self::V;

/// Returns the ChannelEnd for the given `port_id` and `chan_id`.
fn channel_end(&self, channel_end_path: &ChannelEndPath) -> Result<ChannelEnd, HostError>;

fn get_next_sequence_send(&self, seq_send_path: &SeqSendPath) -> Result<Sequence, HostError>;
}

Expand All @@ -33,10 +29,6 @@ where
self.get_client_validation_context()
}

fn channel_end(&self, channel_end_path: &ChannelEndPath) -> Result<ChannelEnd, HostError> {
self.channel_end(channel_end_path)
}

fn get_next_sequence_send(&self, seq_send_path: &SeqSendPath) -> Result<Sequence, HostError> {
self.get_next_sequence_send(seq_send_path)
}
Expand Down
24 changes: 7 additions & 17 deletions ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ibc_eureka_core_channel_types::channel::{Counterparty, Order, State as ChannelState};
use ibc_eureka_core_channel_types::commitment::{
compute_ack_commitment, compute_packet_commitment,
};
Expand Down Expand Up @@ -35,25 +34,21 @@ pub fn acknowledgement_packet_execute<ExecCtx>(
where
ExecCtx: ExecutionContext,
{
let payload = &msg.packet.payloads[0];
let packet = &msg.packet;
let payload = &packet.payloads[0];

let port_id_on_a = &payload.header.source_port.1;
let channel_id_on_a = &msg.packet.header.source_client;
let seq_on_a = &msg.packet.header.seq_on_a;
let channel_id_on_a = &packet.header.source_client;
let seq_on_a = &packet.header.seq_on_a;

let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

// In all cases, this event is emitted
let event = IbcEvent::AcknowledgePacket(AcknowledgePacket::new(
msg.packet.clone(),
chan_end_on_a.ordering,
));
let event = IbcEvent::AcknowledgePacket(AcknowledgePacket::new(packet.clone()));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(event)?;

let commitment_path_on_a =
CommitmentPath::new(port_id_on_a, channel_id_on_a, msg.packet.header.seq_on_a);
let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a);

// check if we're in the NO-OP case
if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() {
Expand All @@ -65,7 +60,7 @@ where
};

let (extras, cb_result) =
module.on_acknowledgement_packet_execute(&msg.packet, &msg.acknowledgement, &msg.signer);
module.on_acknowledgement_packet_execute(packet, &msg.acknowledgement, &msg.signer);

cb_result?;

Expand Down Expand Up @@ -116,14 +111,9 @@ where
let data = &payload.data;

let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

chan_end_on_a.verify_state_matches(&ChannelState::Open)?;

let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone()));

Check failure on line 115 in ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `Counterparty`

error[E0433]: failed to resolve: use of undeclared type `Counterparty` --> ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs:115:24 | 115 | let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone())); | ^^^^^^^^^^^^ use of undeclared type `Counterparty` | help: consider importing one of these structs | 1 + use crate::types::proto::v1::Counterparty; | 1 + use ibc_eureka_core_channel_types::proto::v1::Counterparty; |

Check failure on line 115 in ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs

View workflow job for this annotation

GitHub Actions / Code Coverage

failed to resolve: use of undeclared type `Counterparty`

Check failure on line 115 in ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs

View workflow job for this annotation

GitHub Actions / Run Tests

failed to resolve: use of undeclared type `Counterparty`

Check failure on line 115 in ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs

View workflow job for this annotation

GitHub Actions / Check Documentations

failed to resolve: use of undeclared type `Counterparty`

Check failure on line 115 in ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs

View workflow job for this annotation

GitHub Actions / Check Features

failed to resolve: use of undeclared type `Counterparty`

chan_end_on_a.verify_counterparty_matches(&counterparty)?;

let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a);

// Verify packet commitment
Expand Down
12 changes: 1 addition & 11 deletions ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ibc_eureka_core_channel_types::channel::{Counterparty, Order, State as ChannelState};
use ibc_eureka_core_channel_types::commitment::{
compute_ack_commitment, compute_packet_commitment,
};
Expand Down Expand Up @@ -43,7 +42,6 @@ where
let seq_on_a = &packet.header.seq_on_a;

let chan_end_path_on_b = ChannelEndPath::new(port_id_on_b, channel_id_on_b);
let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?;

// Check if another relayer already relayed the packet.
// We don't want to fail the transaction in this case.
Expand Down Expand Up @@ -105,10 +103,7 @@ where
ctx_b.log_message("success: packet receive".to_string())?;
ctx_b.log_message("success: packet write acknowledgement".to_string())?;

let event = IbcEvent::ReceivePacket(ReceivePacket::new(
msg.packet.clone(),
chan_end_on_b.ordering,
));
let event = IbcEvent::ReceivePacket(ReceivePacket::new(msg.packet.clone()));
ctx_b.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_b.emit_ibc_event(event)?;
let event =
Expand Down Expand Up @@ -145,14 +140,9 @@ where
let data = &payload.data;

let chan_end_path_on_b = ChannelEndPath::new(port_id_on_b, channel_id_on_b);
let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?;

chan_end_on_b.verify_state_matches(&ChannelState::Open)?;

let counterparty = Counterparty::new(port_id_on_a.clone(), Some(channel_id_on_a.clone()));

Check failure on line 144 in ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `Counterparty`

error[E0433]: failed to resolve: use of undeclared type `Counterparty` --> ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs:144:24 | 144 | let counterparty = Counterparty::new(port_id_on_a.clone(), Some(channel_id_on_a.clone())); | ^^^^^^^^^^^^ use of undeclared type `Counterparty` | help: consider importing one of these structs | 1 + use crate::types::proto::v1::Counterparty; | 1 + use ibc_eureka_core_channel_types::proto::v1::Counterparty; |

chan_end_on_b.verify_counterparty_matches(&counterparty)?;

let latest_height = ctx_b.host_height()?;
if packet.header.timeout_height_on_b.has_expired(latest_height) {
return Err(ChannelError::InsufficientPacketHeight {
Expand Down
15 changes: 1 addition & 14 deletions ibc-eureka-core/ics04-channel/src/handler/send_packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ibc_eureka_core_channel_types::channel::Counterparty;
use ibc_eureka_core_channel_types::commitment::compute_packet_commitment;
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::SendPacket;
Expand Down Expand Up @@ -37,21 +36,9 @@ pub fn send_packet_validate(

let port_id_on_a = &payload.header.source_port.1;
let channel_id_on_a = &packet.header.source_client;
let port_id_on_b = &payload.header.target_port.1;
let channel_id_on_b = &packet.header.target_client;
let seq_on_a = &packet.header.seq_on_a;

let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

// Checks the channel end not be `Closed`.
// This allows for optimistic packet processing before a channel opens
chan_end_on_a.verify_not_closed()?;

let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone()));

chan_end_on_a.verify_counterparty_matches(&counterparty)?;

let client_id_on_a = channel_id_on_b.as_ref();

let client_val_ctx_a = ctx_a.get_client_validation_context();
Expand Down Expand Up @@ -137,7 +124,7 @@ pub fn send_packet_execute(
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

Check failure on line 124 in ibc-eureka-core/ics04-channel/src/handler/send_packet.rs

View workflow job for this annotation

GitHub Actions / clippy

no method named `channel_end` found for mutable reference `&mut impl SendPacketExecutionContext` in the current scope

error[E0599]: no method named `channel_end` found for mutable reference `&mut impl SendPacketExecutionContext` in the current scope --> ibc-eureka-core/ics04-channel/src/handler/send_packet.rs:124:35 | 124 | let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; | ^^^^^^^^^^^ method not found in `&mut impl SendPacketExecutionContext`

ctx_a.log_message("success: packet send".to_string())?;
let event = IbcEvent::SendPacket(SendPacket::new(packet, chan_end_on_a.ordering));
let event = IbcEvent::SendPacket(SendPacket::new(packet));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(event)?;
}
Expand Down
13 changes: 1 addition & 12 deletions ibc-eureka-core/ics04-channel/src/handler/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ibc_eureka_core_channel_types::channel::{Counterparty, Order, State};
use ibc_eureka_core_channel_types::commitment::compute_packet_commitment;
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::{ChannelClosed, TimeoutPacket};
Expand Down Expand Up @@ -60,10 +59,9 @@ where
let seq_on_a = &packet.header.seq_on_a;

let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

// In all cases, this event is emitted
let event = IbcEvent::TimeoutPacket(TimeoutPacket::new(packet.clone(), chan_end_on_a.ordering));
let event = IbcEvent::TimeoutPacket(TimeoutPacket::new(packet.clone()));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(event)?;

Expand Down Expand Up @@ -107,7 +105,6 @@ where
channel_id_on_a.clone(),
chan_end_on_a.counterparty().port_id.clone(),
chan_end_on_a.counterparty().channel_id.clone(),
chan_end_on_a.ordering,
));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(event)?;
Expand Down Expand Up @@ -141,14 +138,6 @@ where
let seq_on_a = &packet.header.seq_on_a;
let data = &payload.data;

let chan_end_on_a = ctx_a.channel_end(&ChannelEndPath::new(port_id_on_a, channel_id_on_a))?;

chan_end_on_a.verify_state_matches(&State::Open)?;

let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone()));

chan_end_on_a.verify_counterparty_matches(&counterparty)?;

//verify packet commitment
let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a);
let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else {
Expand Down
29 changes: 0 additions & 29 deletions ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, Order, State};
use ibc_eureka_core_channel_types::commitment::compute_packet_commitment;
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::msgs::MsgTimeoutOnClose;
Expand Down Expand Up @@ -27,11 +26,6 @@ where
let data = &payload.data;

let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone()));

chan_end_on_a.verify_counterparty_matches(&counterparty)?;

let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a);

Expand Down Expand Up @@ -75,32 +69,9 @@ where
);
let consensus_state_of_b_on_a =
client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?;
let port_id_on_b = chan_end_on_a.counterparty().port_id.clone();
let channel_id_on_b = chan_end_on_a
.counterparty()
.channel_id()
.ok_or(ChannelError::MissingCounterparty)?;
let expected_counterparty =
Counterparty::new(port_id_on_a.clone(), Some(channel_id_on_a.clone()));
let expected_chan_end_on_b = ChannelEnd::new(
State::Closed,
*chan_end_on_a.ordering(),
expected_counterparty,
chan_end_on_a.version().clone(),
)?;

let chan_end_path_on_b = ChannelEndPath(port_id_on_b.clone(), channel_id_on_b.clone());

// Verify the proof for the channel state against the expected channel end.
// A counterparty channel id of None in not possible, and is checked by validate_basic in msg.
client_state_of_b_on_a.verify_membership(
prefix_on_a,
&msg.proof_close_on_b,
consensus_state_of_b_on_a.root(),
Path::ChannelEnd(chan_end_path_on_b),
expected_chan_end_on_b.encode_vec(),
)?;

let next_seq_recv_verification_result = match chan_end_on_a.ordering {

Check failure on line 75 in ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `chan_end_on_a` in this scope

error[E0425]: cannot find value `chan_end_on_a` in this scope --> ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs:75:55 | 75 | let next_seq_recv_verification_result = match chan_end_on_a.ordering { | ^^^^^^^^^^^^^ help: a local variable with a similar name exists: `channel_id_on_a`
Order::Ordered => {

Check failure on line 76 in ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `Order`

error[E0433]: failed to resolve: use of undeclared type `Order` --> ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs:76:13 | 76 | Order::Ordered => { | ^^^^^ use of undeclared type `Order` | help: consider importing one of these enums | 1 + use crate::types::proto::v1::Order; | 1 + use ibc_eureka_core_channel_types::proto::v1::Order; |
if seq_on_a < &msg.next_seq_recv_on_b {
Expand Down
6 changes: 0 additions & 6 deletions ibc-eureka-core/ics04-channel/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use ibc_eureka_core_host_types::identifiers::Sequence;
use ibc_primitives::prelude::*;
use ibc_primitives::{Timestamp, TimestampError};

use super::channel::Counterparty;
use super::timeout::TimeoutHeight;
use crate::commitment::PacketCommitment;
use crate::timeout::TimeoutTimestamp;
Expand Down Expand Up @@ -51,11 +50,6 @@ pub enum ChannelError {
MissingCounterparty,
/// missing timeout
MissingTimeout,
/// mismatched counterparty: expected `{expected}`, actual `{actual}`
MismatchedCounterparty {
expected: Counterparty,
actual: Counterparty,
},
/// mismatched packet sequence: expected `{expected}`, actual `{actual}`
MismatchedPacketSequence {
expected: Sequence,
Expand Down
Loading

0 comments on commit bbef5ed

Please sign in to comment.