Skip to content

Commit

Permalink
refactor handler for new packet struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Oct 23, 2024
1 parent c53dc7c commit 416f410
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use ibc_eureka_core_connection_types::msgs::MsgConnectionOpenAck;
use ibc_eureka_core_connection_types::{ConnectionEnd, Counterparty, State};
use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_eureka_core_host::types::identifiers::ClientId;
use ibc_eureka_core_host::types::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path};
use ibc_eureka_core_host::types::path::{
ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path,
};
use ibc_eureka_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;
use ibc_primitives::proto::{Any, Protobuf};
Expand Down
55 changes: 30 additions & 25 deletions ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ pub fn acknowledgement_packet_execute<ExecCtx>(
where
ExecCtx: ExecutionContext,
{
let chan_end_path_on_a =
ChannelEndPath::new(&msg.packet.port_id_on_a, &msg.packet.chan_id_on_a);
let payload = &msg.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 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 conn_id_on_a = &chan_end_on_a.connection_hops()[0];

Expand All @@ -51,11 +56,8 @@ where
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(event)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L32-L57

Added lines #L32 - L57 were not covered by tests

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

// check if we're in the NO-OP case
if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L59-L63

Added lines #L59 - L63 were not covered by tests
Expand All @@ -78,9 +80,8 @@ where
if let Order::Ordered = chan_end_on_a.ordering {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L80

Added line #L80 was not covered by tests
// Note: in validation, we verified that `msg.packet.sequence == nextSeqRecv`
// (where `nextSeqRecv` is the value in the store)
let seq_ack_path_on_a =
SeqAckPath::new(&msg.packet.port_id_on_a, &msg.packet.chan_id_on_a);
ctx_a.store_next_sequence_ack(&seq_ack_path_on_a, msg.packet.seq_on_a.increment())?;
let seq_ack_path_on_a = SeqAckPath::new(port_id_on_a, channel_id_on_a);
ctx_a.store_next_sequence_ack(&seq_ack_path_on_a, (*seq_on_a).increment())?;
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L83-L85

Added lines #L83 - L85 were not covered by tests
}

Expand Down Expand Up @@ -109,15 +110,21 @@ where
ctx_a.validate_message_signer(&msg.signer)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L106-L110

Added lines #L106 - L110 were not covered by tests

let packet = &msg.packet;
let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a);
let payload = &packet.payloads[0];

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 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)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L112-L123

Added lines #L112 - L123 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L125

Added line #L125 was not covered by tests

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

chan_end_on_a.verify_counterparty_matches(&counterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L127-L129

Added lines #L127 - L129 were not covered by tests

Expand All @@ -126,8 +133,7 @@ where

conn_end_on_a.verify_state_matches(&ConnectionState::Open)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L134

Added line #L134 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L136

Added line #L136 was not covered by tests

// Verify packet commitment
let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L139

Added line #L139 was not covered by tests
Expand All @@ -139,9 +145,9 @@ where
};

let expected_commitment_on_a = compute_packet_commitment(
&packet.data,
&packet.timeout_height_on_b,
&packet.timeout_timestamp_on_b,
data,
&packet.header.timeout_height_on_b,
&packet.header.timeout_timestamp_on_b,
);

if commitment_on_a != expected_commitment_on_a {
Expand All @@ -152,11 +158,11 @@ where
}

if let Order::Ordered = chan_end_on_a.ordering {
let seq_ack_path_on_a = SeqAckPath::new(&packet.port_id_on_a, &packet.chan_id_on_a);
let seq_ack_path_on_a = SeqAckPath::new(port_id_on_a, channel_id_on_a);
let next_seq_ack = ctx_a.get_next_sequence_ack(&seq_ack_path_on_a)?;
if packet.seq_on_a != next_seq_ack {
if seq_on_a != &next_seq_ack {
return Err(ChannelError::MismatchedPacketSequence {
actual: packet.seq_on_a,
actual: *seq_on_a,
expected: next_seq_ack,
});
}
Expand Down Expand Up @@ -184,8 +190,7 @@ where
let consensus_state_of_b_on_a =
client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?;
let ack_commitment = compute_ack_commitment(&msg.acknowledgement);
let ack_path_on_b =
AckPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a);
let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a);

verify_conn_delay_passed(ctx_a, msg.proof_height_on_b, &conn_end_on_a)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs#L185-L195

Added lines #L185 - L195 were not covered by tests

Expand Down
4 changes: 3 additions & 1 deletion ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Protocol logic specific to ICS4 messages of type `MsgChannelOpenAck`.
use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State, State as ChannelState};
use ibc_eureka_core_channel_types::channel::{
ChannelEnd, Counterparty, State, State as ChannelState,
};
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::OpenAck;
use ibc_eureka_core_channel_types::msgs::MsgChannelOpenAck;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Protocol logic specific to ICS4 messages of type `MsgChannelOpenConfirm`.
use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State, State as ChannelState};
use ibc_eureka_core_channel_types::channel::{
ChannelEnd, Counterparty, State, State as ChannelState,
};
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::OpenConfirm;
use ibc_eureka_core_channel_types::msgs::MsgChannelOpenConfirm;
Expand Down
8 changes: 6 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Protocol logic specific to ICS4 messages of type `MsgChannelOpenInit`.
use core::str::FromStr;

use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State};
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::OpenInit;
Expand All @@ -21,7 +23,8 @@ where
ValCtx: ValidationContext,
{
validate(ctx_a, &msg)?;

Check warning on line 25 in ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs#L17-L25

Added lines #L17 - L25 were not covered by tests
let chan_id_on_a = ChannelId::new(ctx_a.channel_counter()?);
// todo(rano): hack
let chan_id_on_a = ChannelId::from_str("00-dummy-0")?;

Check warning on line 27 in ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs#L27

Added line #L27 was not covered by tests

module.on_chan_open_init_validate(
msg.ordering,
Expand All @@ -43,7 +46,8 @@ pub fn chan_open_init_execute<ExecCtx>(
where
ExecCtx: ExecutionContext,
{

Check warning on line 48 in ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs#L41-L48

Added lines #L41 - L48 were not covered by tests
let chan_id_on_a = ChannelId::new(ctx_a.channel_counter()?);
// todo(rano): hack
let chan_id_on_a = ChannelId::from_str("00-dummy-0")?;
let (extras, version) = module.on_chan_open_init_execute(
msg.ordering,
&msg.connection_hops_on_a,
Expand Down
8 changes: 6 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Protocol logic specific to ICS4 messages of type `MsgChannelOpenTry`.
use core::str::FromStr;

use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State as ChannelState};
use ibc_eureka_core_channel_types::error::ChannelError;
use ibc_eureka_core_channel_types::events::OpenTry;
Expand Down Expand Up @@ -27,7 +29,8 @@ where
{
validate(ctx_b, &msg)?;

Check warning on line 30 in ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs#L22-L30

Added lines #L22 - L30 were not covered by tests

let chan_id_on_b = ChannelId::new(ctx_b.channel_counter()?);
// todo(rano): hack
let chan_id_on_b = ChannelId::from_str("00-dummy-0")?;

Check warning on line 33 in ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs#L33

Added line #L33 was not covered by tests

module.on_chan_open_try_validate(
msg.ordering,
Expand All @@ -49,7 +52,8 @@ pub fn chan_open_try_execute<ExecCtx>(
where
ExecCtx: ExecutionContext,
{

Check warning on line 54 in ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs#L47-L54

Added lines #L47 - L54 were not covered by tests
let chan_id_on_b = ChannelId::new(ctx_b.channel_counter()?);
// todo(rano): hack
let chan_id_on_b = ChannelId::from_str("00-dummy-0")?;
let (extras, version) = module.on_chan_open_try_execute(
msg.ordering,
&msg.connection_hops_on_b,
Expand Down
93 changes: 49 additions & 44 deletions ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ pub fn recv_packet_execute<ExecCtx>(
where
ExecCtx: ExecutionContext,
{
let chan_end_path_on_b =
ChannelEndPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
let packet = &msg.packet;
let payload = &packet.payloads[0];

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_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 warning on line 48 in ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L32-L48

Added lines #L32 - L48 were not covered by tests

// Check if another relayer already relayed the packet.
Expand All @@ -48,19 +54,16 @@ where
// Note: ibc-go doesn't make the check for `Order::None` channels
Order::None => false,

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L55

Added line #L55 was not covered by tests
Order::Unordered => {
let packet = &msg.packet;
let receipt_path_on_b =
ReceiptPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a);
let receipt_path_on_b = ReceiptPath::new(port_id_on_b, channel_id_on_b, *seq_on_a);
ctx_b.get_packet_receipt(&receipt_path_on_b)?.is_ok()

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L57-L58

Added lines #L57 - L58 were not covered by tests
}
Order::Ordered => {
let seq_recv_path_on_b =
SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b);
let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L61-L62

Added lines #L61 - L62 were not covered by tests

// the sequence number has already been incremented, so
// another relayer already relayed the packet
msg.packet.seq_on_a < next_seq_recv
seq_on_a < &next_seq_recv

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L66

Added line #L66 was not covered by tests
}
};

Expand All @@ -77,26 +80,21 @@ where
match chan_end_on_b.ordering {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L70-L80

Added lines #L70 - L80 were not covered by tests
Order::Unordered => {
let receipt_path_on_b = ReceiptPath {
port_id: msg.packet.port_id_on_b.clone(),
channel_id: msg.packet.chan_id_on_b.clone(),
sequence: msg.packet.seq_on_a,
port_id: port_id_on_b.clone(),
channel_id: channel_id_on_b.clone(),
sequence: *seq_on_a,
};

ctx_b.store_packet_receipt(&receipt_path_on_b, Receipt::Ok)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L82-L88

Added lines #L82 - L88 were not covered by tests
}
Order::Ordered => {
let seq_recv_path_on_b =
SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b);
let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?;
ctx_b.store_next_sequence_recv(&seq_recv_path_on_b, next_seq_recv.increment())?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L91-L93

Added lines #L91 - L93 were not covered by tests
}
_ => {}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L95

Added line #L95 was not covered by tests
}
let ack_path_on_b = AckPath::new(
&msg.packet.port_id_on_b,
&msg.packet.chan_id_on_b,
msg.packet.seq_on_a,
);
let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a);
// `writeAcknowledgement` handler state changes
ctx_b.store_packet_acknowledgement(
&ack_path_on_b,
Expand Down Expand Up @@ -143,16 +141,22 @@ where
{
ctx_b.validate_message_signer(&msg.signer)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L138-L142

Added lines #L138 - L142 were not covered by tests

let chan_end_path_on_b =
ChannelEndPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
let packet = &msg.packet;
let payload = &packet.payloads[0];

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 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)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L144-L155

Added lines #L144 - L155 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L157

Added line #L157 was not covered by tests

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

chan_end_on_b.verify_counterparty_matches(&counterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L159-L161

Added lines #L159 - L161 were not covered by tests

Expand All @@ -162,16 +166,16 @@ where
conn_end_on_b.verify_state_matches(&ConnectionState::Open)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L166

Added line #L166 was not covered by tests

let latest_height = ctx_b.host_height()?;
if msg.packet.timeout_height_on_b.has_expired(latest_height) {
if packet.header.timeout_height_on_b.has_expired(latest_height) {
return Err(ChannelError::InsufficientPacketHeight {
chain_height: latest_height,
timeout_height: msg.packet.timeout_height_on_b,
timeout_height: packet.header.timeout_height_on_b,
});
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L168-L174

Added lines #L168 - L174 were not covered by tests

let latest_timestamp = ctx_b.host_timestamp()?;
if msg
.packet
if packet
.header
.timeout_timestamp_on_b
.has_expired(&latest_timestamp)

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L176-L180

Added lines #L176 - L180 were not covered by tests
{
Expand Down Expand Up @@ -200,15 +204,11 @@ where
client_val_ctx_b.consensus_state(&client_cons_state_path_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L203-L204

Added lines #L203 - L204 were not covered by tests

let expected_commitment_on_a = compute_packet_commitment(
&msg.packet.data,
&msg.packet.timeout_height_on_b,
&msg.packet.timeout_timestamp_on_b,
);
let commitment_path_on_a = CommitmentPath::new(
&msg.packet.port_id_on_a,
&msg.packet.chan_id_on_a,
msg.packet.seq_on_a,
data,
&packet.header.timeout_height_on_b,
&packet.header.timeout_timestamp_on_b,
);
let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a);

verify_conn_delay_passed(ctx_b, msg.proof_height_on_a, &conn_end_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L206-L213

Added lines #L206 - L213 were not covered by tests

Expand All @@ -224,17 +224,16 @@ where

match chan_end_on_b.ordering {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L225

Added line #L225 was not covered by tests
Order::Ordered => {
let seq_recv_path_on_b =
SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b);
let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b);
let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?;
if msg.packet.seq_on_a > next_seq_recv {
if seq_on_a > &next_seq_recv {
return Err(ChannelError::MismatchedPacketSequence {
actual: msg.packet.seq_on_a,
actual: *seq_on_a,
expected: next_seq_recv,
});
}

if msg.packet.seq_on_a == next_seq_recv {
if seq_on_a == &next_seq_recv {

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs#L227-L236

Added lines #L227 - L236 were not covered by tests
// Case where the recvPacket is successful and an
// acknowledgement will be written (not a no-op)
validate_write_acknowledgement(ctx_b, msg)?;
Expand Down Expand Up @@ -265,10 +264,16 @@ fn validate_write_acknowledgement<Ctx>(ctx_b: &Ctx, msg: &MsgRecvPacket) -> Resu
where
Ctx: ValidationContext,
{
let packet = msg.packet.clone();
let ack_path_on_b = AckPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a);
let packet = &msg.packet;
let payload = &packet.payloads[0];

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 ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a);
if ctx_b.get_packet_acknowledgement(&ack_path_on_b).is_ok() {
return Err(ChannelError::DuplicateAcknowledgment(msg.packet.seq_on_a));
return Err(ChannelError::DuplicateAcknowledgment(*seq_on_a));
}

Ok(())
Expand Down
Loading

0 comments on commit 416f410

Please sign in to comment.