【问题标题】:error when cargo build node-templare with Pallet in its own Crate货物在其自己的 Crate 中使用 Pallet 构建节点模板时出错
【发布时间】:2021-07-05 09:49:54
【问题描述】:

我遵循了Write a Pallet in its Own Crate 教程。 我用教程仔细检查了所有内容,但是当我cargo build --release 时,我收到 66 条错误消息。这些错误消息中的大多数类似于以下 2 条(更多详细信息请往下看):

    cannot find type `Pallet` in crate/scope
    the trait bound `Runtime: frame_system::pallet::Congig` is not satisfied

我创建了一个错误日志。在 stackoverflow.com 上发布错误日志或这么多错误消息的最佳方式是什么?

Information that should be included in a bug report.
Executing build command: "/home/df/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--release"
Using rustc version: rustc 1.55.0-nightly (24bdc6d73 2021-06-12)

显示的第一个错误如下:

  errorm: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:338:29
      |
  338 |         TestPallet: test_pallet::{Module, Call, Storage, Event<T>},
      |                                   ^^^^^^ `

因此我从第 338 行删除了 ModuleTestPallet: test_pallet::{Module, Call, Storage, Event&lt;T&gt;},

如果我再次cargo build --release,我会收到 14 条错误消息,这些消息会在下面发布。你有什么想法,哪里出了问题?

   Compiling node-template-runtime v3.0.0 (/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime)
error: failed to run custom build command for `node-template-runtime v3.0.0 (/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime)`

Caused by:
  process didn't exit successfully: `/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/build/node-template-runtime-10b4571a8bd12437/build-script-build` (exit status: 1)
  --- stdout
  Information that should be included in a bug report.
  Executing build command: "/home/df/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--release"
  Using rustc version: rustc 1.55.0-nightly (24bdc6d73 2021-06-12)


  --- stderr
     Compiling node-template-runtime v3.0.0 (/mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime)
  error[E0412]: cannot find type `Pallet` in crate `test_pallet`
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ not found in `test_pallet`
      |
      = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
  help: consider importing one of these items
      |
  9   | use crate::pallet_template::Pallet;
      |
  9   | use frame_system::Pallet;
      |
  9   | use pallet_aura::Pallet;
      |
  9   | use pallet_balances::Pallet;
      |
        and 7 other candidates

  error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `panic_impl`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-68d2ddc13c0ddd99.rmeta
    = note: second definition in `sp_io` loaded from /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0c3d7ed5f1bed9c8.rmeta

  error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `oom`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-68d2ddc13c0ddd99.rmeta
    = note: second definition in `sp_io` loaded from /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/target/release/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-0c3d7ed5f1bed9c8.rmeta

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:316:6
      |
  316 | impl test_pallet::Config for Runtime {
      |      ^^^^^^^^^^^^^^^^^^^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      | 
     ::: /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/pallets/test-pallet/src/lib.rs:17:19
      |
  17  | pub trait Config: frame_system::Config {
      |                   -------------------- required by this bound in `test_pallet::Config`

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Event: TryInto<test_pallet::RawEvent<_>>` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `TryInto<test_pallet::RawEvent<_>>` is not implemented for `Event`
      |
      = help: the following implementations were found:
                <Event as TryInto<frame_system::Event<Runtime>>>
                <Event as TryInto<pallet_balances::Event<Runtime>>>
                <Event as TryInto<pallet_grandpa::Event>>
                <Event as TryInto<pallet_nicks::RawEvent<AccountId32, u128>>>
              and 3 others
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Event: TryInto<test_pallet::RawEvent<_>>` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `TryInto<test_pallet::RawEvent<_>>` is not implemented for `Event`
      |
      = help: the following implementations were found:
                <Event as TryInto<frame_system::Event<Runtime>>>
                <Event as TryInto<pallet_balances::Event<Runtime>>>
                <Event as TryInto<pallet_grandpa::Event>>
                <Event as TryInto<pallet_nicks::RawEvent<AccountId32, u128>>>
              and 3 others
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Runtime: frame_system::pallet::Config` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `frame_system::pallet::Config` is not implemented for `Runtime`
      |
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0277]: the trait bound `Event: TryInto<test_pallet::RawEvent<_>>` is not satisfied
     --> /mnt/f/Etp/Substrate/tutorials/02/substrate-node-template/runtime/src/lib.rs:321:1
      |
  321 | / construct_runtime!(
  322 | |     pub enum Runtime where
  323 | |         Block = Block,
  324 | |         NodeBlock = opaque::Block,
  ...   |
  340 | |     }
  341 | | );
      | |__^ the trait `TryInto<test_pallet::RawEvent<_>>` is not implemented for `Event`
      |
      = help: the following implementations were found:
                <Event as TryInto<frame_system::Event<Runtime>>>
                <Event as TryInto<pallet_balances::Event<Runtime>>>
                <Event as TryInto<pallet_grandpa::Event>>
                <Event as TryInto<pallet_nicks::RawEvent<AccountId32, u128>>>
              and 3 others
      = note: this error originates in the macro `$crate::impl_outer_event` (in Nightly builds, run with -Z macro-backtrace for more info)

  error: aborting due to 14 previous errors

  Some errors have detailed explanations: E0277, E0412.
  For more information about an error, try `rustc --explain E0277`.
  error: could not compile `node-template-runtime`

  To learn more, run the command again with --verbose.

【问题讨论】:

    标签: substrate


    【解决方案1】:

    您可能需要在 test-pallet/lib.rs 中添加 pub use pallet::*;

    【讨论】:

      【解决方案2】:

      您应该将Module替换Pallet,而不是删除它。

      【讨论】:

      • 您好 kianenigma,感谢您的回答,但它不能解决错误。我尝试了您的建议:```construct_runtime!( // --snip-- TestPallet: test_pallet::{Pallet, Call, Storage, Event}, ``` cargo build --release导致 15 个错误:14 个来自之前和以下一个:``` error[E0433]: failed to resolve: could not find Pallet in test_pallet --> /mnt/f/Etp/Substrate/tutorials/02 /substrate-node-template/runtime/src/lib.rs:321:1 | // 跳过 ||__^在test_pallet 中找不到Pallet | ``
      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多