Skip to content

Make construct_runtime macro more flexible #232

Closed
paritytech/substrate
#14788
@arrudagates

Description

Usually the assumptions made by the construct_runtime macro are correct and help keep the runtime boilerplate free, but sometimes it's desirable to override the implementations generated by the macro.

In my case, for example, I want to override the implementation of From<Origin> for Result<RawOrigin<AccountId>, Origin> so I can allow my custom origins to pass through the default ensure_signed assertions in most pallets' calls.

I would like to propose and get feedback/suggestions on how to make the construct_runtime macro more flexible, while still maintaining the minimum amount of boilerplate. The solution I currently have in mind is probably not the best possible, thus I'd like to brainstorm solutions.

I'll preface this with a note that I'm not super knowledgeable in Rust macros, so I'm not sure if this is possible to implement like this, but here's what I had in mind:

construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
        [...]
    }

    // Anything implemented manually here won't get generated by the macro automatically and instead will be passed through. 
    impl From<Origin> for Result<System::Origin, Origin> {
        // impl here
    }

Perhaps we could even break down the implementations from construct_runtime into multiple macros (like impl_call, impl_origin, etc...) and these could be used by themselves or if the runtime does not require any special implementations, we could have the overarching construct_runtime calling these within itself if they are declared in the macro.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

I5-enhancementAn additional feature request.T1-FRAMEThis PR/Issue is related to core FRAME, the framework.

Type

No type

Projects

  • Status

    Done
  • Status

    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions