Skip to content

Commit

Permalink
provide counterparty msg
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Oct 28, 2024
1 parent b9bfec1 commit c6d916b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ibc-eureka-core/ics02-client/context/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait ClientValidationContext: Sized {
fn counterparty_meta(
&self,
client_id: &ClientId,
) -> Result<(ClientId, CommitmentPrefix), HostError>;
) -> Result<Option<(ClientId, CommitmentPrefix)>, HostError>;
}

/// Defines the methods that all client `ExecutionContext`s (precisely the
Expand Down
1 change: 1 addition & 0 deletions ibc-eureka-core/ics02-client/src/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This module implements the processing logic for ICS2 (client abstractions and functions) msgs.

pub mod create_client;
pub mod provide_counterparty;
pub mod recover_client;
pub mod update_client;
pub mod upgrade_client;
57 changes: 57 additions & 0 deletions ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Protocol logic specific to processing ICS2 messages of type `MsgProvideCouterparty`.

use ibc_eureka_core_client_context::prelude::*;
use ibc_eureka_core_client_types::error::ClientError;
use ibc_eureka_core_client_types::msgs::MsgProvideCouterparty;
use ibc_eureka_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;

pub fn validate<Ctx>(ctx: &Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError>
where
Ctx: ValidationContext,
{
let MsgProvideCouterparty {
client_id, signer, ..
} = &msg;

ctx.validate_message_signer(signer)?;

Check warning on line 17 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L9-L17

Added lines #L9 - L17 were not covered by tests

let client_val_ctx = ctx.get_client_validation_context();

Check warning on line 19 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L19

Added line #L19 was not covered by tests

// Read client state from the host chain store. The client should already exist.
let client_state = client_val_ctx.client_state(client_id)?;

Check warning on line 22 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L22

Added line #L22 was not covered by tests

client_state
.status(client_val_ctx, client_id)?
.verify_is_active()?;

Check warning on line 26 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L24-L26

Added lines #L24 - L26 were not covered by tests

if client_val_ctx.counterparty_meta(client_id)?.is_some() {
return Err(ClientError::ClientSpecific {
description: "counterparty is already provided".into(),
});
}

Ok(())
}

Check warning on line 35 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L28-L35

Added lines #L28 - L35 were not covered by tests

pub fn execute<Ctx>(ctx: &mut Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError>
where
Ctx: ExecutionContext,
{
let MsgProvideCouterparty {
client_id,
counterparty_client_id,
counterparty_commitment_prefix,
..
} = &msg;

let client_exec_ctx = ctx.get_client_execution_context();

client_exec_ctx.store_counterparty_meta(
client_id,
counterparty_client_id,
counterparty_commitment_prefix,
)?;

Check warning on line 54 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L37-L54

Added lines #L37 - L54 were not covered by tests

Ok(())
}

Check warning on line 57 in ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/src/handler/provide_counterparty.rs#L56-L57

Added lines #L56 - L57 were not covered by tests
3 changes: 3 additions & 0 deletions ibc-eureka-core/ics02-client/types/src/msgs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use ibc_proto::google::protobuf::Any;

mod create_client;
mod misbehaviour;
mod provide_counterparty;
mod recover_client;
mod update_client;
mod upgrade_client;

pub use create_client::*;
pub use misbehaviour::*;
pub use provide_counterparty::*;
pub use recover_client::*;
pub use update_client::*;
pub use upgrade_client::*;
Expand All @@ -33,6 +35,7 @@ pub enum ClientMsg {
Misbehaviour(MsgSubmitMisbehaviour),
UpgradeClient(MsgUpgradeClient),
RecoverClient(MsgRecoverClient),
ProvideCounterparty(MsgProvideCouterparty),
}

pub enum MsgUpdateOrMisbehaviour {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Definition of domain type message `MsgProvideCouterparty`.

use ibc_eureka_core_commitment_types::commitment::CommitmentPrefix;
use ibc_eureka_core_host_types::identifiers::ClientId;
use ibc_primitives::prelude::*;
use ibc_primitives::Signer;

pub const _PROVIDE_COUNTERPARTY_TYPE_URL: &str = "/ibc.core.client.v1.MsgProvideCouterparty";

/// A type of message that links an on-chain (IBC) client to its counterparty.
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)

Check warning on line 13 in ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs#L13

Added line #L13 was not covered by tests
)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MsgProvideCouterparty {
pub client_id: ClientId,
pub counterparty_client_id: ClientId,
pub counterparty_commitment_prefix: CommitmentPrefix,
pub signer: Signer,
}

impl MsgProvideCouterparty {
pub fn new(
client_id: ClientId,
counterparty_client_id: ClientId,
counterparty_commitment_prefix: CommitmentPrefix,
signer: Signer,
) -> Self {
MsgProvideCouterparty {
client_id,
counterparty_client_id,
counterparty_commitment_prefix,
signer,
}
}

Check warning on line 37 in ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics02-client/types/src/msgs/provide_counterparty.rs#L25-L37

Added lines #L25 - L37 were not covered by tests
}
5 changes: 3 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ where

let client_val_ctx_a = ctx_a.get_client_validation_context();

Check warning on line 140 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#L121-L140

Added lines #L121 - L140 were not covered by tests

let (stored_id_source_client_on_target, target_prefix) =
client_val_ctx_a.counterparty_meta(id_target_client_on_source)?;
let (stored_id_source_client_on_target, target_prefix) = client_val_ctx_a
.counterparty_meta(id_target_client_on_source)?
.ok_or(ChannelError::MissingCounterparty)?;

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#L142-L144

Added lines #L142 - L144 were not covered by tests

if &stored_id_source_client_on_target != id_source_client_on_target {
return Err(ChannelError::MismatchCounterparty {
Expand Down
5 changes: 3 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ where

let client_val_ctx_b = ctx_b.get_client_validation_context();

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

Added lines #L138 - L146 were not covered by tests

let (stored_id_target_client_on_source, source_prefix) =
client_val_ctx_b.counterparty_meta(id_source_client_on_target)?;
let (stored_id_target_client_on_source, source_prefix) = client_val_ctx_b
.counterparty_meta(id_source_client_on_target)?
.ok_or(ChannelError::MissingCounterparty)?;

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

Added lines #L148 - L150 were not covered by tests

if &stored_id_target_client_on_source != id_target_client_on_source {
return Err(ChannelError::MismatchCounterparty {
Expand Down
5 changes: 3 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/send_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ pub fn send_packet_validate(
let id_target_client_on_source = channel_target_client_on_source.as_ref();
let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref();

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L33 - L43 were not covered by tests

let (stored_id_source_client_on_target, _) =
client_val_ctx_a.counterparty_meta(id_target_client_on_source)?;
let (stored_id_source_client_on_target, _) = client_val_ctx_a
.counterparty_meta(id_target_client_on_source)?
.ok_or(ChannelError::MissingCounterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/send_packet.rs#L45-L47

Added lines #L45 - L47 were not covered by tests

if &stored_id_source_client_on_target != id_source_client_on_target {
return Err(ChannelError::MismatchCounterparty {
Expand Down
5 changes: 3 additions & 2 deletions ibc-eureka-core/ics04-channel/src/handler/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ where

let client_val_ctx_a = ctx_a.get_client_validation_context();

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/timeout.rs#L113-L131

Added lines #L113 - L131 were not covered by tests

let (stored_id_source_client_on_target, target_prefix) =
client_val_ctx_a.counterparty_meta(id_target_client_on_source)?;
let (stored_id_source_client_on_target, target_prefix) = client_val_ctx_a
.counterparty_meta(id_target_client_on_source)?
.ok_or(ChannelError::MissingCounterparty)?;

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

View check run for this annotation

Codecov / codecov/patch

ibc-eureka-core/ics04-channel/src/handler/timeout.rs#L133-L135

Added lines #L133 - L135 were not covered by tests

if &stored_id_source_client_on_target != id_source_client_on_target {
return Err(ChannelError::MismatchCounterparty {
Expand Down
6 changes: 5 additions & 1 deletion ibc-eureka-core/ics25-handler/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use ibc_eureka_core_channel::handler::{
};
use ibc_eureka_core_channel::types::msgs::{packet_msg_to_port_id, PacketMsg};
use ibc_eureka_core_client::context::{ClientExecutionContext, ClientValidationContext};
use ibc_eureka_core_client::handler::{create_client, update_client, upgrade_client};
use ibc_eureka_core_client::handler::{
create_client, provide_counterparty, update_client, upgrade_client,
};
use ibc_eureka_core_client::types::error::ClientError;
use ibc_eureka_core_client::types::msgs::{ClientMsg, MsgUpdateOrMisbehaviour};
use ibc_eureka_core_handler_types::error::HandlerError;
Expand Down Expand Up @@ -60,6 +62,7 @@ where
// Recover client messages are not dispatched by ibc-rs as they can only be
// authorized via a passing governance proposal
}
ClientMsg::ProvideCounterparty(msg) => provide_counterparty::validate(ctx, msg)?,
},
MsgEnvelope::Packet(msg) => {
let port_id = packet_msg_to_port_id(&msg);
Expand Down Expand Up @@ -105,6 +108,7 @@ where
// Recover client messages are not dispatched by ibc-rs as they can only be
// authorized via a passing governance proposal
}
ClientMsg::ProvideCounterparty(msg) => provide_counterparty::execute(ctx, msg)?,
},
MsgEnvelope::Packet(msg) => {
let port_id = packet_msg_to_port_id(&msg);
Expand Down

0 comments on commit c6d916b

Please sign in to comment.