Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Move Block, NodeBlock and UncheckedExtrinsic to frame_system, instead construct_runtime #14126

Closed
kianenigma opened this issue May 12, 2023 · 5 comments · Fixed by #14437
Closed
Assignees
Labels
J0-enhancement An additional feature request. T1-runtime This PR/Issue is related to the topic “runtime”.

Comments

@kianenigma
Copy link
Contributor

I came across this in my effort to make the simplest FRAME runtime and pallet, for the new tutorials in https://github.com/paritytech/polkadot-sdk-docs/.

The observation is that construct_runtime, and the need to define type UncheckedExtrinsic and type Block is quite noisy. At best, in a tutorial, you should say: "shuuush... just ignore these for now", which sucks.

type Extrinsic = MockUncheckedExtrinsic<Runtime>;
type Block = MockBlock<Runtime>;

frame_support::construct_runtime!(
	pub struct Runtime
	where
		Block = Block,
		NodeBlock = Block,
		UncheckedExtrinsic = Extrinsic,
	{
		System: frame_system,
		Currency: pallet,
	}
);

Ideally, I want this to just be:

frame_support::construct_runtime!(
	pub struct Runtime {
		System: frame_system,
		Currency: pallet_currency,
	}
);

And I am inclined to think that it is possible.

The fact that construct_runtime needs to know these types is unavoidable. But, can't it get these from frame_system::Config? I think we already have a pretty hard requirement for the frame_system to exist, and exist with the exact crate name frame-system. So it should be possible for construct_runtime to get these types as <#frame_system::Pallet as #frame_system::Config>::Block.

Even further, I think with #13454 we can actually have these have their defaults be set to the things that are in frame_system::mocking:: and free the whole universe from needing to define them at all in 95% of tests.

Needs to be verified. Would love to hear @ggwpez and @bkchr's opinion.

If deemed feasible, suggest @gupnik to take it over.

@kianenigma kianenigma added the J2-unconfirmed Issue might be valid, but it’s not yet known. label May 12, 2023
@bkchr
Copy link
Member

bkchr commented May 12, 2023

I think the block types can be removed when we have the sp-api refactorings implemented.

For the extrinsic we first should check where we currently require it.

@kianenigma
Copy link
Contributor Author

Let's assume the worse case, that we need both. Can't we move them to type Block, type NodeBlock and type Extrinsic to frame_system::Config, and instruct construct_runtime to read it from there?

I think the block types can be removed when we have the sp-api refactorings implemented.

do you have an issue pr PR?

@gupnik gupnik self-assigned this May 15, 2023
@gupnik
Copy link
Contributor

gupnik commented May 15, 2023

I will try to create a prototype to see if this could work.

@bkchr
Copy link
Member

bkchr commented May 16, 2023

do you have an issue pr PR?

paritytech/polkadot-sdk#27

@kianenigma
Copy link
Contributor Author

I will try to create a prototype to see if this could work.

I would suggest keeping it based on DefaultConfig PR and seeing of you can provide defaults for it as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
4 participants