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

Migrate pallet-migrations to use umbrella crate #7209

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions substrate/frame/migrations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
cfg-if = { workspace = true }
codec = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frame = { workspace = true, features = ["experimental", "runtime"]}
frame = { workspace = true, features = ["runtime"]}

docify = { workspace = true }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true, default-features = true }
scale-info = { features = ["derive"], workspace = true }

frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
frame-executive = { workspace = true, default-features = true }
sp-api = { features = ["std"], workspace = true, default-features = true }
sp-block-builder = { features = ["std"], workspace = true, default-features = true }
sp-io = { features = ["std"], workspace = true, default-features = true }
sp-tracing = { features = ["std"], workspace = true, default-features = true }
sp-version = { features = ["std"], workspace = true, default-features = true }

Expand All @@ -39,25 +33,15 @@ default = ["std"]

std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
"frame/std",
]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]

try-runtime = [
"frame-executive/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
5 changes: 1 addition & 4 deletions substrate/frame/migrations/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

use super::*;

use frame_benchmarking::{v2::*, BenchmarkError};
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::One;
use frame::benchmarking::prelude::*;

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
Expand All @@ -30,7 +28,6 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
#[benchmarks]
mod benches {
use super::*;
use frame_support::traits::Hooks;

#[benchmark]
fn onboard_new_mbms() {
Expand Down
34 changes: 10 additions & 24 deletions substrate/frame/migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,9 @@ pub use weights::WeightInfo;
use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use core::ops::ControlFlow;
use frame_support::{
defensive, defensive_assert,
migrations::*,
pallet_prelude::*,
traits::Get,
weights::{Weight, WeightMeter},
BoundedVec,
};
use frame_system::{
pallet_prelude::{BlockNumberFor, *},
Pallet as System,
};
use sp_runtime::Saturating;
use frame::prelude::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this, prelude is already in the testing_prelude

use frame::testing_prelude::*;


/// Points to the next migration to execute.
#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode, scale_info::TypeInfo, MaxEncodedLen)]
Expand Down Expand Up @@ -290,11 +280,11 @@ struct PreUpgradeBytesWrapper(pub Vec<u8>);
///
/// Define this outside of the pallet so it is not confused with actual storage.
#[cfg(feature = "try-runtime")]
#[frame_support::storage_alias]
#[frame::storage_alias]
type PreUpgradeBytes<T: Config> =
StorageMap<Pallet<T>, Twox64Concat, IdentifierOf<T>, PreUpgradeBytesWrapper, ValueQuery>;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -354,12 +344,8 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::{inject_runtime_type, DefaultConfig};
use frame_support::{
derive_impl,
migrations::FreezeChainOnFailedMigration,
pallet_prelude::{ConstU32, *},
};
use frame_system::limits::BlockWeights;

// use frame_system::limits::BlockWeights;

/// Provides a viable default config that can be used with
/// [`derive_impl`](`frame_support::derive_impl`) to derive a testing pallet config
Expand All @@ -369,15 +355,15 @@ pub mod pallet {
/// a downstream user of this particular `TestDefaultConfig`
pub struct TestDefaultConfig;

frame_support::parameter_types! {
parameter_types! {
/// Maximal weight per block that can be spent on migrations in tests.
pub TestMaxServiceWeight: Weight = <<TestDefaultConfig as frame_system::DefaultConfig>::BlockWeights as Get<BlockWeights>>::get().max_block.div(2);
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}

#[frame_support::register_default_impl(TestDefaultConfig)]
#[register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
#[inject_runtime_type]
type RuntimeEvent = ();
Expand Down Expand Up @@ -474,7 +460,7 @@ pub mod pallet {
#[cfg(feature = "std")]
fn integrity_test() {
// Check that the migrations tuple is legit.
frame_support::assert_ok!(T::Migrations::integrity_test());
assert_ok!(T::Migrations::integrity_test());

// Very important! Ensure that the pallet is configured in `System::Config`.
{
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/migrations/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
#![cfg(test)]

use crate::{mock_helpers::*, Event, Historic};
use frame::testing_prelude::*;

use frame_support::{derive_impl, migrations::*, weights::Weight};
use frame_system::EventRecord;
use sp_core::H256;

type Block = frame_system::mocking::MockBlock<Test>;

type Block = MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
construct_runtime!(
pub enum Test {
System: frame_system,
Migrations: crate,
Expand Down
11 changes: 4 additions & 7 deletions substrate/frame/migrations/src/mock_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode};
use frame_support::{
migrations::*,
weights::{Weight, WeightMeter},
};
use sp_core::ConstU32;
use sp_runtime::BoundedVec;
use frame::testing_prelude::*;
use frame::deps::sp_core::ConstU32;
use frame::deps::sp_runtime::BoundedVec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoundedVec is already in the main prelude and ConstU32 is already in the runtime prelude, so they are both imported in the testing prelude. You can remove these imports.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're still there


/// Opaque identifier of a migration.
pub type MockedIdentifier = BoundedVec<u8, ConstU32<256>>;
Expand Down Expand Up @@ -57,7 +54,7 @@ pub fn mocked_id(kind: MockedMigrationKind, steps: u32) -> MockedIdentifier {
(b"MockedMigration", kind, steps).encode().try_into().unwrap()
}

frame_support::parameter_types! {
parameter_types! {
/// The configs for the migrations to run.
storage MIGRATIONS: Vec<(MockedMigrationKind, u32)> = vec![];
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/migrations/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#![cfg(test)]

use frame_support::{pallet_prelude::Weight, traits::OnRuntimeUpgrade};
use frame::testing_prelude::*;

use crate::{
mock::{Test as T, *},
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/migrations/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ pub mod prelude {
/// Dispatch types from `frame-support`, other fundamental traits
#[doc(no_inline)]
pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo};
pub use frame_support::traits::{
Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess,
NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
VariantCount, VariantCountOf,
pub use frame_support::{
defensive, defensive_assert,
migrations::FreezeChainOnFailedMigration,
traits::{
Contains, EitherOf, EstimateNextSessionRotation, Get, Hooks, IsSubType, MapSuccess,
NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
},
weights::{Weight, WeightMeter},
};

/// Pallet prelude of `frame-system`.
Expand All @@ -231,9 +235,12 @@ pub mod prelude {

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
pub use sp_runtime::{
traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, One, ReduceBy,
ReplaceWithDefault, SaturatedConversion, StaticLookup, TrailingZeroInput,
},
Saturating,
};

/// Bounded storage related types.
Expand Down Expand Up @@ -326,7 +333,8 @@ pub mod testing_prelude {
/// Other helper macros from `frame_support` that help with asserting in tests.
pub use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok,
assert_storage_noop, ensure, hypothetically, storage_alias,
assert_storage_noop, derive_impl, hypothetically, parameter_types, register_default_impl,
storage_alias,
};

pub use frame_system::{self, mocking::*, RunToBlockHooks};
Expand Down
Loading