简体   繁体   English

Substrate 教程 - 特征 `MaxEncodedLen` 没有为`Vec 实现<u8> `</u8>

[英]Substrate tutorials - trait `MaxEncodedLen` is not implemented for `Vec<u8>`

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):我在预构建检查中收到以下错误(之前的教程已经构建好,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 :我的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?我该如何开始调试/修复这个?

For now, all that is needed it to remove the #[pallet::generate_storage_info] macro line.现在,只需要它来删除#[pallet::generate_storage_info]宏行。

Future users should not have this error.未来的用户不应出现此错误。 See https://github.com/substrate-developer-hub/substrate-docs/issues/627https://github.com/substrate-developer-hub/substrate-docs/issues/627

In the latest frame_support::pallet , #[pallet::generate_storage_info] is no longer explicitly available.在最新的frame_support::pallet中, #[pallet::generate_storage_info]不再明确可用。 And if someone is still getting the error如果有人仍然收到错误

the trait MaxEncodedLen is not implemented for xxx没有为 xxx 实现特征 MaxEncodedLen

add #[pallet::without_storage_info] after #[pallet::pallet]#[pallet::pallet] ] 之后添加#[pallet::without_storage_info] ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM