0

Find the source I have been working with at: https://github.com/al3mart/substrate-node-template/tree/al3mart/runtime-featuregated.

While building a node using the feature-gated runtimes added in https://github.com/paritytech/substrate/pull/11818 I encounter the following compilation errors.

  • Scenario 1

construct_runtime! includes a pallet decorated by #[cfg(feature = "template")]. Building with: $ cargo build --release results in

--- stderr
     Compiling node-template-runtime v4.0.0-dev (/home/ale/Projects/substrate/substrate-node-template/runtime)
  error[E0277]: the trait bound `Event: From<pallet_template::Event<Runtime>>` is not satisfied
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:270:15
      |
  270 |     type Event = Event;
      |                  ^^^^^ the trait `From<pallet_template::Event<Runtime>>` is not implemented for `Event`
      |
      = help: the following other types implement trait `From<T>`:
                <Event as From<frame_system::Event<Runtime>>>
                <Event as From<pallet_balances::Event<Runtime>>>
                <Event as From<pallet_grandpa::Event>>
                <Event as From<pallet_sudo::Event<Runtime>>>
                <Event as From<pallet_transaction_payment::Event<Runtime>>>
  note: required by a bound in `pallet_template::Config::Event`
     --> /home/ale/Projects/substrate/substrate-node-template/pallets/template/src/lib.rs:30:15
      |
  30  |         type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
      |                     ^^^^^^^^^^^^^^^^^ required by this bound in `pallet_template::Config::Event`

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

construct_runtime! includes a pallet decorated by #[cfg(feature = "template")]. Building with: $ cargo build --release --features template results in

  --- stdout
  Information that should be included in a bug report.
  Executing build command: "rustup" "run" "nightly" "cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/home/ale/Projects/substrate/substrate-node-template/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--profile" "release"
  Using rustc version: rustc 1.65.0-nightly (2e35f954a 2022-09-01)


  --- stderr
     Compiling node-template-runtime v4.0.0-dev (/home/ale/Projects/substrate/substrate-node-template/runtime)
  error[E0428]: the name `AllPalletsWithSystem` is defined multiple times
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:280:1
      |
  280 |     construct_runtime!(
      |    _^
      |  _|_|
      | | |
  281 | | |     pub struct Runtime
  282 | | |     where
  283 | | |         Block = Block,
  ...   | |
  298 | | |     }
  299 | | | );
      | | |_- in this macro invocation
  ...   |
      |
      = note: `AllPalletsWithSystem` must be defined only once in the type namespace of this module
      = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0428]: the name `AllPalletsWithoutSystem` is defined multiple times
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:280:1
      |
  280 |     construct_runtime!(
      |    _^
      |  _|_|
      | | |
  281 | | |     pub struct Runtime
  282 | | |     where
  283 | | |         Block = Block,
  ...   | |
  298 | | |     }
  299 | | | );
      | | |_- in this macro invocation
  ...   |
      |
      = note: `AllPalletsWithoutSystem` must be defined only once in the type namespace of this module
      = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0428]: the name `AllPalletsWithSystemReversed` is defined multiple times
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:280:1
      |
  280 |     construct_runtime!(
      |    _^
      |  _|_|
      | | |
  281 | | |     pub struct Runtime
  282 | | |     where
  283 | | |         Block = Block,
  ...   | |
  298 | | |     }
  299 | | | );
      | | |_- in this macro invocation
  ...   |
      |
      = note: `AllPalletsWithSystemReversed` must be defined only once in the type namespace of this module
      = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0428]: the name `AllPalletsWithoutSystemReversed` is defined multiple times
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:280:1
      |
  280 |     construct_runtime!(
      |    _^
      |  _|_|
      | | |
  281 | | |     pub struct Runtime
  282 | | |     where
  283 | | |         Block = Block,
  ...   | |
  298 | | |     }
  299 | | | );
      | | |_- in this macro invocation
  ...   |
      |
      = note: `AllPalletsWithoutSystemReversed` must be defined only once in the type namespace of this module
      = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

  error[E0428]: the name `AllPalletsReversedWithSystemFirst` is defined multiple times
     --> /home/ale/Projects/substrate/substrate-node-template/runtime/src/lib.rs:280:1
      |
  280 |     construct_runtime!(
      |    _^
      |  _|_|
      | | |
  281 | | |     pub struct Runtime
  282 | | |     where
  283 | | |         Block = Block,
  ...   | |
  298 | | |     }
  299 | | | );
      | | |_- in this macro invocation
  ...   |
      |
      = note: `AllPalletsReversedWithSystemFirst` must be defined only once in the type namespace of this module
      = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

  warning: ignoring -C extra-filename flag due to -o flag

  For more information about this error, try `rustc --explain E0428`.
  warning: `node-template-runtime` (lib) generated 1 warning
  error: could not compile `node-template-runtime` due to 5 previous errors; 1 warning emitted

To reproduce the above behavior run the build commands posted above.

1 Answer 1

0
  • Scenario 1 - feature not enabled

Not only the pallet has to be decorated within the contruct_runtime! macro, like so

#[cfg(feature = "template")]
TemplateModule: pallet_template::{Event},

But also its Config trait implementation for the runtime

#[cfg(feature = "template")]
impl pallet_template::Config for Runtime {
    type Event = Event;
}

as when adding #[cfg(feature = "template")] on TemplateModule, it basically removes the pallet from the runtime if the "template" feature flag is not present. So, the compilation errors make total sense as the pallet is not part of the runtime.

  • Scenario 2

So far, this scenario looks like is caused by a possible bug.

EDIT: including comment with fix.

Fix for scenario 2: github.com/paritytech/substrate/pull/12229

2

Your Answer

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

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