Skip to content

Commit

Permalink
Implement CanBootstrapChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Dec 18, 2024
1 parent 1005bcd commit 80ef98f
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 8 deletions.
14 changes: 11 additions & 3 deletions relayer/crates/starknet-chain-components/src/components/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ use crate::impls::contract::deploy::DeployStarknetContract;
use crate::impls::contract::invoke::InvokeStarknetContract;
use crate::impls::contract::message::BuildInvokeContractCall;
use crate::impls::counterparty_message_height::GetCounterpartyCosmosHeightFromStarknetMessage;
use crate::impls::events::connection_id::UseStarknetConnectionHandshakeEvents;
use crate::impls::events::channel::UseStarknetChannelEvents;
use crate::impls::events::connection_id::UseStarknetConnectionEvents;
use crate::impls::events::create_client::UseStarknetCreateClientEvent;
use crate::impls::messages::channel::BuildStarknetChannelHandshakeMessages;
use crate::impls::messages::connection::BuildStarknetConnectionHandshakeMessages;
Expand Down Expand Up @@ -142,8 +143,9 @@ cgp_preset! {
ContractClassHashTypeComponent,
]:
ProvideStarknetContractTypes,
// FIXME: we may have to define our own chain types,
// or implement Cairo encoding for the Cosmos types
[
ChannelIdTypeComponent,
PortIdTypeComponent,
SequenceTypeComponent,
OutgoingPacketTypeComponent,
Expand All @@ -154,6 +156,7 @@ cgp_preset! {
[
ClientIdTypeComponent,
ConnectionIdTypeComponent,
ChannelIdTypeComponent,
ConnectionEndTypeComponent,
ChannelEndTypeComponent,
]:
Expand Down Expand Up @@ -221,7 +224,12 @@ cgp_preset! {
ConnectionOpenInitEventComponent,
ConnectionOpenTryEventComponent,
]:
UseStarknetConnectionHandshakeEvents,
UseStarknetConnectionEvents,
[
ChannelOpenInitEventComponent,
ChannelOpenTryEventComponent,
]:
UseStarknetChannelEvents,
CreateClientMessageOptionsTypeComponent:
ProvideNoCreateClientMessageOptionsType,
CreateClientPayloadBuilderComponent:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use cgp::prelude::*;
use hermes_cosmos_chain_components::components::client::{
ChannelEndTypeComponent, ClientIdTypeComponent, ConnectionEndTypeComponent,
ConnectionIdTypeComponent,
ChannelEndTypeComponent, ChannelIdTypeComponent, ClientIdTypeComponent,
ConnectionEndTypeComponent, ConnectionIdTypeComponent,
};

use crate::types::channel_end::ChannelEnd;
use crate::types::channel_id::ChannelId;
use crate::types::client_id::ClientId;
use crate::types::connection_id::{ConnectionEnd, ConnectionId};

cgp_preset! {
StarknetChainTypes {
ClientIdTypeComponent: ClientId,
ConnectionIdTypeComponent: ConnectionId,
ChannelIdTypeComponent: ChannelId,
ConnectionEndTypeComponent: ConnectionEnd,
ChannelEndTypeComponent: ChannelEnd,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use hermes_cairo_encoding_components::strategy::ViaCairo;
use hermes_cairo_encoding_components::types::as_felt::AsFelt;
use hermes_chain_components::traits::types::ibc::HasChannelIdType;
use hermes_chain_components::traits::types::ibc_events::channel::{
ProvideChannelOpenInitEvent, ProvideChannelOpenTryEvent,
};
use hermes_chain_type_components::traits::types::message_response::HasMessageResponseType;
use hermes_encoding_components::traits::decode::CanDecode;
use hermes_encoding_components::traits::has_encoding::HasDefaultEncoding;
use hermes_encoding_components::traits::types::encoded::HasEncodedType;
use starknet::core::types::Felt;

use crate::types::channel_id::ChannelId;
use crate::types::message_response::StarknetMessageResponse;

pub struct UseStarknetChannelEvents;

impl<Chain, Counterparty, Encoding> ProvideChannelOpenInitEvent<Chain, Counterparty>
for UseStarknetChannelEvents
where
Chain: HasMessageResponseType<MessageResponse = StarknetMessageResponse>
+ HasChannelIdType<Counterparty, ChannelId = ChannelId>
+ HasDefaultEncoding<AsFelt, Encoding = Encoding>,
Encoding: HasEncodedType<Encoded = Vec<Felt>> + CanDecode<ViaCairo, ChannelId>,
{
type ChannelOpenInitEvent = ChannelId;

fn try_extract_channel_open_init_event(
response: &StarknetMessageResponse,
) -> Option<ChannelId> {
Chain::default_encoding().decode(&response.result).ok()
}

fn channel_open_init_event_channel_id(channel_id: &ChannelId) -> &ChannelId {
channel_id
}
}

impl<Chain, Counterparty, Encoding> ProvideChannelOpenTryEvent<Chain, Counterparty>
for UseStarknetChannelEvents
where
Chain: HasMessageResponseType<MessageResponse = StarknetMessageResponse>
+ HasChannelIdType<Counterparty, ChannelId = ChannelId>
+ HasDefaultEncoding<AsFelt, Encoding = Encoding>,
Encoding: HasEncodedType<Encoded = Vec<Felt>> + CanDecode<ViaCairo, ChannelId>,
{
type ChannelOpenTryEvent = ChannelId;

fn try_extract_channel_open_try_event(response: &StarknetMessageResponse) -> Option<ChannelId> {
Chain::default_encoding().decode(&response.result).ok()
}

fn channel_open_try_event_channel_id(channel_id: &ChannelId) -> &ChannelId {
channel_id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use starknet::core::types::Felt;
use crate::types::connection_id::ConnectionId;
use crate::types::message_response::StarknetMessageResponse;

pub struct UseStarknetConnectionHandshakeEvents;
pub struct UseStarknetConnectionEvents;

impl<Chain, Counterparty, Encoding> ProvideConnectionOpenInitEvent<Chain, Counterparty>
for UseStarknetConnectionHandshakeEvents
for UseStarknetConnectionEvents
where
Chain: HasMessageResponseType<MessageResponse = StarknetMessageResponse>
+ HasConnectionIdType<Counterparty, ConnectionId = ConnectionId>
Expand All @@ -37,7 +37,7 @@ where
}

impl<Chain, Counterparty, Encoding> ProvideConnectionOpenTryEvent<Chain, Counterparty>
for UseStarknetConnectionHandshakeEvents
for UseStarknetConnectionEvents
where
Chain: HasMessageResponseType<MessageResponse = StarknetMessageResponse>
+ HasConnectionIdType<Counterparty, ConnectionId = ConnectionId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod channel;
pub mod connection_id;
pub mod create_client;
2 changes: 2 additions & 0 deletions relayer/crates/starknet-chain-context/src/contexts/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use hermes_relayer_components::chain::traits::types::event::HasEventType;
use hermes_relayer_components::chain::traits::types::ibc::{
HasClientIdType, HasConnectionIdType, HasCounterpartyMessageHeight,
};
use hermes_relayer_components::chain::traits::types::ibc_events::channel::HasChannelOpenTryEvent;
use hermes_relayer_components::chain::traits::types::ibc_events::connection::HasConnectionOpenTryEvent;
use hermes_relayer_components::chain::traits::types::packet::HasOutgoingPacketType;
use hermes_relayer_components::chain::traits::types::update_client::HasUpdateClientPayloadType;
Expand Down Expand Up @@ -301,6 +302,7 @@ pub trait CanUseStarknetChain:
+ CanBuildChannelOpenAckMessage<CosmosChain>
+ CanBuildChannelOpenConfirmMessage<CosmosChain>
+ HasConnectionOpenTryEvent<CosmosChain>
+ HasChannelOpenTryEvent<CosmosChain>
+ CanQueryContractAddress<symbol!("ibc_client_contract_address")>
+ CanQueryContractAddress<symbol!("ibc_core_contract_address")>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ use hermes_relayer_components::multi::traits::chain_at::{
};
use hermes_relayer_components::multi::traits::client_id_at::ClientIdAtGetterComponent;
use hermes_relayer_components::multi::types::tags::{Dst, Src};
use hermes_relayer_components::relay::impls::channel::bootstrap::CanBootstrapChannel;
use hermes_relayer_components::relay::impls::connection::bootstrap::CanBootstrapConnection;
use hermes_relayer_components::relay::impls::selector::SelectRelayAToB;
use hermes_relayer_components::relay::traits::chains::{
CanRaiseRelayChainErrors, HasRelayChains, HasRelayClientIds,
};
use hermes_relayer_components::relay::traits::channel::open_ack::CanRelayChannelOpenAck;
use hermes_relayer_components::relay::traits::channel::open_confirm::CanRelayChannelOpenConfirm;
use hermes_relayer_components::relay::traits::channel::open_try::CanRelayChannelOpenTry;
use hermes_relayer_components::relay::traits::client_creator::CanCreateClient;
use hermes_relayer_components::relay::traits::connection::open_ack::CanRelayConnectionOpenAck;
use hermes_relayer_components::relay::traits::connection::open_confirm::CanRelayConnectionOpenConfirm;
Expand Down Expand Up @@ -139,6 +143,10 @@ pub trait CanUseCosmosToStarknetRelay:
+ CanRelayConnectionOpenAck
+ CanRelayConnectionOpenConfirm
+ CanBootstrapConnection
+ CanRelayChannelOpenTry
+ CanRelayChannelOpenAck
+ CanRelayChannelOpenConfirm
+ CanBootstrapChannel
{
}

Expand Down
6 changes: 6 additions & 0 deletions relayer/crates/starknet-relayer/src/impls/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use hermes_error::traits::wrap::WrapError;
use hermes_error::types::Error;
use hermes_relayer_components::chain::traits::send_message::EmptyMessageResponse;
use hermes_relayer_components::chain::traits::types::chain_id::HasChainIdType;
use hermes_relayer_components::relay::impls::channel::open_init::MissingChannelInitEventError;
use hermes_relayer_components::relay::impls::channel::open_try::MissingChannelTryEventError;
use hermes_relayer_components::relay::impls::connection::open_init::MissingConnectionInitEventError;
use hermes_relayer_components::relay::impls::connection::open_try::MissingConnectionTryEventError;
use hermes_relayer_components::relay::impls::create_client::MissingCreateClientEventError;
Expand Down Expand Up @@ -45,6 +47,10 @@ delegate_components! {
MissingConnectionInitEventError<'a, Relay>,
<'a, Relay: HasRelayChains>
MissingConnectionTryEventError<'a, Relay>,
<'a, Relay>
MissingChannelInitEventError<'a, Relay>,
<'a, Relay: HasRelayChains>
MissingChannelTryEventError<'a, Relay>,
]:
DebugError,
[
Expand Down

0 comments on commit 80ef98f

Please sign in to comment.