-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic IBC channel handshake in relayer-next (#3463)
* Implement channel Init step * Implement Channel handshake TRY step for relayer-next * Implement channel ack step for relayer-next * Fix merge error * Implement channel handshake confirm step for relayer-next * Implement channel handshake for relayer-next * Add docstring to channel handshake steps implementation * Minor touch up --------- Co-authored-by: Soares Chen <[email protected]>
- Loading branch information
1 parent
612ed64
commit 6251577
Showing
36 changed files
with
1,599 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
crates/relayer-all-in-one/src/one_for_all/impls/chain/channel.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
use async_trait::async_trait; | ||
|
||
use ibc_relayer_components::chain::traits::message_builders::channel::{ | ||
CanBuildChannelHandshakeMessages, CanBuildChannelHandshakePayloads, | ||
}; | ||
use ibc_relayer_components::chain::traits::types::channel::{ | ||
HasChannelHandshakePayloads, HasInitChannelOptionsType, | ||
}; | ||
use ibc_relayer_components::chain::traits::types::ibc_events::channel::{ | ||
HasChannelOpenInitEvent, HasChannelOpenTryEvent, | ||
}; | ||
|
||
use crate::one_for_all::traits::chain::OfaIbcChain; | ||
use crate::one_for_all::types::chain::OfaChainWrapper; | ||
use crate::std_prelude::*; | ||
|
||
impl<Chain, Counterparty> HasChannelHandshakePayloads<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
type ChannelOpenTryPayload = Chain::ChannelOpenTryPayload; | ||
|
||
type ChannelOpenAckPayload = Chain::ChannelOpenAckPayload; | ||
|
||
type ChannelOpenConfirmPayload = Chain::ChannelOpenConfirmPayload; | ||
} | ||
|
||
impl<Chain, Counterparty> HasInitChannelOptionsType<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
type InitChannelOptions = Chain::InitChannelOptions; | ||
} | ||
|
||
impl<Chain, Counterparty> HasChannelOpenInitEvent<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
type ChannelOpenInitEvent = Chain::ChannelOpenInitEvent; | ||
|
||
fn try_extract_channel_open_init_event( | ||
event: Chain::Event, | ||
) -> Option<Chain::ChannelOpenInitEvent> { | ||
Chain::try_extract_channel_open_init_event(event) | ||
} | ||
|
||
fn channel_open_init_event_channel_id( | ||
event: &Chain::ChannelOpenInitEvent, | ||
) -> &Chain::ChannelId { | ||
Chain::channel_open_init_event_channel_id(event) | ||
} | ||
} | ||
|
||
impl<Chain, Counterparty> HasChannelOpenTryEvent<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
type ChannelOpenTryEvent = Chain::ChannelOpenTryEvent; | ||
|
||
fn try_extract_channel_open_try_event( | ||
event: Chain::Event, | ||
) -> Option<Chain::ChannelOpenTryEvent> { | ||
Chain::try_extract_channel_open_try_event(event) | ||
} | ||
|
||
fn channel_open_try_event_channel_id(event: &Chain::ChannelOpenTryEvent) -> &Chain::ChannelId { | ||
Chain::channel_open_try_event_channel_id(event) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Chain, Counterparty> CanBuildChannelHandshakePayloads<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
async fn build_channel_open_try_payload( | ||
&self, | ||
height: &Self::Height, | ||
port_id: &Self::PortId, | ||
channel_id: &Self::ChannelId, | ||
) -> Result<Self::ChannelOpenTryPayload, Self::Error> { | ||
self.chain | ||
.build_channel_open_try_payload(height, port_id, channel_id) | ||
.await | ||
} | ||
|
||
async fn build_channel_open_ack_payload( | ||
&self, | ||
height: &Self::Height, | ||
port_id: &Self::PortId, | ||
channel_id: &Self::ChannelId, | ||
) -> Result<Self::ChannelOpenAckPayload, Self::Error> { | ||
self.chain | ||
.build_channel_open_ack_payload(height, port_id, channel_id) | ||
.await | ||
} | ||
|
||
async fn build_channel_open_confirm_payload( | ||
&self, | ||
height: &Self::Height, | ||
port_id: &Self::PortId, | ||
channel_id: &Self::ChannelId, | ||
) -> Result<Self::ChannelOpenConfirmPayload, Self::Error> { | ||
self.chain | ||
.build_channel_open_confirm_payload(height, port_id, channel_id) | ||
.await | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Chain, Counterparty> CanBuildChannelHandshakeMessages<OfaChainWrapper<Counterparty>> | ||
for OfaChainWrapper<Chain> | ||
where | ||
Chain: OfaIbcChain<Counterparty>, | ||
Counterparty: OfaIbcChain<Chain>, | ||
{ | ||
async fn build_channel_open_init_message( | ||
&self, | ||
port_id: &Self::PortId, | ||
counterparty_port_id: &Counterparty::PortId, | ||
init_channel_options: &Self::InitChannelOptions, | ||
) -> Result<Self::Message, Self::Error> { | ||
self.chain | ||
.build_channel_open_init_message(port_id, counterparty_port_id, init_channel_options) | ||
.await | ||
} | ||
|
||
async fn build_channel_open_try_message( | ||
&self, | ||
dst_port_id: &Self::PortId, | ||
src_port_id: &Counterparty::PortId, | ||
src_channel_id: &Counterparty::ChannelId, | ||
counterparty_payload: Counterparty::ChannelOpenTryPayload, | ||
) -> Result<Self::Message, Self::Error> { | ||
self.chain | ||
.build_channel_open_try_message( | ||
dst_port_id, | ||
src_port_id, | ||
src_channel_id, | ||
counterparty_payload, | ||
) | ||
.await | ||
} | ||
|
||
async fn build_channel_open_ack_message( | ||
&self, | ||
port_id: &Self::PortId, | ||
channel_id: &Self::ChannelId, | ||
counterparty_channel_id: &Counterparty::ChannelId, | ||
counterparty_payload: Counterparty::ChannelOpenAckPayload, | ||
) -> Result<Self::Message, Self::Error> { | ||
self.chain | ||
.build_channel_open_ack_message( | ||
port_id, | ||
channel_id, | ||
counterparty_channel_id, | ||
counterparty_payload, | ||
) | ||
.await | ||
} | ||
|
||
async fn build_channel_open_confirm_message( | ||
&self, | ||
port_id: &Self::PortId, | ||
channel_id: &Self::ChannelId, | ||
counterparty_payload: Counterparty::ChannelOpenConfirmPayload, | ||
) -> Result<Self::Message, Self::Error> { | ||
self.chain | ||
.build_channel_open_confirm_message(port_id, channel_id, counterparty_payload) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod channel; | ||
pub mod client; | ||
pub mod connection; | ||
pub mod error; | ||
|
149 changes: 149 additions & 0 deletions
149
crates/relayer-all-in-one/src/one_for_all/impls/relay/channel.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use async_trait::async_trait; | ||
|
||
use ibc_relayer_components::relay::impls::channel::open_ack::RelayChannelOpenAck; | ||
use ibc_relayer_components::relay::impls::channel::open_confirm::RelayChannelOpenConfirm; | ||
use ibc_relayer_components::relay::impls::channel::open_handshake::RelayChannelOpenHandshake; | ||
use ibc_relayer_components::relay::impls::channel::open_init::{ | ||
InitializeChannel, InjectMissingChannelInitEventError, | ||
}; | ||
use ibc_relayer_components::relay::impls::channel::open_try::{ | ||
InjectMissingChannelTryEventError, RelayChannelOpenTry, | ||
}; | ||
use ibc_relayer_components::relay::traits::channel::open_ack::{ | ||
CanRelayChannelOpenAck, ChannelOpenAckRelayer, | ||
}; | ||
use ibc_relayer_components::relay::traits::channel::open_confirm::{ | ||
CanRelayChannelOpenConfirm, ChannelOpenConfirmRelayer, | ||
}; | ||
use ibc_relayer_components::relay::traits::channel::open_handshake::{ | ||
CanRelayChannelOpenHandshake, ChannelOpenHandshakeRelayer, | ||
}; | ||
use ibc_relayer_components::relay::traits::channel::open_init::{ | ||
CanInitChannel, ChannelInitializer, | ||
}; | ||
use ibc_relayer_components::relay::traits::channel::open_try::{ | ||
CanRelayChannelOpenTry, ChannelOpenTryRelayer, | ||
}; | ||
|
||
use crate::one_for_all::traits::chain::{OfaChain, OfaIbcChain}; | ||
use crate::one_for_all::{traits::relay::OfaRelay, types::relay::OfaRelayWrapper}; | ||
use crate::std_prelude::*; | ||
|
||
impl<Relay> InjectMissingChannelInitEventError for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
fn missing_channel_init_event_error(&self) -> Relay::Error { | ||
self.relay.missing_channel_init_event_error() | ||
} | ||
} | ||
|
||
impl<Relay> InjectMissingChannelTryEventError for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
fn missing_channel_try_event_error( | ||
&self, | ||
src_channel_id: &<Relay::SrcChain as OfaChain>::ChannelId, | ||
) -> Relay::Error { | ||
self.relay.missing_channel_try_event_error(src_channel_id) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Relay> CanInitChannel for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
async fn init_channel( | ||
&self, | ||
src_port_id: &<Relay::SrcChain as OfaChain>::PortId, | ||
dst_port_id: &<Relay::DstChain as OfaChain>::PortId, | ||
init_channel_options: &<Relay::SrcChain as OfaIbcChain<Relay::DstChain>>::InitChannelOptions, | ||
) -> Result<<Relay::SrcChain as OfaChain>::ChannelId, Self::Error> { | ||
InitializeChannel::init_channel(self, src_port_id, dst_port_id, init_channel_options).await | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Relay> CanRelayChannelOpenTry for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
async fn relay_channel_open_try( | ||
&self, | ||
dst_port_id: &<Relay::DstChain as OfaChain>::PortId, | ||
src_port_id: &<Relay::SrcChain as OfaChain>::PortId, | ||
src_channel_id: &<Relay::SrcChain as OfaChain>::ChannelId, | ||
) -> Result<<Relay::DstChain as OfaChain>::ChannelId, Self::Error> { | ||
RelayChannelOpenTry::relay_channel_open_try(self, dst_port_id, src_port_id, src_channel_id) | ||
.await | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Relay> CanRelayChannelOpenAck for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
async fn relay_channel_open_ack( | ||
&self, | ||
src_port_id: &<Relay::SrcChain as OfaChain>::PortId, | ||
src_channel_id: &<Relay::SrcChain as OfaChain>::ChannelId, | ||
dst_port_id: &<Relay::DstChain as OfaChain>::PortId, | ||
dst_channel_id: &<Relay::DstChain as OfaChain>::ChannelId, | ||
) -> Result<(), Self::Error> { | ||
RelayChannelOpenAck::relay_channel_open_ack( | ||
self, | ||
src_port_id, | ||
src_channel_id, | ||
dst_port_id, | ||
dst_channel_id, | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Relay> CanRelayChannelOpenConfirm for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
async fn relay_channel_open_confirm( | ||
&self, | ||
dst_port_id: &<Relay::DstChain as OfaChain>::PortId, | ||
dst_channel_id: &<Relay::DstChain as OfaChain>::ChannelId, | ||
src_port_id: &<Relay::SrcChain as OfaChain>::PortId, | ||
src_channel_id: &<Relay::SrcChain as OfaChain>::ChannelId, | ||
) -> Result<(), Self::Error> { | ||
RelayChannelOpenConfirm::relay_channel_open_confirm( | ||
self, | ||
dst_port_id, | ||
dst_channel_id, | ||
src_port_id, | ||
src_channel_id, | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<Relay> CanRelayChannelOpenHandshake for OfaRelayWrapper<Relay> | ||
where | ||
Relay: OfaRelay, | ||
{ | ||
async fn relay_channel_open_handshake( | ||
&self, | ||
src_channel_id: &<Relay::SrcChain as OfaChain>::ChannelId, | ||
src_port_id: &<Relay::SrcChain as OfaChain>::PortId, | ||
dst_port_id: &<Relay::DstChain as OfaChain>::PortId, | ||
) -> Result<<Relay::DstChain as OfaChain>::ChannelId, Self::Error> { | ||
RelayChannelOpenHandshake::relay_channel_open_handshake( | ||
self, | ||
src_channel_id, | ||
src_port_id, | ||
dst_port_id, | ||
) | ||
.await | ||
} | ||
} |
Oops, something went wrong.