Skip to content

Commit

Permalink
Implement abstract and mock IBC v2 components (#445)
Browse files Browse the repository at this point in the history
* Add hermes-ibc-components crate

* Scaffold IBC v2 packet types

* Scaffold packet handlers

* Draft outgoing packet handlers

* Draft packet ack handlers

* Rename PacketPayload to PacketEntry

* Draft commitment verification

* Draft packet commitment value builder

* Add HasPacketType

* Draft more commitment verification methods

* Implement StorePacketAck and define CanQueryConsensusState

* Implement VerifySendPacketCommitmentProof

* Replace RawPacket-Entry/Ack with AnyApp

* Implement DisallowDoubleReceive

* Implement HandleIncomingPacketEntries

* Define IbcChainComponents with IncomingPacketHandlerComponent

* Implement DisallowTimedOutIncomingPacket

* Generalize IncomingPacketHandler to work with generic App instead of AnyApp

* Swap the generic order from <App, Counterparty> to <Counterparty, App>

* Use HasCommitmentProofType from chain-type-components

* WIP

* Minor refactoring

* Add IgnoreDoubleReceive

* Implement EncodeAndHandlePacketEntry

* Implement WrapHandlerErrorAsAck

* Add IbcTransaction type

* Draft IBC transaction and message handlers

* Add CanAllocatePacketNonce

* Implement CommitSendPacket

* Add CanQuerySendPacketCommitment

* Make PacketAck singular, and add PacketEntryAck as sub-list

* Make WrapHandlerErrorAsAck a IncomingPacketHandler

* Add <App> generic to FullIncomingPacketHandler

* Add WrapHandlerErrorAsAck to FullIncomingPacketHandler

* Add PacketAck getter and builder

* Add CanBuildPacket

* Implement HandleIbcTransactionMessages

* Rename ClientId to ChannelId

* Move builder traits to builder:: module

* Add IbcMessageHeader type

* Implement ValidateHeaderAppIds

* Implement ConvertAndHandleIbcMessage

* Implement IbcMessageHandler and IncomingPacketEntryHandler for UseContext

* Rename HasPacketEntryHeaderType to HasPayloadType

* Rename HasPacketDataType to HasPayloadDataType

* Rename CanHandleIncomingPacketEntry to CanHandleIncomingPayload

* Rename and redesign ack handlers

* Replace more use of "entries"

* Remove remaining use of "entries"

* Move message and transaction handlers to outgoing::module

* Add InHandler to HandleIbcTransactionMessages

* Add new ibc-token-transfer-components crate

* Move HasAddressType and HasDenomType to chain-type-components

* Add HasQuantityType

* Draft IBC transfer payload fields

* Add HasAmountType

* Draft mint traits

* Draft mint registry

* Draft implement HandleIncomingIbcTransfer

* Check and update escrowed aamount for HandleIncomingIbcTransfer

* Implement DispatchMintOrUnescrow

* Use CanParseIncomingTransferData in DispatchMintOrUnescrow

* Implement HandleIncomingMintTransfer

* Implement HandleIncomingUnescrowTransfer

* Remove HasIbcTransferAmount

* Drafting SendIbcTransfer

* Finish implementing SendIbcTransfer

* Add ibc-mock-chain crate

* Implement ProvideStringError

* Implement MockChain with HasErrorType

* Implement HasAppIdType for MockChain

* Implement HasChannelId for MockChain

* Implement HasPacketHeaderType and HasPacketChannelIds

* Implement HasPacketNonce

* Use upstream FieldGetter

* Implement HasPacketPayloads

* Implement HasPacketTimeout

* Implement HasPayloadAppIds

* Implement HasIbcMessageAppIds

* Use delegated type map for PacketData

* Add Transfer PacketData types

* Implement HasDenomType and HasAmountType

* Implement PacketData types for IBC transfer

* Add tagging to MockChain

* Add tags to all mock values

* Add back phantom Chain generic to IbcTransferUnescrowPacketData

* Implement custom provider types for ProvidePayloadDataType

* Add custom providers for other generic IBC types

* Use "Use" instead of "Provide" for name of type providers

* Rename DelegateTo to UseDelegate

* Add UseTaggedType to simplify provider impl for tagged types

* imp: remove ack from incoming packet handlers

* chore: remove further acks

* chore: remove packet ack types

* Add explicit tags to MockChain

* Add state fields to mock chain

* Implement clone for MockChain

* Remove HasPayloadAckType

* Add HasPayloadType and CanSendPacket

* Use IbcPayload inside IbcPacket

* Make IbcMessage handler return payload directly

* Implement AllocateNonceAndBuildPacket

* Implement CommitSendPacket

* Implement HandleMessagesAndSendPacket

* Remove transaction handlers replaced by packet senders

* Make IbcMessageHandler return payload header and data separately again

* Implement CheckSendPayloadPermission

* Use chain-level caller instead of putting it in ibc-transaction

* Add CanQueryClientIdFromChannelId

* Move packet nonce field to packet instead of packet header

* Replace IbcTransactionHeader with PacketHeader

* Rename MockChainFields to MockChainState

* Add some documentation for HasPacketType

* Simplify implementation of token transfer dispatcher

* Add direct tags to mock denom and amount

* Put MockChainState behind Mutex

* Add mock balances field

* Implement mint on mock chain

* Implement remaining TokenTransfer methods

* Implement mint registry methods

* Fix clippy

* Implement amount methods

* Implement CanHandleIncomingPayload for IbcTransferMintApp

* Fix clippy

* Implement UnescrowTokenRegistrar

* Implement EscrowTokenRegistrar

* Add documentation for escrow registry

* Remove UnescrowAmountExceeded error

* Implement CanHandleIncomingPayload for IbcTransferUnescrowApp and IbcTransferApp

* Implement CanHandleIncomingPayload for AnyApp

* Use HandleIncomingPacketPayloads

* Refactor commitment path construction

* Implement commitment path builders

* Implement HasConsensusStateType

* Implement commitment value builders

* Implement ConsensusStateQuerier

* Implement CommitmentVerifier

* Implement CommitmentStorage

* Use CommitReceivePacket

* Add generic tag parameter to commitment type traits

* Use different commitment types for mock send and receive packet

* Implement HasCommitmentProofHeight

* Implement ClientIdFromChannelIdQuerier

* Use VerifySendPacketCommitmentProof

* Implement HasPacketReceivedQuerier

* Use DisallowDoubleReceive

* Implement time methods

* Use FullIncomingPacketHandler directly

* Reformat imports

* Fix clippy

* Implement CanAllocatePacketNonce

* Implement CanBuildPacket and CanSendPacket

* Implement transfer payload builders

* Implement HasIbcMessageType

* Refine component wiring

* Wire up IBC message handler

* Use &mut self for handlers for state update

* Remove mutex and update mock chain state directly

* Implement HasCaller

* Implement message handler for IbcTransferApp

* Update cgp

* Add changelog

---------

Co-authored-by: Farhad Shabani <[email protected]>
  • Loading branch information
soareschen and Farhad-Shabani authored Oct 21, 2024
1 parent 34c0d46 commit d5d7838
Show file tree
Hide file tree
Showing 264 changed files with 5,777 additions and 139 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## v0.2.0 (pre-release)

- Implement abstract and mock IBC v2 components - [#445](https://github.com/informalsystems/hermes-sdk/pull/445)
- Rename `DelegateTo` to `UseDelegate`.
- Move the following chain trait types to `hermes-chain-type-components`: `HasAddressType`, `HasAmountType`,
`HasDenomType`, `HasCommitmentPrefixType`.

- CGP Refactoring [#440](https://github.com/informalsystems/hermes-sdk/pull/440)
- Update `cgp` version to include the addition of `cgp-type`. [cgp#23](https://github.com/contextgeneric/cgp/pull/23)
- Use `DelegateTo` from `cgp-component` instead of custom constructs to implement delegated chain implementations.
Expand Down
62 changes: 47 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ members = [

"tools/integration-test",
"tools/test-framework",

"crates/ibc/ibc-components",
"crates/ibc/ibc-token-transfer-components",
"crates/ibc/ibc-mock-chain",
]

[workspace.package]
Expand Down Expand Up @@ -157,6 +161,10 @@ hermes-wasm-test-components = { version = "0.1.0" }
hermes-solomachine-chain-components = { version = "0.1.0" }
hermes-solomachine-relayer = { version = "0.1.0" }

hermes-ibc-components = { version = "0.1.0" }
hermes-ibc-token-transfer-components = { version = "0.1.0" }
hermes-ibc-mock-chain = { version = "0.1.0" }

[patch.crates-io]
cgp = { git = "https://github.com/contextgeneric/cgp.git" }
cgp-core = { git = "https://github.com/contextgeneric/cgp.git" }
Expand Down Expand Up @@ -219,3 +227,7 @@ hermes-wasm-test-components = { path = "./crates/wasm/wasm-test-componen

hermes-solomachine-chain-components = { path = "./crates/solomachine/solomachine-chain-components" }
hermes-solomachine-relayer = { path = "./crates/solomachine/solomachine-relayer" }

hermes-ibc-components = { path = "./crates/ibc/ibc-components" }
hermes-ibc-token-transfer-components = { path = "./crates/ibc/ibc-token-transfer-components" }
hermes-ibc-mock-chain = { path = "./crates/ibc/ibc-mock-chain" }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cgp::prelude::*;

pub use hermes_chain_type_components::traits::types::commitment_prefix::*;

#[derive_component(IbcCommitmentPrefixGetterComponent, IbcCommitmentPrefixGetter<Chain>)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgp::core::component::DelegateTo;
use cgp::core::component::UseDelegate;
use cgp::prelude::*;

use crate::traits::types::channel::{
Expand Down Expand Up @@ -70,7 +70,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ChannelOpenInitMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasInitChannelOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasIbcChainTypes<Chain>,
Expand All @@ -94,7 +94,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ChannelOpenTryMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenTryPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand All @@ -120,7 +120,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ChannelOpenAckMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenAckPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand All @@ -146,7 +146,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate>
ChannelOpenConfirmMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
ChannelOpenConfirmMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasChannelOpenConfirmPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgp::core::component::DelegateTo;
use cgp::core::component::UseDelegate;
use cgp::prelude::*;

use crate::traits::types::connection::{
Expand Down Expand Up @@ -70,7 +70,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate>
ConnectionOpenInitMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
ConnectionOpenInitMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
where
Chain:
HasInitConnectionOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType,
Expand All @@ -97,7 +97,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ConnectionOpenTryMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasConnectionOpenTryPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand All @@ -123,7 +123,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ConnectionOpenAckMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasConnectionOpenAckPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand All @@ -147,7 +147,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate>
ConnectionOpenConfirmMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
ConnectionOpenConfirmMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasConnectionOpenConfirmPayloadType<Chain> + HasIbcChainTypes<Chain>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgp::core::component::DelegateTo;
use cgp::core::component::UseDelegate;
use cgp::prelude::*;

use crate::traits::types::create_client::{
Expand All @@ -21,7 +21,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> CreateClientMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasCreateClientMessageOptionsType<Counterparty> + HasMessageType + HasErrorType,
Counterparty: HasCreateClientPayloadType<Chain>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::vec::Vec;

use cgp::core::component::DelegateTo;
use cgp::core::component::UseDelegate;
use cgp::prelude::*;

use crate::traits::types::ibc::HasIbcChainTypes;
Expand All @@ -21,7 +21,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> UpdateClientMessageBuilder<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasUpdateClientPayloadType<Chain>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
writeln!(
f,
"channel not found with channel id {}, port id {}, height {}",
"channel not found with channel id {:?}, port id {}, height {}",
self.channel_id, self.port_id, self.height,
)?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::vec::Vec;

use cgp::core::component::DelegateTo;
use cgp::core::component::UseDelegate;
use cgp::prelude::*;

use crate::traits::queries::chain_status::CanQueryChainStatus;
Expand Down Expand Up @@ -138,7 +138,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ClientStateQuerier<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasClientStateType<Chain>,
Expand All @@ -155,7 +155,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> ClientStateWithProofsQuerier<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasCommitmentProofType + HasErrorType,
Counterparty: HasClientStateType<Chain>,
Expand All @@ -172,7 +172,7 @@ where
}

impl<Chain, Counterparty, Components, Delegate> AllClientStatesQuerier<Chain, Counterparty>
for DelegateTo<Components>
for UseDelegate<Components>
where
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
Counterparty: HasClientStateType<Chain>,
Expand Down
Loading

0 comments on commit d5d7838

Please sign in to comment.