6

In the project we are currently working on, we declared some runtime apis in our custom pallet, we tried to update the dependencies from 0.9.28 to 0.9.42 but the build fails with the following error:

error[E0277]: the trait bound `R: pallet::Config` is not satisfied
   --> pallet/src/lib.rs:196:2
    |
196 | /     sp_api::decl_runtime_apis! {
197 | |         /// Get extrinsic ids from a vector of extrinsics
198 | |         /// that should be used to quickly retrieve all the event ids (hashes) given a vector of
199 | |         /// extrinsics currently used to inspect the proposed block event ids and whether they are
...   |
210 | |         }
211 | |     }
    | |_____^ the trait `pallet::Config` is not implemented for `R`
    |
    = note: this error originates in the macro `sp_api::decl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `R`
    |
211 |     }, R: pallet::Config
    |      +++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.

this error is a bit misleading as far as I understand since I'm already implementing pallet::Config, so I decided to run a minimal setup with substrate-node-template and see if there are any problems with the macro itself.

In the latest version in substrate-node-template, I tried adding the following runtime api in the template pallet:

sp_api::decl_runtime_apis! {
    pub trait ExtrinsicDetails<R> where R:crate::Config
    {
        fn dummy_test(runtime: R::length) -> R;
    }
}

given that I declare length in the pallet::Config like this:

#[pallet::config]
pub trait Config: frame_system::Config {
    /// Because this pallet emits events, it depends on the runtime's definition of an event.
    type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
    /// Type representing the weight of this pallet
    type WeightInfo: WeightInfo;
    #[pallet::constant]
    type length: Get<u32>;
}

and implemented like this:

impl pallet_template::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
    type length = ConstU32<100>;
}

it kept throwing this error:

 error[E0220]: associated type `length` not found for `R`
     --> /home/coder/project/substrate-node-template/pallets/template/src/lib.rs:114:30
      |
  114 |             fn dummy_test(runtime: R::length) -> R;
      |                                       ^^^^^^ there is a similarly named associated type `length` in the trait `pallet::Config`

even though it has the same name, i also tried using pallet::Config instead of crate::Config and also just Config, all have the same error.

Ps: same code was working in 0.9.28

2
  • Can you share the repo?
    – Bruno
    May 10 at 20:51
  • @Bruno question updated!
    – dadzerlaze
    May 11 at 10:30

1 Answer 1

0

Error resolves for me on v0.9.40 by capitalizing the letter L in these two places:

pallets/template/src/lib.rs

type Length: Get<u32>;

runtime/src/lib.rs

type Length = ConstU32<100>;
6
  • still does not work, using latest rust latest update in both stable and nightly, didn't work, and sometimes when i use R directly for example in a trait methid parameter dummy_test(my_type: MyType<R>) and my MyType is defined in the module like this type MyType<T> =BoundedVec<u8, T::Length> it show this error: associated type Length` not found`
    – dadzerlaze
    May 10 at 21:38
  • 1
    Best to push up your code so I can pull and test it.
    – Bruno
    May 10 at 21:45
  • Alright, here is the repository that im working with currently https://github.com/revoltez/validated-streams, its not minimal setup but nothing too complicated, its very similar to what i asked but this time it always gives this error: ^ the trait pallet::Config` is not implemented for R `, i'll update the question to this repository if needed
    – dadzerlaze
    May 11 at 8:11
  • even though its implemented and it also suggests to to further restrict it by retyping the same bound }, R: pallet::Config
    – dadzerlaze
    May 11 at 8:17
  • 1
    fixed it with 0.9.40, i'll leave this question open since the problem is in 0.9.42
    – dadzerlaze
    May 11 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.