cosmos / ibc-rs

Rust implementation of the Inter-Blockchain Communication (IBC) protocol.
Apache License 2.0
201 stars 79 forks source link

Can't implement AnyClientState validation and execution Use Generics Context<T> #1117

Open DaviRain-Su opened 7 months ago

DaviRain-Su commented 7 months ago

Bug Summary

Currently I am using the latest ibc version to upgrade substrate-ibc to implement the ibc protocol. During the implementation process, I am implementing the validation and Exection attributes for AnyClientState. It cannot support Context with generics very well.

Details

https://github.com/octopus-network/substrate-ibc/blob/81786952f83478606a5dc0136fbfe2601cba981a/core/src/client/mod.rs#L80

#[derive(Debug, Clone, From, PartialEq, ClientState)]
#[validation(Context<T: Config>)]
#[execution(Context<T: Config>)]
pub enum AnyClientState {
    Tendermint(TmClientState),
}

Version

ibc version 0.50

Farhad-Shabani commented 7 months ago

Hey @DaviRain-Su, Would you mind sharing the compiler error? Appreciate that.

DaviRain-Su commented 7 months ago

Hey @DaviRain-Su, Would you mind sharing the compiler error? Appreciate that.

here.

warning: use of deprecated struct `pallet::_::Store`:
                 Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed after July 2023.
                 Check https://github.com/paritytech/substrate/pull/13535 for more details.
  --> core/src/lib.rs:97:3
   |
97 |     #[pallet::generate_store(pub(super) trait Store)]
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`:
                 It is deprecated to use hard-coded constant as call weight.
                 Please instead benchmark all calls or put the pallet into `dev` mode.

                 For more info see:
                     <https://github.com/paritytech/substrate/pull/13798>
   --> core/src/lib.rs:296:20
    |
296 |         #[pallet::weight(0)]
    |                          ^

error[E0277]: the trait bound `u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>` is not satisfied
  --> core/src/client/mod.rs:84:13
   |
84 |     Tendermint(TmClientState),
   |                ^^^^^^^^^^^^^ the trait `std::convert::From<<T as pallet_timestamp::Config>::Moment>` is not implemented for `u64`
   |
note: required for `context::Context<T>` to implement `CommonContext`
  --> core/src/client/mod.rs:21:17
   |
21 | impl<T: Config> ibc::clients::tendermint::context::CommonContext for Context<T>
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^
22 | where
23 |     u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>,
   |          ----------------------------------------------------------- unsatisfied trait bound introduced here
   = note: required for `ibc::clients::tendermint::client_state::ClientState` to implement `ClientStateValidation<context::Context<T>>`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
   |
80 | #[derive(Debug, Clone, From, PartialEq, ClientState, u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>)]
   |                                                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `u64: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>` is not satisfied
  --> core/src/client/mod.rs:84:13
   |
84 |     Tendermint(TmClientState),
   |                ^^^^^^^^^^^^^ the trait `std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>` is not implemented for `u64`
   |
note: required for `context::Context<T>` to implement `CommonContext`
  --> core/src/client/mod.rs:21:17
   |
21 | ...: Config> ibc::clients::tendermint::context::CommonContext for Context<T>
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^
...
24 | ...4: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>
   |       ------------------------------------------------------------------------------------------------------------------------------------------------------------------- unsatisfied trait bound introduced here
   = note: required for `ibc::clients::tendermint::client_state::ClientState` to implement `ClientStateValidation<context::Context<T>>`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
   |
80 | #[derive(Debug, Clone, From, PartialEq, ClientState, u64: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>)]
   |                                                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>` is not satisfied
   --> core/src/client/mod.rs:84:13
    |
84  |     Tendermint(TmClientState),
    |                ^^^^^^^^^^^^^ the trait `std::convert::From<<T as pallet_timestamp::Config>::Moment>` is not implemented for `u64`
    |
note: required for `context::Context<T>` to implement `ibc::core::host::ExecutionContext`
   --> core/src/context.rs:409:17
    |
409 | impl<T: Config> ExecutionContext for Context<T>
    |                 ^^^^^^^^^^^^^^^^     ^^^^^^^^^^
410 | where
411 |     u64: From<<T as pallet_timestamp::Config>::Moment> + From<BlockNumberFor<T>>,
    |          --------------------------------------------- unsatisfied trait bound introduced here
    = note: required for `ibc::clients::tendermint::client_state::ClientState` to implement `ClientStateExecution<context::Context<T>>`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
    |
80  | #[derive(Debug, Clone, From, PartialEq, ClientState, u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>)]
    |                                                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `u64: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>` is not satisfied
   --> core/src/client/mod.rs:84:13
    |
84  |     Tendermint(TmClientState),
    |                ^^^^^^^^^^^^^ the trait `std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>` is not implemented for `u64`
    |
note: required for `context::Context<T>` to implement `ibc::core::host::ExecutionContext`
   --> core/src/context.rs:409:17
    |
409 | impl<T: Config> ExecutionContext for Context<T>
    |                 ^^^^^^^^^^^^^^^^     ^^^^^^^^^^
410 | where
411 |     u64: From<<T as pallet_timestamp::Config>::Moment> + From<BlockNumberFor<T>>,
    |                                                          ----------------------- unsatisfied trait bound introduced here
    = note: required for `ibc::clients::tendermint::client_state::ClientState` to implement `ClientStateExecution<context::Context<T>>`
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
    |
80  | #[derive(Debug, Clone, From, PartialEq, ClientState, u64: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number>)]
    |                                                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0061]: this function takes 3 arguments but 2 arguments were supplied
   --> core/src/lib.rs:306:11
    |
306 |                 match ibc::core::handler::entrypoint::dispatch(&mut ctx, envelope) {
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^           -------- an argument of type `&mut _` is missing
    |
note: function defined here
   --> /Users/davirian/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ibc-core-handler-0.50.0/src/entrypoint.rs:25:8
    |
25  | pub fn dispatch(
    |        ^^^^^^^^
help: provide the argument
    |
306 |                 match ibc::core::handler::entrypoint::dispatch(&mut ctx, /* router */, envelope) {
    |                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0308]: mismatched types
    --> core/src/lib.rs:308:28
     |
308  |                     Err(e) => errors.push(e),
     |                                      ---- ^ expected `RouterError`, found `ContextError`
     |                                      |
     |                                      arguments to this method are incorrect
     |
note: method defined here
    --> /Users/davirian/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:1880:12
     |
1880 |     pub fn push(&mut self, value: T) {
     |            ^^^^

Some errors have detailed explanations: E0061, E0277, E0308.
For more information about an error, try `rustc --explain E0061`.
warning: `pallet-ibc` (lib) generated 2 warnings
error: could not compile `pallet-ibc` (lib) due to 16 previous errors; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
Farhad-Shabani commented 7 months ago

Hmm. Apparently, the macro couldn't handle the following "where" clause:

where
    u64: std::convert::From<<T as pallet_timestamp::Config>::Moment>,
    u64: std::convert::From<<<<T as frame_system::Config>::Block as frame_support::sp_runtime::traits::Block>::Header as frame_support::sp_runtime::traits::Header>::Number