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

MBM try-runtime support #4251

Merged
merged 49 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7ec7cc9
wip mbm try-runtime
liamaharon Apr 23, 2024
1c8416d
Merge branch 'master' into liam-mbm-try-runtime
liamaharon Apr 23, 2024
623c2b8
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 21, 2024
675338a
update cargo.lock
liamaharon May 21, 2024
d36ce71
refactor try-runtime logic
liamaharon May 27, 2024
45ce6e4
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 27, 2024
1403cbc
taplo
liamaharon May 27, 2024
f5b9210
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 28, 2024
92053e0
wip upgrade check select
liamaharon May 28, 2024
311d994
Merge branch 'liam-mbm-try-runtime' of github.com:paritytech/polkadot…
liamaharon May 28, 2024
e0a8152
impl_for_tuples MockedMigrations
liamaharon May 28, 2024
bf3fbfb
wip revert upgradecheckselect changes
liamaharon May 29, 2024
279e4cf
revert upgradecheckselect changes
liamaharon May 29, 2024
1710410
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 29, 2024
38dd259
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 29, 2024
1a8e86c
use Vec
liamaharon May 29, 2024
b10534f
Merge branch 'liam-mbm-try-runtime' of github.com:paritytech/polkadot…
liamaharon May 29, 2024
30121c5
prdoc
liamaharon May 29, 2024
b1ccef1
address comments
liamaharon May 30, 2024
6fbe843
address comment
liamaharon May 30, 2024
1677cd6
address comment
liamaharon May 30, 2024
1a61af3
fix newlines
liamaharon May 30, 2024
f57b50a
clippy
liamaharon May 30, 2024
95b7969
Merge branch 'master' into liam-mbm-try-runtime
liamaharon May 30, 2024
7dcad83
Merge branch 'master' into liam-mbm-try-runtime
liamaharon Jun 3, 2024
8fa87f2
Merge branch 'master' into liam-mbm-try-runtime
liamaharon Jun 3, 2024
49cd4e1
Merge branch 'master' into liam-mbm-try-runtime
liamaharon Jun 4, 2024
028aa60
ci: test without try-runtime feature
liamaharon Jun 7, 2024
e01c9e4
Merge branch 'liam-mbm-try-runtime' of github.com:paritytech/polkadot…
liamaharon Jun 7, 2024
b38ff1a
Merge branch 'master' into liam-mbm-try-runtime
liamaharon Jun 7, 2024
06eb247
cfg_attr
liamaharon Jun 7, 2024
96860b3
Merge branch 'liam-mbm-try-runtime' of github.com:paritytech/polkadot…
liamaharon Jun 7, 2024
b9bf013
Merge remote-tracking branch 'origin/master' into liam-mbm-try-runtime
ggwpez Sep 11, 2024
ba768dc
Cleanup
ggwpez Sep 12, 2024
97a1cbd
replace sp-std
claravanstaden Sep 12, 2024
f610140
adds external crate alloc
claravanstaden Sep 12, 2024
1c969d8
Cleanup
ggwpez Sep 12, 2024
ad1811a
cleanup
ggwpez Sep 12, 2024
666db60
Add PrDoc (auto generated)
ggwpez Sep 12, 2024
e437426
review
ggwpez Sep 12, 2024
00de16a
prdoc
ggwpez Sep 12, 2024
6e0539f
prdoc
ggwpez Sep 12, 2024
f26c07b
Fix clippy
georgepisaltu Sep 12, 2024
475a976
Add missing migration to people-rococo
ggwpez Sep 16, 2024
ea00e35
Derive PartialEq on some enums
ggwpez Sep 16, 2024
7c597b6
Merge branch 'master' into liam-mbm-try-runtime
ggwpez Sep 16, 2024
fbda868
Merge branch 'master' into liam-mbm-try-runtime
ggwpez Sep 24, 2024
d6ff835
Merge branch 'master' into liam-mbm-try-runtime
ggwpez Sep 24, 2024
9113c2b
Merge branch 'master' into liam-mbm-try-runtime
ggwpez Sep 25, 2024
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
26 changes: 26 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-
pallet-transaction-payment = { path = "../../../../../substrate/frame/transaction-payment", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { path = "../../../../../substrate/frame/transaction-payment/rpc/runtime-api", default-features = false }
pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false }
pallet-example-mbm = { path = "../../../../../substrate/frame/examples/multi-block-migrations", default-features = false }
pallet-migrations = { path = "../../../../../substrate/frame/migrations", default-features = false }
sp-api = { path = "../../../../../substrate/primitives/api", default-features = false }
sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false }
sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false }
Expand Down Expand Up @@ -121,6 +123,8 @@ snowbridge-runtime-common = { path = "../../../../../bridges/snowbridge/runtime/

bridge-hub-common = { path = "../common", default-features = false }



[dev-dependencies]
static_assertions = "1.1"
bridge-hub-test-utils = { path = "../test-utils" }
Expand Down Expand Up @@ -221,6 +225,8 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"pallet-example-mbm/std",
"pallet-migrations/std"
]

runtime-benchmarks = [
Expand Down Expand Up @@ -262,6 +268,8 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"pallet-example-mbm/runtime-benchmarks",
"pallet-migrations/runtime-benchmarks"
]

