paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

Moves `Block` to `frame_system` instead of `construct_runtime` and removes `Header` and `BlockNumber` #14437

Closed gupnik closed 1 year ago

gupnik commented 1 year ago

Fixes https://github.com/paritytech/substrate/issues/14126

Currently, one needs to define these params explicitly when using construct_runtime!

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,
    }
);

This PR add these types as part of frame_system instead and allows the following:

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

Note that this change is backwards compatible. However, a warning is issued if the older syntax is still used.

Further, this PR also removes BlockNumber and Header from frame_system::Config. It instead uses Block to retrieve these using the trait HeaderProvider.

impl frame_system::Config for Runtime {
-    type Header = Header;
-    type BlockNumber = u32;
+    type Block = generic::Block<Header, UncheckedExtrinsic>;
}

Note that this is a breaking change.

Cumulus companion: https://github.com/paritytech/cumulus/pull/2790 Polkadot companion: https://github.com/paritytech/polkadot/pull/7431

gupnik commented 1 year ago

If this works, it looks much better IMO.

Agreed.

Did you checked on how much other things you need to change?

It would still require a change at all places that get the BlockNumber using T::BlockNumber, though the change set will definitely be lesser than the previous one.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3083487 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 2-3560af8e-2133-4686-a027-340c128a80c4 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3083487 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3083487/artifacts/download.

kianenigma commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@kianenigma https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3152006 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 11-aa7a603f-cc88-4932-9b2d-2f3ef98dfb88 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@kianenigma Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3152006 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3152006/artifacts/download.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3155175 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 14-fbf80700-b78b-4719-9ae6-f6019ab197d0 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3155175 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3155175/artifacts/download.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164533 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 19-14b63cc3-1404-4706-a998-a8b58c05e116 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164533 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164533/artifacts/download.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164893 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 20-54f0a4d5-67ce-4ff0-b188-3dd5e00a62ce to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164893 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3164893/artifacts/download.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3175979 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 12-f1045260-aa10-4411-b48d-a0200a47de9a to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3175979 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3175979/artifacts/download.

gupnik commented 1 year ago

bot update-ui $ 1.70

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3177623 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh" 1.70. Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 14-9d401990-6eaf-43e0-a0b4-76a1c9e4f5ea to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh" 1.70 has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3177623 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3177623/artifacts/download.

gupnik commented 1 year ago

Is there a consideration for having frame_system still export a BlockNumber type, even if it is just referencing the other generic type?

Yeah, we are currently exporting BlockNumberFor from frame_system's prelude. Most of the code previously used T::BlockNumber and would still require a change if we name the export as BlockNumber itself. A number of places that already used BlockNumberFor see no impact with this PR.

gupnik commented 1 year ago

bot fmt

command-bot[bot] commented 1 year ago

@gupnik https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3179287 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 15-baeb5df4-1743-4cf0-aef7-8e0a0f45d017 to cancel this command or bot cancel to cancel all commands in this pull request.

command-bot[bot] commented 1 year ago

@gupnik Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3179287 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3179287/artifacts/download.

gupnik commented 1 year ago

bot merge