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

impl: new packet structure for eureka #1365

Open
wants to merge 5 commits into
base: rano/eureka/1367
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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 All @@ -16,189 +18,189 @@

use crate::handler::{pack_host_consensus_state, unpack_host_client_state};

pub fn validate<Ctx>(ctx_a: &Ctx, msg: MsgConnectionOpenAck) -> Result<(), ConnectionError>
where
Ctx: ValidationContext,
<Ctx::HostClientState as TryFrom<Any>>::Error: Into<ClientError>,
{
let vars = LocalVars::new(ctx_a, &msg)?;
validate_impl(ctx_a, &msg, &vars)
}

Check warning on line 28 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L21-L28

Added lines #L21 - L28 were not covered by tests

fn validate_impl<Ctx>(
ctx_a: &Ctx,
msg: &MsgConnectionOpenAck,
vars: &LocalVars,
) -> Result<(), ConnectionError>
where
Ctx: ValidationContext,
<Ctx::HostClientState as TryFrom<Any>>::Error: Into<ClientError>,
{
ctx_a.validate_message_signer(&msg.signer)?;

Check warning on line 39 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L30-L39

Added lines #L30 - L39 were not covered by tests

let host_height = ctx_a.host_height()?;

Check warning on line 41 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L41

Added line #L41 was not covered by tests

if msg.consensus_height_of_a_on_b > host_height {
return Err(ConnectionError::InsufficientConsensusHeight {
target_height: msg.consensus_height_of_a_on_b,
current_height: host_height,
});
}

let client_val_ctx_a = ctx_a.get_client_validation_context();

Check warning on line 50 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L43-L50

Added lines #L43 - L50 were not covered by tests

let client_state_of_a_on_b = unpack_host_client_state::<Ctx::HostClientState>(
msg.client_state_of_a_on_b.clone(),
vars.client_id_on_b(),
)?;

Check warning on line 55 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L52-L55

Added lines #L52 - L55 were not covered by tests

ctx_a.validate_self_client(client_state_of_a_on_b)?;

Check warning on line 57 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L57

Added line #L57 was not covered by tests

msg.version
.verify_is_supported(vars.conn_end_on_a.versions())?;

Check warning on line 60 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L59-L60

Added lines #L59 - L60 were not covered by tests

vars.conn_end_on_a.verify_state_matches(&State::Init)?;

Check warning on line 62 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L62

Added line #L62 was not covered by tests

// Proof verification.
{
let client_state_of_b_on_a = client_val_ctx_a.client_state(vars.client_id_on_a())?;

Check warning on line 66 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L66

Added line #L66 was not covered by tests

client_state_of_b_on_a
.status(client_val_ctx_a, vars.client_id_on_a())?
.verify_is_active()?;

Check warning on line 70 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L68-L70

Added lines #L68 - L70 were not covered by tests

client_state_of_b_on_a.validate_proof_height(msg.proofs_height_on_b)?;

Check warning on line 72 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L72

Added line #L72 was not covered by tests

let client_cons_state_path_on_a = ClientConsensusStatePath::new(
vars.client_id_on_a().clone(),
msg.proofs_height_on_b.revision_number(),
msg.proofs_height_on_b.revision_height(),
);

Check warning on line 78 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L74-L78

Added lines #L74 - L78 were not covered by tests

let consensus_state_of_b_on_a =
client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?;

Check warning on line 81 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L80-L81

Added lines #L80 - L81 were not covered by tests

let prefix_on_a = ctx_a.commitment_prefix();
let prefix_on_b = vars.conn_end_on_a.counterparty().prefix();

Check warning on line 84 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L83-L84

Added lines #L83 - L84 were not covered by tests

{
let expected_conn_end_on_b = ConnectionEnd::new(
State::TryOpen,
vars.client_id_on_b().clone(),
Counterparty::new(
vars.client_id_on_a().clone(),
Some(msg.conn_id_on_a.clone()),
prefix_on_a,
),
vec![msg.version.clone()],
vars.conn_end_on_a.delay_period(),
)?;

Check warning on line 97 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L87-L97

Added lines #L87 - L97 were not covered by tests

client_state_of_b_on_a.verify_membership(
prefix_on_b,
&msg.proof_conn_end_on_b,
consensus_state_of_b_on_a.root(),
Path::Connection(ConnectionPath::new(&msg.conn_id_on_b)),
expected_conn_end_on_b.encode_vec(),
)?;

Check warning on line 105 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L99-L105

Added lines #L99 - L105 were not covered by tests
}

client_state_of_b_on_a.verify_membership(
prefix_on_b,
&msg.proof_client_state_of_a_on_b,
consensus_state_of_b_on_a.root(),
Path::ClientState(ClientStatePath::new(vars.client_id_on_b().clone())),
msg.client_state_of_a_on_b.to_vec(),
)?;

Check warning on line 114 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L108-L114

Added lines #L108 - L114 were not covered by tests

let expected_consensus_state_of_a_on_b =
ctx_a.host_consensus_state(&msg.consensus_height_of_a_on_b)?;

Check warning on line 117 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L116-L117

Added lines #L116 - L117 were not covered by tests

let stored_consensus_state_of_a_on_b =
pack_host_consensus_state(expected_consensus_state_of_a_on_b, vars.client_id_on_b());

let client_cons_state_path_on_b = ClientConsensusStatePath::new(
vars.client_id_on_b().clone(),
msg.consensus_height_of_a_on_b.revision_number(),
msg.consensus_height_of_a_on_b.revision_height(),
);

client_state_of_b_on_a.verify_membership(
prefix_on_b,
&msg.proof_consensus_state_of_a_on_b,
consensus_state_of_b_on_a.root(),
Path::ClientConsensusState(client_cons_state_path_on_b),
stored_consensus_state_of_a_on_b.to_vec(),
)?;

Check warning on line 134 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L119-L134

Added lines #L119 - L134 were not covered by tests
}

Ok(())
}

Check warning on line 138 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L137-L138

Added lines #L137 - L138 were not covered by tests

pub fn execute<Ctx>(ctx_a: &mut Ctx, msg: MsgConnectionOpenAck) -> Result<(), ConnectionError>
where
Ctx: ExecutionContext,
{
let vars = LocalVars::new(ctx_a, &msg)?;
execute_impl(ctx_a, msg, vars)
}

Check warning on line 146 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L140-L146

Added lines #L140 - L146 were not covered by tests

fn execute_impl<Ctx>(
ctx_a: &mut Ctx,
msg: MsgConnectionOpenAck,
vars: LocalVars,
) -> Result<(), ConnectionError>
where
Ctx: ExecutionContext,
{
let event = IbcEvent::OpenAckConnection(OpenAck::new(
msg.conn_id_on_a.clone(),
vars.client_id_on_a().clone(),
msg.conn_id_on_b.clone(),
vars.client_id_on_b().clone(),
));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Connection))?;
ctx_a.emit_ibc_event(event)?;

Check warning on line 163 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L148-L163

Added lines #L148 - L163 were not covered by tests

ctx_a.log_message("success: conn_open_ack verification passed".to_string())?;

Check warning on line 165 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L165

Added line #L165 was not covered by tests

{
let new_conn_end_on_a = {
let mut counterparty = vars.conn_end_on_a.counterparty().clone();
counterparty.connection_id = Some(msg.conn_id_on_b.clone());

let mut new_conn_end_on_a = vars.conn_end_on_a;
new_conn_end_on_a.set_state(State::Open);
new_conn_end_on_a.set_version(msg.version.clone());
new_conn_end_on_a.set_counterparty(counterparty);
new_conn_end_on_a
};

ctx_a.store_connection(&ConnectionPath::new(&msg.conn_id_on_a), new_conn_end_on_a)?;

Check warning on line 179 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L168-L179

Added lines #L168 - L179 were not covered by tests
}

Ok(())
}

Check warning on line 183 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L182-L183

Added lines #L182 - L183 were not covered by tests

struct LocalVars {
conn_end_on_a: ConnectionEnd,
}

impl LocalVars {
fn new<Ctx>(ctx_a: &Ctx, msg: &MsgConnectionOpenAck) -> Result<Self, ConnectionError>
where
Ctx: ValidationContext,
{
Ok(LocalVars {
conn_end_on_a: ctx_a.connection_end(&msg.conn_id_on_a)?,

Check warning on line 195 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L190-L195

Added lines #L190 - L195 were not covered by tests
})
}

Check warning on line 197 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L197

Added line #L197 was not covered by tests

fn client_id_on_a(&self) -> &ClientId {
self.conn_end_on_a.client_id()
}

Check warning on line 201 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L199-L201

Added lines #L199 - L201 were not covered by tests

fn client_id_on_b(&self) -> &ClientId {
self.conn_end_on_a.counterparty().client_id()
}

Check warning on line 205 in ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs#L203-L205

Added lines #L203 - L205 were not covered by tests
}
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 @@ -16,188 +16,193 @@
use ibc_eureka_core_router::module::Module;
use ibc_primitives::prelude::*;

pub fn acknowledgement_packet_validate<ValCtx>(
ctx_a: &ValCtx,
module: &dyn Module,
msg: MsgAcknowledgement,
) -> Result<(), ChannelError>
where
ValCtx: ValidationContext,
{
validate(ctx_a, &msg)?;

Check warning on line 27 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#L19-L27

Added lines #L19 - L27 were not covered by tests

module.on_acknowledgement_packet_validate(&msg.packet, &msg.acknowledgement, &msg.signer)
}

Check warning on line 30 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#L29-L30

Added lines #L29 - L30 were not covered by tests

pub fn acknowledgement_packet_execute<ExecCtx>(
ctx_a: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgAcknowledgement,
) -> Result<(), ChannelError>
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];

// In all cases, this event is emitted
let event = IbcEvent::AcknowledgePacket(AcknowledgePacket::new(
msg.packet.clone(),
chan_end_on_a.ordering,
conn_id_on_a.clone(),
));
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
// This error indicates that the timeout has already been relayed
// or there is a misconfigured relayer attempting to prove a timeout
// for a packet never sent. Core IBC will treat this error as a no-op in order to
// prevent an entire relay transaction from failing and consuming unnecessary fees.
return Ok(());
};

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

cb_result?;

Check warning on line 74 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#L68-L74

Added lines #L68 - L74 were not covered by tests

// apply state changes
{
ctx_a.delete_packet_commitment(&commitment_path_on_a)?;

Check warning on line 78 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#L78

Added line #L78 was not covered by tests

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
}

// emit events and logs
{
ctx_a.log_message("success: packet acknowledgement".to_string())?;

Check warning on line 90 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#L90

Added line #L90 was not covered by tests

// Note: Acknowledgement event was emitted at the beginning

for module_event in extras.events {
ctx_a.emit_ibc_event(IbcEvent::Module(module_event))?

Check warning on line 95 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#L94-L95

Added lines #L94 - L95 were not covered by tests
}

for log_message in extras.log {
ctx_a.log_message(log_message)?;

Check warning on line 99 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#L98-L99

Added lines #L98 - L99 were not covered by tests
}
}

Ok(())
}

Check warning on line 104 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#L103-L104

Added lines #L103 - L104 were not covered by tests

fn validate<Ctx>(ctx_a: &Ctx, msg: &MsgAcknowledgement) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
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

let conn_id_on_a = &chan_end_on_a.connection_hops()[0];
let conn_end_on_a = ctx_a.connection_end(conn_id_on_a)?;

Check warning on line 132 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#L131-L132

Added lines #L131 - L132 were not covered by tests

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
// This error indicates that the timeout has already been relayed
// or there is a misconfigured relayer attempting to prove a timeout
// for a packet never sent. Core IBC will treat this error as a no-op in order to
// prevent an entire relay transaction from failing and consuming unnecessary fees.
return Ok(());

Check warning on line 144 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#L144

Added line #L144 was not covered by tests
};

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 {
return Err(ChannelError::MismatchedPacketCommitment {
actual: commitment_on_a,
expected: expected_commitment_on_a,
});
}

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,
});
}
}

Check warning on line 169 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#L147-L169

Added lines #L147 - L169 were not covered by tests

// Verify proofs
{
let client_id_on_a = conn_end_on_a.client_id();

let client_val_ctx_a = ctx_a.get_client_validation_context();

Check warning on line 175 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#L173-L175

Added lines #L173 - L175 were not covered by tests

let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?;

Check warning on line 177 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#L177

Added line #L177 was not covered by tests

client_state_of_b_on_a
.status(ctx_a.get_client_validation_context(), client_id_on_a)?
.verify_is_active()?;

Check warning on line 181 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#L179-L181

Added lines #L179 - L181 were not covered by tests

client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?;

Check warning on line 183 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#L183

Added line #L183 was not covered by tests

let client_cons_state_path_on_a = ClientConsensusStatePath::new(
client_id_on_a.clone(),
msg.proof_height_on_b.revision_number(),
msg.proof_height_on_b.revision_height(),
);
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

// Verify the proof for the packet against the chain store.
client_state_of_b_on_a.verify_membership(
conn_end_on_a.counterparty().prefix(),
&msg.proof_acked_on_b,
consensus_state_of_b_on_a.root(),
Path::Ack(ack_path_on_b),
ack_commitment.into_vec(),
)?;

Check warning on line 204 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#L198-L204

Added lines #L198 - L204 were not covered by tests
}

Ok(())
}

Check warning on line 208 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#L207-L208

Added lines #L207 - L208 were not covered by tests
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 All @@ -13,145 +15,145 @@
use ibc_primitives::prelude::*;
use ibc_primitives::proto::Protobuf;

pub fn chan_open_ack_validate<ValCtx>(
ctx_a: &ValCtx,
module: &dyn Module,
msg: MsgChannelOpenAck,
) -> Result<(), ChannelError>
where
ValCtx: ValidationContext,
{
validate(ctx_a, &msg)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L18-L26

Added lines #L18 - L26 were not covered by tests

module.on_chan_open_ack_validate(&msg.port_id_on_a, &msg.chan_id_on_a, &msg.version_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L28

Added line #L28 was not covered by tests

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L30-L31

Added lines #L30 - L31 were not covered by tests

pub fn chan_open_ack_execute<ExecCtx>(
ctx_a: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgChannelOpenAck,
) -> Result<(), ChannelError>
where
ExecCtx: ExecutionContext,
{
let extras =
module.on_chan_open_ack_execute(&msg.port_id_on_a, &msg.chan_id_on_a, &msg.version_on_b)?;
let chan_end_path_on_a = ChannelEndPath::new(&msg.port_id_on_a, &msg.chan_id_on_a);
let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L33 - L44 were not covered by tests

// state changes
{
let chan_end_on_a = {
let mut chan_end_on_a = chan_end_on_a.clone();

chan_end_on_a.set_state(State::Open);
chan_end_on_a.set_version(msg.version_on_b.clone());
chan_end_on_a.set_counterparty_channel_id(msg.chan_id_on_b.clone());

chan_end_on_a
};
ctx_a.store_channel(&chan_end_path_on_a, chan_end_on_a)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L48-L57

Added lines #L48 - L57 were not covered by tests
}

// emit events and logs
{
ctx_a.log_message("success: channel open ack".to_string())?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L62 was not covered by tests

let core_event = {
let port_id_on_b = chan_end_on_a.counterparty().port_id.clone();
let conn_id_on_a = chan_end_on_a.connection_hops[0].clone();

IbcEvent::OpenAckChannel(OpenAck::new(
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
port_id_on_b,
msg.chan_id_on_b,
conn_id_on_a,
))
};
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(core_event)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L64-L77

Added lines #L64 - L77 were not covered by tests

for module_event in extras.events {
ctx_a.emit_ibc_event(IbcEvent::Module(module_event))?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L79 - L80 were not covered by tests
}

for log_message in extras.log {
ctx_a.log_message(log_message)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L83-L84

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

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L88-L89

Added lines #L88 - L89 were not covered by tests

fn validate<Ctx>(ctx_a: &Ctx, msg: &MsgChannelOpenAck) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
ctx_a.validate_message_signer(&msg.signer)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L91 - L95 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L97-L98

Added lines #L97 - L98 were not covered by tests

// Validate that the channel end is in a state where it can be ack.
chan_end_on_a.verify_state_matches(&ChannelState::Init)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L101

Added line #L101 was not covered by tests

// An OPEN IBC connection running on the local (host) chain should exist.
chan_end_on_a.verify_connection_hops_length()?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L104

Added line #L104 was not covered by tests

let conn_end_on_a = ctx_a.connection_end(&chan_end_on_a.connection_hops()[0])?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L106 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L108

Added line #L108 was not covered by tests

// Verify proofs
{
let client_id_on_a = conn_end_on_a.client_id();
let client_val_ctx_a = ctx_a.get_client_validation_context();
let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L112-L114

Added lines #L112 - L114 were not covered by tests

client_state_of_b_on_a
.status(ctx_a.get_client_validation_context(), client_id_on_a)?
.verify_is_active()?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L116-L118

Added lines #L116 - L118 were not covered by tests

client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L120

Added line #L120 was not covered by tests

let client_cons_state_path_on_a = ClientConsensusStatePath::new(
client_id_on_a.clone(),
msg.proof_height_on_b.revision_number(),
msg.proof_height_on_b.revision_height(),
);
let consensus_state_of_b_on_a =
client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?;
let prefix_on_b = conn_end_on_a.counterparty().prefix();
let port_id_on_b = &chan_end_on_a.counterparty().port_id;
let conn_id_on_b = conn_end_on_a
.counterparty()
.connection_id()
.ok_or(ConnectionError::MissingCounterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L122 - L134 were not covered by tests

let expected_chan_end_on_b = ChannelEnd::new(
ChannelState::TryOpen,
// Note: Both ends of a channel must have the same ordering, so it's
// fine to use A's ordering here
*chan_end_on_a.ordering(),
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
vec![conn_id_on_b.clone()],
msg.version_on_b.clone(),
)?;
let chan_end_path_on_b = ChannelEndPath::new(port_id_on_b, &msg.chan_id_on_b);

// 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_b,
&msg.proof_chan_end_on_b,
consensus_state_of_b_on_a.root(),
Path::ChannelEnd(chan_end_path_on_b),
expected_chan_end_on_b.encode_vec(),
)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L136 - L155 were not covered by tests
}

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs#L158-L159

Added lines #L158 - L159 were not covered by tests
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 All @@ -14,147 +16,147 @@
use ibc_primitives::prelude::*;
use ibc_primitives::proto::Protobuf;

pub fn chan_open_confirm_validate<ValCtx>(
ctx_b: &ValCtx,
module: &dyn Module,
msg: MsgChannelOpenConfirm,
) -> Result<(), ChannelError>
where
ValCtx: ValidationContext,
{
validate(ctx_b, &msg)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L19 - L27 were not covered by tests

module.on_chan_open_confirm_validate(&msg.port_id_on_b, &msg.chan_id_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L29

Added line #L29 was not covered by tests

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L31-L32

Added lines #L31 - L32 were not covered by tests

pub fn chan_open_confirm_execute<ExecCtx>(
ctx_b: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgChannelOpenConfirm,
) -> Result<(), ChannelError>
where
ExecCtx: ExecutionContext,
{
let extras = module.on_chan_open_confirm_execute(&msg.port_id_on_b, &msg.chan_id_on_b)?;
let chan_end_path_on_b = ChannelEndPath::new(&msg.port_id_on_b, &msg.chan_id_on_b);
let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L34-L44

Added lines #L34 - L44 were not covered by tests

// state changes
{
let chan_end_on_b = {
let mut chan_end_on_b = chan_end_on_b.clone();
chan_end_on_b.set_state(State::Open);

chan_end_on_b
};
ctx_b.store_channel(&chan_end_path_on_b, chan_end_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L48-L54

Added lines #L48 - L54 were not covered by tests
}

// emit events and logs
{
ctx_b.log_message("success: channel open confirm".to_string())?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L59 was not covered by tests

let conn_id_on_b = chan_end_on_b.connection_hops[0].clone();
let port_id_on_a = chan_end_on_b.counterparty().port_id.clone();
let chan_id_on_a = chan_end_on_b
.counterparty()
.channel_id
.clone()
.ok_or(ChannelError::MissingCounterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L61-L67

Added lines #L61 - L67 were not covered by tests

let core_event = IbcEvent::OpenConfirmChannel(OpenConfirm::new(
msg.port_id_on_b.clone(),
msg.chan_id_on_b.clone(),
port_id_on_a,
chan_id_on_a,
conn_id_on_b,
));
ctx_b.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_b.emit_ibc_event(core_event)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L69-L77

Added lines #L69 - L77 were not covered by tests

for module_event in extras.events {
ctx_b.emit_ibc_event(IbcEvent::Module(module_event))?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L79 - L80 were not covered by tests
}

for log_message in extras.log {
ctx_b.log_message(log_message)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L83-L84

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

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L88-L89

Added lines #L88 - L89 were not covered by tests

fn validate<Ctx>(ctx_b: &Ctx, msg: &MsgChannelOpenConfirm) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
ctx_b.validate_message_signer(&msg.signer)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L91 - L95 were not covered by tests

// Unwrap the old channel end and validate it against the message.
let chan_end_path_on_b = ChannelEndPath::new(&msg.port_id_on_b, &msg.chan_id_on_b);
let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L98-L99

Added lines #L98 - L99 were not covered by tests

// Validate that the channel end is in a state where it can be confirmed.
chan_end_on_b.verify_state_matches(&ChannelState::TryOpen)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L102

Added line #L102 was not covered by tests

// An OPEN IBC connection running on the local (host) chain should exist.
chan_end_on_b.verify_connection_hops_length()?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L105

Added line #L105 was not covered by tests

let conn_end_on_b = ctx_b.connection_end(&chan_end_on_b.connection_hops()[0])?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L107

Added line #L107 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L109

Added line #L109 was not covered by tests

// Verify proofs
{
let client_id_on_b = conn_end_on_b.client_id();
let client_val_ctx_b = ctx_b.get_client_validation_context();
let client_state_of_a_on_b = client_val_ctx_b.client_state(client_id_on_b)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L113-L115

Added lines #L113 - L115 were not covered by tests

client_state_of_a_on_b
.status(ctx_b.get_client_validation_context(), client_id_on_b)?
.verify_is_active()?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L117-L119

Added lines #L117 - L119 were not covered by tests

client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L121

Added line #L121 was not covered by tests

let client_cons_state_path_on_b = ClientConsensusStatePath::new(
client_id_on_b.clone(),
msg.proof_height_on_a.revision_number(),
msg.proof_height_on_a.revision_height(),
);
let consensus_state_of_a_on_b =
client_val_ctx_b.consensus_state(&client_cons_state_path_on_b)?;
let prefix_on_a = conn_end_on_b.counterparty().prefix();
let port_id_on_a = &chan_end_on_b.counterparty().port_id;
let chan_id_on_a = chan_end_on_b
.counterparty()
.channel_id()
.ok_or(ChannelError::MissingCounterparty)?;
let conn_id_on_a = conn_end_on_b
.counterparty()
.connection_id()
.ok_or(ConnectionError::MissingCounterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L123 - L139 were not covered by tests

let expected_chan_end_on_a = ChannelEnd::new(
ChannelState::Open,
*chan_end_on_b.ordering(),
Counterparty::new(msg.port_id_on_b.clone(), Some(msg.chan_id_on_b.clone())),
vec![conn_id_on_a.clone()],
chan_end_on_b.version.clone(),
)?;
let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, chan_id_on_a);

// Verify the proof for the channel state against the expected channel end.
// A counterparty channel id of None in not possible, and is checked in msg.
client_state_of_a_on_b.verify_membership(
prefix_on_a,
&msg.proof_chan_end_on_a,
consensus_state_of_a_on_b.root(),
Path::ChannelEnd(chan_end_path_on_a),
expected_chan_end_on_a.encode_vec(),
)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L141-L158

Added lines #L141 - L158 were not covered by tests
}

Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs#L161-L162

Added lines #L161 - L162 were not covered by tests
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 @@ -12,124 +14,126 @@
use ibc_eureka_core_router::module::Module;
use ibc_primitives::prelude::*;

pub fn chan_open_init_validate<ValCtx>(
ctx_a: &ValCtx,
module: &dyn Module,
msg: MsgChannelOpenInit,
) -> Result<(), ChannelError>
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,
&msg.connection_hops_on_a,
&msg.port_id_on_a,
&chan_id_on_a,
&Counterparty::new(msg.port_id_on_b.clone(), None),
&msg.version_proposal,
)?;

Check warning on line 36 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#L29-L36

Added lines #L29 - L36 were not covered by tests

Ok(())
}

Check warning on line 39 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#L38-L39

Added lines #L38 - L39 were not covered by tests

pub fn chan_open_init_execute<ExecCtx>(
ctx_a: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgChannelOpenInit,
) -> Result<(), ChannelError>
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,
&msg.port_id_on_a,
&chan_id_on_a,
&Counterparty::new(msg.port_id_on_b.clone(), None),
&msg.version_proposal,
)?;

Check warning on line 58 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#L50-L58

Added lines #L50 - L58 were not covered by tests

let conn_id_on_a = msg.connection_hops_on_a[0].clone();

Check warning on line 60 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#L60

Added line #L60 was not covered by tests

// state changes
{
let chan_end_on_a = ChannelEnd::new(
State::Init,
msg.ordering,
Counterparty::new(msg.port_id_on_b.clone(), None),
msg.connection_hops_on_a.clone(),
msg.version_proposal.clone(),
)?;
let chan_end_path_on_a = ChannelEndPath::new(&msg.port_id_on_a, &chan_id_on_a);
ctx_a.store_channel(&chan_end_path_on_a, chan_end_on_a)?;

Check warning on line 72 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#L64-L72

Added lines #L64 - L72 were not covered by tests

ctx_a.increase_channel_counter()?;

Check warning on line 74 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#L74

Added line #L74 was not covered by tests

// Initialize send, recv, and ack sequence numbers.
let seq_send_path = SeqSendPath::new(&msg.port_id_on_a, &chan_id_on_a);
ctx_a.store_next_sequence_send(&seq_send_path, 1.into())?;

Check warning on line 78 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#L77-L78

Added lines #L77 - L78 were not covered by tests

let seq_recv_path = SeqRecvPath::new(&msg.port_id_on_a, &chan_id_on_a);
ctx_a.store_next_sequence_recv(&seq_recv_path, 1.into())?;

Check warning on line 81 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#L80-L81

Added lines #L80 - L81 were not covered by tests

let seq_ack_path = SeqAckPath::new(&msg.port_id_on_a, &chan_id_on_a);
ctx_a.store_next_sequence_ack(&seq_ack_path, 1.into())?;

Check warning on line 84 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#L83-L84

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

// emit events and logs
{
ctx_a.log_message(format!(
"success: channel open init with channel identifier: {chan_id_on_a}"
))?;
let core_event = IbcEvent::OpenInitChannel(OpenInit::new(
msg.port_id_on_a.clone(),
chan_id_on_a.clone(),
msg.port_id_on_b,
conn_id_on_a,
version,
));
ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_a.emit_ibc_event(core_event)?;

Check warning on line 100 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#L89-L100

Added lines #L89 - L100 were not covered by tests

for module_event in extras.events {
ctx_a.emit_ibc_event(IbcEvent::Module(module_event))?;

Check warning on line 103 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#L102-L103

Added lines #L102 - L103 were not covered by tests
}

for log_message in extras.log {
ctx_a.log_message(log_message)?;

Check warning on line 107 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#L106-L107

Added lines #L106 - L107 were not covered by tests
}
}

Ok(())
}

Check warning on line 112 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#L111-L112

Added lines #L111 - L112 were not covered by tests

fn validate<Ctx>(ctx_a: &Ctx, msg: &MsgChannelOpenInit) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
ctx_a.validate_message_signer(&msg.signer)?;

Check warning on line 118 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#L114-L118

Added lines #L114 - L118 were not covered by tests

msg.verify_connection_hops_length()?;

Check warning on line 120 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#L120

Added line #L120 was not covered by tests
// An IBC connection running on the local (host) chain should exist.
let conn_end_on_a = ctx_a.connection_end(&msg.connection_hops_on_a[0])?;

Check warning on line 122 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#L122

Added line #L122 was not covered by tests

// Note: Not needed check if the connection end is OPEN. Optimistic channel handshake is allowed.

let client_id_on_a = conn_end_on_a.client_id();
let client_val_ctx_a = ctx_a.get_client_validation_context();
let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?;

Check warning on line 128 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#L126-L128

Added lines #L126 - L128 were not covered by tests

client_state_of_b_on_a
.status(ctx_a.get_client_validation_context(), client_id_on_a)?
.verify_is_active()?;

Check warning on line 132 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#L130-L132

Added lines #L130 - L132 were not covered by tests

let conn_version = conn_end_on_a.versions();

conn_version[0].verify_feature_supported(msg.ordering.to_string())?;

Check warning on line 136 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#L134-L136

Added lines #L134 - L136 were not covered by tests

Ok(())
}

Check warning on line 139 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#L138-L139

Added lines #L138 - L139 were not covered by tests
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 All @@ -17,166 +19,168 @@
use ibc_primitives::prelude::*;
use ibc_primitives::proto::Protobuf;

pub fn chan_open_try_validate<ValCtx>(
ctx_b: &ValCtx,
module: &dyn Module,
msg: MsgChannelOpenTry,
) -> Result<(), ChannelError>
where
ValCtx: ValidationContext,
{
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,
&msg.connection_hops_on_b,
&msg.port_id_on_b,
&chan_id_on_b,
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
&msg.version_supported_on_a,
)?;

Check warning on line 42 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#L35-L42

Added lines #L35 - L42 were not covered by tests

Ok(())
}

Check warning on line 45 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#L44-L45

Added lines #L44 - L45 were not covered by tests

pub fn chan_open_try_execute<ExecCtx>(
ctx_b: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgChannelOpenTry,
) -> Result<(), ChannelError>
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,
&msg.port_id_on_b,
&chan_id_on_b,
&Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
&msg.version_supported_on_a,
)?;

Check warning on line 64 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#L56-L64

Added lines #L56 - L64 were not covered by tests

let conn_id_on_b = msg.connection_hops_on_b[0].clone();

Check warning on line 66 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#L66

Added line #L66 was not covered by tests

// state changes
{
let chan_end_on_b = ChannelEnd::new(
ChannelState::TryOpen,
msg.ordering,
Counterparty::new(msg.port_id_on_a.clone(), Some(msg.chan_id_on_a.clone())),
msg.connection_hops_on_b.clone(),
version.clone(),
)?;

Check warning on line 76 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#L70-L76

Added lines #L70 - L76 were not covered by tests

let chan_end_path_on_b = ChannelEndPath::new(&msg.port_id_on_b, &chan_id_on_b);
ctx_b.store_channel(&chan_end_path_on_b, chan_end_on_b)?;
ctx_b.increase_channel_counter()?;

Check warning on line 80 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#L78-L80

Added lines #L78 - L80 were not covered by tests

// Initialize send, recv, and ack sequence numbers.
let seq_send_path = SeqSendPath::new(&msg.port_id_on_b, &chan_id_on_b);
ctx_b.store_next_sequence_send(&seq_send_path, 1.into())?;

Check warning on line 84 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#L83-L84

Added lines #L83 - L84 were not covered by tests

let seq_recv_path = SeqRecvPath::new(&msg.port_id_on_b, &chan_id_on_b);
ctx_b.store_next_sequence_recv(&seq_recv_path, 1.into())?;

Check warning on line 87 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#L86-L87

Added lines #L86 - L87 were not covered by tests

let seq_ack_path = SeqAckPath::new(&msg.port_id_on_b, &chan_id_on_b);
ctx_b.store_next_sequence_ack(&seq_ack_path, 1.into())?;

Check warning on line 90 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#L89-L90

Added lines #L89 - L90 were not covered by tests
}

// emit events and logs
{
ctx_b.log_message(format!(
"success: channel open try with channel identifier: {chan_id_on_b}"
))?;

Check warning on line 97 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#L95-L97

Added lines #L95 - L97 were not covered by tests

let core_event = IbcEvent::OpenTryChannel(OpenTry::new(
msg.port_id_on_b.clone(),
chan_id_on_b.clone(),
msg.port_id_on_a.clone(),
msg.chan_id_on_a.clone(),
conn_id_on_b,
version,
));
ctx_b.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_b.emit_ibc_event(core_event)?;

Check warning on line 108 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#L99-L108

Added lines #L99 - L108 were not covered by tests

for module_event in extras.events {
ctx_b.emit_ibc_event(IbcEvent::Module(module_event))?;

Check warning on line 111 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#L110-L111

Added lines #L110 - L111 were not covered by tests
}

for log_message in extras.log {
ctx_b.log_message(log_message)?;

Check warning on line 115 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#L114-L115

Added lines #L114 - L115 were not covered by tests
}
}

Ok(())
}

Check warning on line 120 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#L119-L120

Added lines #L119 - L120 were not covered by tests

fn validate<Ctx>(ctx_b: &Ctx, msg: &MsgChannelOpenTry) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
ctx_b.validate_message_signer(&msg.signer)?;

Check warning on line 126 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#L122-L126

Added lines #L122 - L126 were not covered by tests

msg.verify_connection_hops_length()?;

Check warning on line 128 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#L128

Added line #L128 was not covered by tests

let conn_end_on_b = ctx_b.connection_end(&msg.connection_hops_on_b[0])?;

Check warning on line 130 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#L130

Added line #L130 was not covered by tests

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

Check warning on line 132 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#L132

Added line #L132 was not covered by tests

let conn_version = conn_end_on_b.versions();

conn_version[0].verify_feature_supported(msg.ordering.to_string())?;

Check warning on line 136 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#L134-L136

Added lines #L134 - L136 were not covered by tests

// Verify proofs
{
let client_id_on_b = conn_end_on_b.client_id();
let client_val_ctx_b = ctx_b.get_client_validation_context();
let client_state_of_a_on_b = client_val_ctx_b.client_state(client_id_on_b)?;

Check warning on line 142 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#L140-L142

Added lines #L140 - L142 were not covered by tests

client_state_of_a_on_b
.status(ctx_b.get_client_validation_context(), client_id_on_b)?
.verify_is_active()?;

Check warning on line 146 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#L144-L146

Added lines #L144 - L146 were not covered by tests

client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?;

Check warning on line 148 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#L148

Added line #L148 was not covered by tests

let client_cons_state_path_on_b = ClientConsensusStatePath::new(
client_id_on_b.clone(),
msg.proof_height_on_a.revision_number(),
msg.proof_height_on_a.revision_height(),
);
let consensus_state_of_a_on_b =
client_val_ctx_b.consensus_state(&client_cons_state_path_on_b)?;
let prefix_on_a = conn_end_on_b.counterparty().prefix();
let port_id_on_a = msg.port_id_on_a.clone();
let chan_id_on_a = msg.chan_id_on_a.clone();
let conn_id_on_a = conn_end_on_b
.counterparty()
.connection_id()
.ok_or(ConnectionError::MissingCounterparty)?;

Check warning on line 163 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#L150-L163

Added lines #L150 - L163 were not covered by tests

let expected_chan_end_on_a = ChannelEnd::new(
ChannelState::Init,
msg.ordering,
Counterparty::new(msg.port_id_on_b.clone(), None),
vec![conn_id_on_a.clone()],
msg.version_supported_on_a.clone(),
)?;
let chan_end_path_on_a = ChannelEndPath::new(&port_id_on_a, &chan_id_on_a);

// 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_a_on_b.verify_membership(
prefix_on_a,
&msg.proof_chan_end_on_a,
consensus_state_of_a_on_b.root(),
Path::ChannelEnd(chan_end_path_on_a),
expected_chan_end_on_a.encode_vec(),
)?;

Check warning on line 182 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#L165-L182

Added lines #L165 - L182 were not covered by tests
}

Ok(())
}

Check warning on line 186 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#L185-L186

Added lines #L185 - L186 were not covered by tests
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 @@ -18,227 +18,226 @@
use ibc_eureka_core_router::module::Module;
use ibc_primitives::prelude::*;

pub fn recv_packet_validate<ValCtx>(ctx_b: &ValCtx, msg: MsgRecvPacket) -> Result<(), ChannelError>
where
ValCtx: ValidationContext,
{
// Note: this contains the validation for `write_acknowledgement` as well.
validate(ctx_b, &msg)

// nothing to validate with the module, since `onRecvPacket` cannot fail.
// If any error occurs, then an "error acknowledgement" must be returned.
}

Check warning on line 30 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#L21-L30

Added lines #L21 - L30 were not covered by tests

pub fn recv_packet_execute<ExecCtx>(
ctx_b: &mut ExecCtx,
module: &mut dyn Module,
msg: MsgRecvPacket,
) -> Result<(), ChannelError>
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.
// We don't want to fail the transaction in this case.
{
let packet_already_received = match chan_end_on_b.ordering {

Check warning on line 53 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#L53

Added line #L53 was not covered by tests
// 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
}
};

if packet_already_received {
return Ok(());
}
}

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

// state changes
{
// `recvPacket` core handler state changes
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,
compute_ack_commitment(&acknowledgement),
)?;

Check warning on line 102 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#L97-L102

Added lines #L97 - L102 were not covered by tests
}

// emit events and logs
{
ctx_b.log_message("success: packet receive".to_string())?;
ctx_b.log_message("success: packet write acknowledgement".to_string())?;

Check warning on line 108 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#L107-L108

Added lines #L107 - L108 were not covered by tests

let conn_id_on_b = &chan_end_on_b.connection_hops()[0];
let event = IbcEvent::ReceivePacket(ReceivePacket::new(
msg.packet.clone(),
chan_end_on_b.ordering,
conn_id_on_b.clone(),
));
ctx_b.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_b.emit_ibc_event(event)?;
let event = IbcEvent::WriteAcknowledgement(WriteAcknowledgement::new(
msg.packet,
acknowledgement,
conn_id_on_b.clone(),
));
ctx_b.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?;
ctx_b.emit_ibc_event(event)?;

Check warning on line 124 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#L110-L124

Added lines #L110 - L124 were not covered by tests

for module_event in extras.events {
ctx_b.emit_ibc_event(IbcEvent::Module(module_event))?;

Check warning on line 127 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#L126-L127

Added lines #L126 - L127 were not covered by tests
}

for log_message in extras.log {
ctx_b.log_message(log_message)?;

Check warning on line 131 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#L130-L131

Added lines #L130 - L131 were not covered by tests
}
}

Ok(())
}

Check warning on line 136 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#L135-L136

Added lines #L135 - L136 were not covered by tests

fn validate<Ctx>(ctx_b: &Ctx, msg: &MsgRecvPacket) -> Result<(), ChannelError>
where
Ctx: ValidationContext,
{
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

let conn_id_on_b = &chan_end_on_b.connection_hops()[0];
let conn_end_on_b = ctx_b.connection_end(conn_id_on_b)?;

Check warning on line 164 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#L163-L164

Added lines #L163 - L164 were not covered by tests

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
{
return Err(ChannelError::ExpiredPacketTimestamp);
}

// Verify proofs
{
let client_id_on_b = conn_end_on_b.client_id();
let client_val_ctx_b = ctx_b.get_client_validation_context();
let client_state_of_a_on_b = client_val_ctx_b.client_state(client_id_on_b)?;

Check warning on line 189 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#L182-L189

Added lines #L182 - L189 were not covered by tests

client_state_of_a_on_b
.status(ctx_b.get_client_validation_context(), client_id_on_b)?
.verify_is_active()?;

Check warning on line 193 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#L191-L193

Added lines #L191 - L193 were not covered by tests

client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?;

Check warning on line 195 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#L195

Added line #L195 was not covered by tests

let client_cons_state_path_on_b = ClientConsensusStatePath::new(
client_id_on_b.clone(),
msg.proof_height_on_a.revision_number(),
msg.proof_height_on_a.revision_height(),
);

Check warning on line 201 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#L197-L201

Added lines #L197 - L201 were not covered by tests

let consensus_state_of_a_on_b =
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

// Verify the proof for the packet against the chain store.
client_state_of_a_on_b.verify_membership(
conn_end_on_b.counterparty().prefix(),
&msg.proof_commitment_on_a,
consensus_state_of_a_on_b.root(),
Path::Commitment(commitment_path_on_a),
expected_commitment_on_a.into_vec(),
)?;

Check warning on line 222 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#L216-L222

Added lines #L216 - L222 were not covered by tests
}

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

Check warning on line 240 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#L239-L240

Added lines #L239 - L240 were not covered by tests
}
Order::Unordered => {
// Note: We don't check for the packet receipt here because another
Expand All @@ -248,28 +247,34 @@

// Case where the recvPacket is successful and an
// acknowledgement will be written (not a no-op)
validate_write_acknowledgement(ctx_b, msg)?;

Check warning on line 250 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#L250

Added line #L250 was not covered by tests
}
Order::None => {
return Err(ChannelError::InvalidState {
expected: "Channel ordering to not be None".to_string(),
actual: chan_end_on_b.ordering.to_string(),
})

Check warning on line 256 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#L253-L256

Added lines #L253 - L256 were not covered by tests
}
}

Ok(())
}

Check warning on line 261 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#L260-L261

Added lines #L260 - L261 were not covered by tests

fn validate_write_acknowledgement<Ctx>(ctx_b: &Ctx, msg: &MsgRecvPacket) -> Result<(), ChannelError>
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(())
}

Check warning on line 280 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#L263-L280

Added lines #L263 - L280 were not covered by tests
Loading
Loading