try-runtime = [
Expand Down Expand Up @@ -296,6 +304,8 @@ try-runtime = [
"snowbridge-pallet-outbound-queue/try-runtime",
"snowbridge-pallet-system/try-runtime",
"sp-runtime/try-runtime",
"pallet-example-mbm/try-runtime",
"pallet-migrations/try-runtime"
]

fast-runtime = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
migrations::FreezeChainOnFailedMigration,
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin},
weights::{ConstantMultiplier, Weight},
Expand Down Expand Up @@ -272,6 +273,7 @@ impl frame_system::Config for Runtime {
/// The action to take on a Runtime Upgrade
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MultiBlockMigrator = PalletMigrations;
}

impl pallet_timestamp::Config for Runtime {
Expand Down Expand Up @@ -662,6 +664,8 @@ impl snowbridge_pallet_system::Config for Runtime {
type InboundDeliveryCost = EthereumInboundQueue;
}

impl pallet_example_mbm::Config for Runtime {}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -727,9 +731,26 @@ construct_runtime!(
// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
MessageQueue: pallet_message_queue = 175,

PalletMigrations: pallet_migrations = 200,
}
);

frame_support::parameter_types! {
pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block;
}

impl pallet_migrations::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxServiceWeight = MbmServiceWeight;
type WeightInfo = ();
type Migrations = ();
type CursorMaxLen = ConstU32<65_536>;
type IdentifierMaxLen = ConstU32<256>;
type MigrationStatusHandler = ();
type FailedMigrationHandler = FreezeChainOnFailedMigration;
}

/// Proper alias for bridge GRANDPA pallet used to bridge with the bulletin chain.
pub type BridgeRococoBulletinGrandpa = BridgePolkadotBulletinGrandpa;
/// Proper alias for bridge messages pallet used to bridge with the bulletin chain.
Expand Down Expand Up @@ -1033,7 +1054,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ sp_api::impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(_: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ sp_api::impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(_: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
unimplemented!()
}

Expand Down
8 changes: 5 additions & 3 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ sp_api::impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade rococo.");
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
Expand Down Expand Up @@ -2500,7 +2500,7 @@ sp_api::impl_runtime_apis! {
#[cfg(all(test, feature = "try-runtime"))]
mod remote_tests {
use super::*;
use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, UpgradeCheckSelect};
use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, TryOnRuntimeUpgradeOpts};
use remote_externalities::{
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport,
};
Expand Down Expand Up @@ -2532,6 +2532,8 @@ mod remote_tests {
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost));
ext.execute_with(|| {
Runtime::on_runtime_upgrade(TryOnRuntimeUpgradeOpts::new().pre_and_post(true).build())
});
}
}
8 changes: 5 additions & 3 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ sp_api::impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade westend.");
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
Expand Down Expand Up @@ -2536,7 +2536,7 @@ sp_api::impl_runtime_apis! {
#[cfg(all(test, feature = "try-runtime"))]
mod remote_tests {
use super::*;
use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, UpgradeCheckSelect};
use frame_try_runtime::{runtime_decl_for_try_runtime::TryRuntime, TryOnRuntimeUpgradeOpts};
use remote_externalities::{
Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport,
};
Expand Down Expand Up @@ -2568,7 +2568,9 @@ mod remote_tests {
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost));
ext.execute_with(|| {
Runtime::on_runtime_upgrade(TryOnRuntimeUpgradeOpts::new().pre_and_post(true).build())
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3157,7 +3157,7 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::TryOnRuntimeUpgradeOpts) -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/examples/multi-block-migrations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ frame-benchmarking = { path = "../../benchmarking", default-features = false, op
log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.10.0", default-features = false }
sp-io = { path = "../../../primitives/io", default-features = false }
sp-std = { path = "../../../primitives/std", default-features = false }

[features]
default = ["std"]
Expand All @@ -33,6 +34,7 @@ std = [
"pallet-migrations/std",
"scale-info/std",
"sp-io/std",
"sp-std/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ use frame_support::{
weights::WeightMeter,
};

#[cfg(feature = "try-runtime")]
use sp_std::collections::btree_map::BTreeMap;

mod benchmarks;
mod tests;
pub mod weights;
Expand Down Expand Up @@ -115,4 +118,29 @@ impl<T: Config, W: weights::WeightInfo> SteppedMigration for LazyMigrationV1<T,
}
Ok(cursor)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, frame_support::sp_runtime::TryRuntimeError> {
use codec::Encode;

// Return the state of the storage before the migration.
Ok(v0::MyMap::<T>::iter().collect::<BTreeMap<_, _>>().encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(prev: Vec<u8>) -> Result<(), frame_support::sp_runtime::TryRuntimeError> {
use codec::Decode;

// Check the state of the storage after the migration.
let prev_map = BTreeMap::<u32, u32>::decode(&mut &prev[..])
.expect("Failed to decode the previous storage state");

for (key, value) in MyMap::<T>::iter() {
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
let prev_value =
prev_map.get(&key).expect("Key not found in the previous storage state");
assert_eq!(value as u32, *prev_value, "Migration failed for key {}", key);
}

Ok(())
}
}
Loading
Loading