Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRAME: runtime macro doesn't handle cfg contrary to construct_runtime #6209

Closed
gui1117 opened this issue Oct 24, 2024 · 1 comment · Fixed by #6410
Closed

FRAME: runtime macro doesn't handle cfg contrary to construct_runtime #6209

gui1117 opened this issue Oct 24, 2024 · 1 comment · Fixed by #6410
Assignees
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@gui1117
Copy link
Contributor

gui1117 commented Oct 24, 2024

With construct runtime it compiles:

frame_support::construct_runtime!(
	pub enum Runtime
	{
		System: frame_system,
		MyPallet1: my_pallet::<Instance1>,
		#[cfg(feature = "frame-feature-testing")]
		MyPallet2: my_pallet::<Instance2>,
	}
);

with runtime it doesn't:

#[frame_support::runtime]
mod runtime {
	#[runtime::runtime]
	#[runtime::derive(
		RuntimeCall,
		RuntimeEvent,
		RuntimeError,
		RuntimeOrigin,
		RuntimeFreezeReason,
		RuntimeHoldReason,
		RuntimeSlashReason,
		RuntimeLockId,
		RuntimeTask
	)]
	pub struct Runtime;

	#[runtime::pallet_index(0)]
	pub type System = frame_system;

	#[runtime::pallet_index(1)]
	pub type MyPallet1 = my_pallet<Instance1>;

	#[cfg(feature = "frame-feature-testing")]
	#[runtime::pallet_index(2)]
	pub type MyPallet2 = my_pallet<Instance2>;
}

error:

error[E0277]: the trait bound `Runtime: my_pallet::Config<Instance2>` is not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `my_pallet::Config<Instance2>` is not implemented for `Runtime`, which is required by `my_pallet::Pallet<Runtime, Instance2>: PalletInfoAccess`
   |
   = help: the trait `my_pallet::Config<Instance1>` is implemented for `Runtime`
   = help: for that trait implementation, expected `Instance1`, found `Instance2`
note: required for `my_pallet::Pallet<Runtime, Instance2>` to implement `PalletInfoAccess`
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 |   #[frame_support::pallet(dev_mode)]
   |   ^
...
25 |       #[pallet::pallet]
   |  _______________^
26 | |     pub struct Pallet<T, I = ()>(_);
   | |_____________________^
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `storage_metadata` exists for struct `Pallet<Runtime, Instance2>`, but its trait bounds were not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
26 |     pub struct Pallet<T, I = ()>(_);
   |     ---------------------------- function or associated item `storage_metadata` not found for this struct
...
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | function or associated item cannot be called on `Pallet<Runtime, Instance2>` due to unsatisfied trait bounds
   | doesn't satisfy `Runtime: my_pallet::Config<Instance2>`
   |
note: trait bound `Runtime: my_pallet::Config<Instance2>` was not satisfied
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 | #[frame_support::pallet(dev_mode)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
note: the trait `my_pallet::Config` must be implemented
  --> substrate/frame/support/test/tests/regression.rs:23:2
   |
23 |     pub trait Config<I: 'static = ()>: frame_system::Config {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `pallet_constants_metadata` exists for struct `Pallet<Runtime, Instance2>`, but its trait bounds were not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
26 |     pub struct Pallet<T, I = ()>(_);
   |     ---------------------------- function or associated item `pallet_constants_metadata` not found for this struct
...
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | function or associated item cannot be called on `Pallet<Runtime, Instance2>` due to unsatisfied trait bounds
   | doesn't satisfy `Runtime: my_pallet::Config<Instance2>`
   |
note: trait bound `Runtime: my_pallet::Config<Instance2>` was not satisfied
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 | #[frame_support::pallet(dev_mode)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
note: the trait `my_pallet::Config` must be implemented
  --> substrate/frame/support/test/tests/regression.rs:23:2
   |
