Skip to content

Commit d5d7838

Browse files
Implement abstract and mock IBC v2 components (#445)
* 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]>
1 parent 34c0d46 commit d5d7838

File tree

264 files changed

+5777
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+5777
-139
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## v0.2.0 (pre-release)
44

5+
- Implement abstract and mock IBC v2 components - [#445](https://github.com/informalsystems/hermes-sdk/pull/445)
6+
- Rename `DelegateTo` to `UseDelegate`.
7+
- Move the following chain trait types to `hermes-chain-type-components`: `HasAddressType`, `HasAmountType`,
8+
`HasDenomType`, `HasCommitmentPrefixType`.
9+
510
- CGP Refactoring [#440](https://github.com/informalsystems/hermes-sdk/pull/440)
611
- Update `cgp` version to include the addition of `cgp-type`. [cgp#23](https://github.com/contextgeneric/cgp/pull/23)
712
- Use `DelegateTo` from `cgp-component` instead of custom constructs to implement delegated chain implementations.

Cargo.lock

+47-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ members = [
5353

5454
"tools/integration-test",
5555
"tools/test-framework",
56+
57+
"crates/ibc/ibc-components",
58+
"crates/ibc/ibc-token-transfer-components",
59+
"crates/ibc/ibc-mock-chain",
5660
]
5761

5862
[workspace.package]
@@ -157,6 +161,10 @@ hermes-wasm-test-components = { version = "0.1.0" }
157161
hermes-solomachine-chain-components = { version = "0.1.0" }
158162
hermes-solomachine-relayer = { version = "0.1.0" }
159163

164+
hermes-ibc-components = { version = "0.1.0" }
165+
hermes-ibc-token-transfer-components = { version = "0.1.0" }
166+
hermes-ibc-mock-chain = { version = "0.1.0" }
167+
160168
[patch.crates-io]
161169
cgp = { git = "https://github.com/contextgeneric/cgp.git" }
162170
cgp-core = { git = "https://github.com/contextgeneric/cgp.git" }
@@ -219,3 +227,7 @@ hermes-wasm-test-components = { path = "./crates/wasm/wasm-test-componen
219227

220228
hermes-solomachine-chain-components = { path = "./crates/solomachine/solomachine-chain-components" }
221229
hermes-solomachine-relayer = { path = "./crates/solomachine/solomachine-relayer" }
230+
231+
hermes-ibc-components = { path = "./crates/ibc/ibc-components" }
232+
hermes-ibc-token-transfer-components = { path = "./crates/ibc/ibc-token-transfer-components" }
233+
hermes-ibc-mock-chain = { path = "./crates/ibc/ibc-mock-chain" }

crates/chain/chain-components/src/traits/commitment_prefix.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use cgp::prelude::*;
2-
32
pub use hermes_chain_type_components::traits::types::commitment_prefix::*;
43

54
#[derive_component(IbcCommitmentPrefixGetterComponent, IbcCommitmentPrefixGetter<Chain>)]

crates/chain/chain-components/src/traits/message_builders/channel_handshake.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cgp::core::component::DelegateTo;
1+
use cgp::core::component::UseDelegate;
22
use cgp::prelude::*;
33

44
use crate::traits::types::channel::{
@@ -70,7 +70,7 @@ where
7070
}
7171

7272
impl<Chain, Counterparty, Components, Delegate> ChannelOpenInitMessageBuilder<Chain, Counterparty>
73-
for DelegateTo<Components>
73+
for UseDelegate<Components>
7474
where
7575
Chain: HasInitChannelOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType,
7676
Counterparty: HasIbcChainTypes<Chain>,
@@ -94,7 +94,7 @@ where
9494
}
9595

9696
impl<Chain, Counterparty, Components, Delegate> ChannelOpenTryMessageBuilder<Chain, Counterparty>
97-
for DelegateTo<Components>
97+
for UseDelegate<Components>
9898
where
9999
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
100100
Counterparty: HasChannelOpenTryPayloadType<Chain> + HasIbcChainTypes<Chain>,
@@ -120,7 +120,7 @@ where
120120
}
121121

122122
impl<Chain, Counterparty, Components, Delegate> ChannelOpenAckMessageBuilder<Chain, Counterparty>
123-
for DelegateTo<Components>
123+
for UseDelegate<Components>
124124
where
125125
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
126126
Counterparty: HasChannelOpenAckPayloadType<Chain> + HasIbcChainTypes<Chain>,
@@ -146,7 +146,7 @@ where
146146
}
147147

148148
impl<Chain, Counterparty, Components, Delegate>
149-
ChannelOpenConfirmMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
149+
ChannelOpenConfirmMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
150150
where
151151
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
152152
Counterparty: HasChannelOpenConfirmPayloadType<Chain> + HasIbcChainTypes<Chain>,

crates/chain/chain-components/src/traits/message_builders/connection_handshake.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cgp::core::component::DelegateTo;
1+
use cgp::core::component::UseDelegate;
22
use cgp::prelude::*;
33

44
use crate::traits::types::connection::{
@@ -70,7 +70,7 @@ where
7070
}
7171

7272
impl<Chain, Counterparty, Components, Delegate>
73-
ConnectionOpenInitMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
73+
ConnectionOpenInitMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
7474
where
7575
Chain:
7676
HasInitConnectionOptionsType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType,
@@ -97,7 +97,7 @@ where
9797
}
9898

9999
impl<Chain, Counterparty, Components, Delegate> ConnectionOpenTryMessageBuilder<Chain, Counterparty>
100-
for DelegateTo<Components>
100+
for UseDelegate<Components>
101101
where
102102
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
103103
Counterparty: HasConnectionOpenTryPayloadType<Chain> + HasIbcChainTypes<Chain>,
@@ -123,7 +123,7 @@ where
123123
}
124124

125125
impl<Chain, Counterparty, Components, Delegate> ConnectionOpenAckMessageBuilder<Chain, Counterparty>
126-
for DelegateTo<Components>
126+
for UseDelegate<Components>
127127
where
128128
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
129129
Counterparty: HasConnectionOpenAckPayloadType<Chain> + HasIbcChainTypes<Chain>,
@@ -147,7 +147,7 @@ where
147147
}
148148

149149
impl<Chain, Counterparty, Components, Delegate>
150-
ConnectionOpenConfirmMessageBuilder<Chain, Counterparty> for DelegateTo<Components>
150+
ConnectionOpenConfirmMessageBuilder<Chain, Counterparty> for UseDelegate<Components>
151151
where
152152
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
153153
Counterparty: HasConnectionOpenConfirmPayloadType<Chain> + HasIbcChainTypes<Chain>,

crates/chain/chain-components/src/traits/message_builders/create_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cgp::core::component::DelegateTo;
1+
use cgp::core::component::UseDelegate;
22
use cgp::prelude::*;
33

44
use crate::traits::types::create_client::{
@@ -21,7 +21,7 @@ where
2121
}
2222

2323
impl<Chain, Counterparty, Components, Delegate> CreateClientMessageBuilder<Chain, Counterparty>
24-
for DelegateTo<Components>
24+
for UseDelegate<Components>
2525
where
2626
Chain: HasCreateClientMessageOptionsType<Counterparty> + HasMessageType + HasErrorType,
2727
Counterparty: HasCreateClientPayloadType<Chain>,

crates/chain/chain-components/src/traits/message_builders/update_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alloc::vec::Vec;
22

3-
use cgp::core::component::DelegateTo;
3+
use cgp::core::component::UseDelegate;
44
use cgp::prelude::*;
55

66
use crate::traits::types::ibc::HasIbcChainTypes;
@@ -21,7 +21,7 @@ where
2121
}
2222

2323
impl<Chain, Counterparty, Components, Delegate> UpdateClientMessageBuilder<Chain, Counterparty>
24-
for DelegateTo<Components>
24+
for UseDelegate<Components>
2525
where
2626
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
2727
Counterparty: HasUpdateClientPayloadType<Chain>,

crates/chain/chain-components/src/traits/queries/channel_end.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where
5252
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
5353
writeln!(
5454
f,
55-
"channel not found with channel id {}, port id {}, height {}",
55+
"channel not found with channel id {:?}, port id {}, height {}",
5656
self.channel_id, self.port_id, self.height,
5757
)?;
5858

crates/chain/chain-components/src/traits/queries/client_state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alloc::vec::Vec;
22

3-
use cgp::core::component::DelegateTo;
3+
use cgp::core::component::UseDelegate;
44
use cgp::prelude::*;
55

66
use crate::traits::queries::chain_status::CanQueryChainStatus;
@@ -138,7 +138,7 @@ where
138138
}
139139

140140
impl<Chain, Counterparty, Components, Delegate> ClientStateQuerier<Chain, Counterparty>
141-
for DelegateTo<Components>
141+
for UseDelegate<Components>
142142
where
143143
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
144144
Counterparty: HasClientStateType<Chain>,
@@ -155,7 +155,7 @@ where
155155
}
156156

157157
impl<Chain, Counterparty, Components, Delegate> ClientStateWithProofsQuerier<Chain, Counterparty>
158-
for DelegateTo<Components>
158+
for UseDelegate<Components>
159159
where
160160
Chain: HasIbcChainTypes<Counterparty> + HasCommitmentProofType + HasErrorType,
161161
Counterparty: HasClientStateType<Chain>,
@@ -172,7 +172,7 @@ where
172172
}
173173

174174
impl<Chain, Counterparty, Components, Delegate> AllClientStatesQuerier<Chain, Counterparty>
175-
for DelegateTo<Components>
175+
for UseDelegate<Components>
176176
where
177177
Chain: HasIbcChainTypes<Counterparty> + HasErrorType,
178178
Counterparty: HasClientStateType<Chain>,

0 commit comments

Comments
 (0)