Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DaviRain-Su opened this issue Mar 8, 2024 · 3 comments
Labels
A: bug Admin: something isn't working

Comments

@DaviRain-Su
Copy link
Contributor

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
Copy link
Member

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

@DaviRain-Su
Copy link
Contributor Author

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
Copy link
Member

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

@Farhad-Shabani Farhad-Shabani added the A: bug Admin: something isn't working label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: bug Admin: something isn't working
Projects
Status: 📥 To Do
Development

No branches or pull requests

2 participants