23 |     pub trait Config<I: 'static = ()>: frame_system::Config {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `error_metadata` exists for struct `Pallet<Runtime, Instance2>`, but its trait bounds were not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
26 |     pub struct Pallet<T, I = ()>(_);
   |     ---------------------------- function or associated item `error_metadata` not found for this struct
...
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | function or associated item cannot be called on `Pallet<Runtime, Instance2>` due to unsatisfied trait bounds
   | doesn't satisfy `Runtime: my_pallet::Config<Instance2>`
   |
note: trait bound `Runtime: my_pallet::Config<Instance2>` was not satisfied
  --> substrate/frame/support/test/tests/regression.rs:25:12
   |
25 |       #[pallet::pallet]
   |  _______________^
26 | |     pub struct Pallet<T, I = ()>(_);
   | |_____________________^
note: the trait `my_pallet::Config` must be implemented
  --> substrate/frame/support/test/tests/regression.rs:23:2
   |
23 |     pub trait Config<I: 'static = ()>: frame_system::Config {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `pallet_documentation_metadata` exists for struct `Pallet<Runtime, Instance2>`, but its trait bounds were not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
26 |     pub struct Pallet<T, I = ()>(_);
   |     ---------------------------- function or associated item `pallet_documentation_metadata` not found for this struct
...
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | function or associated item cannot be called on `Pallet<Runtime, Instance2>` due to unsatisfied trait bounds
   | doesn't satisfy `Runtime: my_pallet::Config<Instance2>`
   |
note: trait bound `Runtime: my_pallet::Config<Instance2>` was not satisfied
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 | #[frame_support::pallet(dev_mode)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
note: the trait `my_pallet::Config` must be implemented
  --> substrate/frame/support/test/tests/regression.rs:23:2
   |
23 |     pub trait Config<I: 'static = ()>: frame_system::Config {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `pallet_associated_types_metadata` exists for struct `Pallet<Runtime, Instance2>`, but its trait bounds were not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
26 |     pub struct Pallet<T, I = ()>(_);
   |     ---------------------------- function or associated item `pallet_associated_types_metadata` not found for this struct
...
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | function or associated item cannot be called on `Pallet<Runtime, Instance2>` due to unsatisfied trait bounds
   | doesn't satisfy `Runtime: my_pallet::Config<Instance2>`
   |
note: trait bound `Runtime: my_pallet::Config<Instance2>` was not satisfied
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 | #[frame_support::pallet(dev_mode)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
note: the trait `my_pallet::Config` must be implemented
  --> substrate/frame/support/test/tests/regression.rs:23:2
   |
23 |     pub trait Config<I: 'static = ()>: frame_system::Config {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Runtime: my_pallet::Config<Instance2>` is not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `my_pallet::Config<Instance2>` is not implemented for `Runtime`, which is required by `(frame_system::Pallet<Runtime>, my_pallet::Pallet<Runtime, Instance1>, my_pallet::Pallet<Runtime, Instance2>): OnGenesis`
   |
   = help: the trait `my_pallet::Config<Instance1>` is implemented for `Runtime`
   = help: for that trait implementation, expected `Instance1`, found `Instance2`
note: required for `my_pallet::Pallet<Runtime, Instance2>` to implement `OnGenesis`
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 |   #[frame_support::pallet(dev_mode)]
   |   ^
...
25 |       #[pallet::pallet]
   |  _______________^
26 | |     pub struct Pallet<T, I = ()>(_);
   | |_____________________^
   = note: 1 redundant requirement hidden
   = note: required for `(frame_system::Pallet<Runtime>, my_pallet::Pallet<Runtime, Instance1>, my_pallet::Pallet<Runtime, Instance2>)` to implement `OnGenesis`
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Runtime: my_pallet::Config<Instance2>` is not satisfied
  --> substrate/frame/support/test/tests/regression.rs:48:1
   |
48 | #[frame_support::runtime]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `my_pallet::Config<Instance2>` is not implemented for `Runtime`, which is required by `(frame_system::Pallet<Runtime>, my_pallet::Pallet<Runtime, Instance1>, my_pallet::Pallet<Runtime, Instance2>): IntegrityTest`
   |
   = help: the trait `my_pallet::Config<Instance1>` is implemented for `Runtime`
   = help: for that trait implementation, expected `Instance1`, found `Instance2`
note: required for `my_pallet::Pallet<Runtime, Instance2>` to implement `IntegrityTest`
  --> substrate/frame/support/test/tests/regression.rs:18:1
   |
18 |   #[frame_support::pallet(dev_mode)]
   |   ^
...
25 |       #[pallet::pallet]
   |  _______________^
26 | |     pub struct Pallet<T, I = ()>(_);
   | |_____________________^
   = note: 1 redundant requirement hidden
   = note: required for `(frame_system::Pallet<Runtime>, my_pallet::Pallet<Runtime, Instance1>, my_pallet::Pallet<Runtime, Instance2>)` to implement `IntegrityTest`
   = note: this error originates in the attribute macro `frame_support::runtime` which comes from the expansion of the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `frame-support-test` (test "regression") due to 8 previous errors
Connection to 78.137.198.97 closed.
2024-10-24 13:34:28,114 INFO [cargo_remote] Transferring Cargo.lock file back to client.
              0   0%    0,00kB/s    0:00:00 (xfr#0, to-chk=0/1)

complete test:

#[frame_support::pallet(dev_mode)]
mod my_pallet {
	use frame_support::pallet_prelude::{StorageValue, ValueQuery};

	#[pallet::config]
	pub trait Config<I: 'static = ()>: frame_system::Config {}

	#[pallet::pallet]
	pub struct Pallet<T, I = ()>(_);

	#[pallet::storage]
	pub type SomeStorage<T, I = ()> = StorageValue<_, (u32, u64), ValueQuery>;
}

type BlockNumber = u32;
type AccountId = u64;
type Header = sp_runtime::generic::Header<BlockNumber, sp_runtime::traits::BlakeTwo256>;
type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, RuntimeCall, (), ()>;
type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;

// frame_support::construct_runtime!(
// 	pub enum Runtime
// 	{
// 		System: frame_system,
// 		MyPallet1: my_pallet::<Instance1>,
// 		#[cfg(feature = "frame-feature-testing")]
// 		MyPallet2: my_pallet::<Instance2>,
// 	}
// );

#[frame_support::runtime]
mod runtime {
	#[runtime::runtime]
	#[runtime::derive(
		RuntimeCall,
		RuntimeEvent,
		RuntimeError,
		RuntimeOrigin,
		RuntimeFreezeReason,
		RuntimeHoldReason,
		RuntimeSlashReason,
		RuntimeLockId,
		RuntimeTask
	)]
	pub struct Runtime;

	#[runtime::pallet_index(0)]
	pub type System = frame_system;

	#[runtime::pallet_index(1)]
	pub type MyPallet1 = my_pallet<Instance1>;

	#[cfg(feature = "frame-feature-testing")]
	#[runtime::pallet_index(2)]
	pub type MyPallet2 = my_pallet<Instance2>;
}

// NOTE: Needed for derive_impl expansion
use frame_support::derive_impl;
#[frame_support::derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
	type Block = Block;
	type AccountId = AccountId;
}

impl my_pallet::Config<frame_support::instances::Instance1> for Runtime {}

#[cfg(feature = "frame-feature-testing")]
impl my_pallet::Config<frame_support::instances::Instance2> for Runtime {}

fn new_test_ext() -> sp_io::TestExternalities {
	use sp_runtime::BuildStorage;

	RuntimeGenesisConfig::default().build_storage().unwrap().into()
}
@gui1117 gui1117 added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Oct 24, 2024
@kianenigma
Copy link
Contributor

cc @gupnik

github-merge-queue bot pushed a commit that referenced this issue Nov 25, 2024
Fixes #6209

This PR adds the support for cfg attributes in the runtime macro.

---------

Co-authored-by: Bastian Köcher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants