5

Presently, in working through the substrate tutorials, I've got to the "Build the runtime with your new pallet" section. With files updated and double checked as per the tutorial.

I'm getting the following error on pre-build check (the previous tutorials had built ok, Ubuntu 20.04.3):

cargo check -p node-template-runtime

Gives:

cargo check -p node-template-runtime
    Updating git repository `https://github.com/paritytech/substrate.git`
    Checking sp-std v4.0.0-dev (https://github.com/paritytech/substrate.git?tag=monthly-2021-11-1#352c46a6)
   Compiling node-template-runtime v4.0.0-dev (/myPath/substrate/att2/substrate-node-template/runtime)
    Checking pallet-template v4.0.0-dev (/myPath/substrate/att2/substrate-node-template/pallets/template)
error[E0277]: the trait bound `Vec<u8>: MaxEncodedLen` is not satisfied
  --> pallets/template/src/lib.rs:40:11
   |
40 | #[pallet::generate_storage_info]
   |           ^^^^^^^^^^^^^^^^^^^^^ the trait `MaxEncodedLen` is not implemented for `Vec<u8>`
   |
   = note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageMap<_GeneratedPrefixForStorageProofs<T>, frame_support::Blake2_128Concat, Vec<u8>, (<T as frame_system::Config>::AccountId, <T as frame_system::Config>::BlockNumber), frame_support::pallet_prelude::ValueQuery>`
note: required by `storage_info`
  --> /myPath/.cargo/git/checkouts/substrate-7e08433d4c370a21/352c46a/frame/support/src/traits/storage.rs:71:2
   |
71 |     fn storage_info() -> Vec<StorageInfo>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0277`.
error: could not compile `pallet-template` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

I have the following in my Cargo.toml:

[dependencies.sp-std]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-11-1'  # or the latest monthly
version = '4.0.0-dev'      # or the latest version

Is there some obvious thing that might've gone wrong? How might I start to debug/fix this?

Lee
  • 29,398
  • 28
  • 117
  • 170
  • @NukeManDan Thank you, I'll update the question :-) – Lee Dec 02 '21 at 21:10
  • I agree an issue to fix this if it's indeed a breaking change is in order @Stargateur - https://github.com/substrate-developer-hub/substrate-docs/issues/648 /// https://github.com/paritytech/substrate/tree/devhub/latest is upstream, so should not be an issue with breaking changes in substrate #10043 – Nuke Dec 02 '21 at 21:23
  • what version of the node are you using and what is the substrate git tag your are targeting @atomh33ls? You can find this in your `Cargo.toml` files – Nuke Dec 02 '21 at 21:24
  • 1
    PS: https://github.com/substrate-developer-hub/substrate-docs/issues/627 is what we will fix shortly to address the same problem. – Nuke Dec 02 '21 at 21:29
  • much better question, as nukemandan open the issue on github, I have no further complain – Stargateur Dec 02 '21 at 21:30
  • happy to move to resolve on github @atomh33ls - in #627 – Nuke Dec 02 '21 at 21:30
  • 1
    @NukeManDan yes, thanks, the suggestion there works and could be added as an answer here (I'm unsure if it'll affect later part of the tutorial atm though). – Lee Dec 02 '21 at 21:42
  • 1
    Hi Atomh33ls, Can you please support our Substrate StackExchange proposal: https://area51.stackexchange.com/proposals/126136 – Shawn Tabrizi Dec 16 '21 at 13:16
  • 1
    @ShawnTabrizi I did a couple of weeks ago, so close now! – Lee Dec 16 '21 at 17:58

3 Answers3

6

In the latest frame_support::pallet, #[pallet::generate_storage_info] is no longer explicitly available. And if someone is still getting the error

the trait MaxEncodedLen is not implemented for xxx

add #[pallet::without_storage_info] after #[pallet::pallet]

Toufeeq
  • 386
  • 4
  • 9
2

For now, all that is needed it to remove the #[pallet::generate_storage_info] macro line.

Future users should not have this error. See https://github.com/substrate-developer-hub/substrate-docs/issues/627

Nuke
  • 1,032
  • 7
  • 13
1

For error of no function or associated item named "max_encoded_len" found for struct "Vec<u8>" in the current scope function or associated item not found in "Vec<u8>"

if you have a struct like

    #[derive(Default, Encode, Decode, Clone, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
    pub struct UserInfo {
        pub id: i64,
        pub username: Vec<u8>, //bytes
    }

Replace Vec<u8> with [u8; 256] because Rust does not know the max length of that vector.

Russo
  • 2,186
  • 2
  • 26
  • 42