-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add awesome avatars multi-block-migration with pallet-migrations #21
Changes from 10 commits
2c44d7e
c1bba11
9de89d8
c1c9d48
9365a5c
54b0369
4828945
fd3496a
9073b1b
ff715d6
1fed21d
a65c1d5
5c69608
564d813
a64a060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ use frame_support::{ | |
construct_runtime, | ||
dispatch::DispatchClass, | ||
genesis_builder_helper::{build_config, create_default_config}, | ||
migrations::{FailedMigrationHandler, FailedMigrationHandling, MigrationStatusHandler}, | ||
pallet_prelude::ConstU32, | ||
parameter_types, | ||
traits::{ | ||
|
@@ -157,13 +158,8 @@ pub type Executive = frame_executive::Executive< | |
frame_system::ChainContext<Runtime>, | ||
Runtime, | ||
AllPalletsWithSystem, | ||
Migrations, | ||
>; | ||
|
||
type Migrations = (pallet_ajuna_awesome_avatars::migration::v6::MigrateToV6<Runtime>,); | ||
|
||
//type Migrations = (pallet_ajuna_awesome_avatars::migration::v6::MigrateToV6<Runtime>,); | ||
|
||
/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the | ||
/// node's balance type. | ||
/// | ||
|
@@ -379,13 +375,75 @@ impl frame_system::Config for Runtime { | |
/// The Block provider type | ||
type Block = Block; | ||
type RuntimeTask = RuntimeTask; | ||
type SingleBlockMigrations = (); | ||
type MultiBlockMigrator = (); | ||
type SingleBlockMigrations = SingleBlockMigrations; | ||
type MultiBlockMigrator = pallet_migrations::Pallet<Runtime>; | ||
type PreInherents = (); | ||
type PostInherents = (); | ||
type PostTransactions = (); | ||
} | ||
|
||
type SingleBlockMigrations = (pallet_ajuna_awesome_avatars::migration::v6::MigrateToV6<Runtime>,); | ||
|
||
#[cfg(not(feature = "runtime-benchmarks"))] | ||
use mbm::MultiBlockMigrations; | ||
|
||
#[cfg(not(feature = "runtime-benchmarks"))] | ||
mod mbm { | ||
use crate::Runtime; | ||
use pallet_ajuna_awesome_avatars::migration::v6::mbm::{ | ||
LazyMigrationAvatarV5ToV6, LazyMigrationPlayerSeasonConfigsV5ToV6, | ||
LazyMigrationSeasonStatsV5ToV6, LazyTradeStatsMapCleanup, | ||
}; | ||
|
||
use crate::weights::pallet_ajuna_awesome_avatars_mbm::WeightInfo as AaaMbmWeight; | ||
|
||
pub type MultiBlockMigrations = ( | ||
LazyMigrationPlayerSeasonConfigsV5ToV6<Runtime, AaaMbmWeight<Runtime>>, | ||
LazyMigrationSeasonStatsV5ToV6<Runtime, AaaMbmWeight<Runtime>>, | ||
LazyMigrationAvatarV5ToV6<Runtime, AaaMbmWeight<Runtime>>, | ||
LazyTradeStatsMapCleanup<Runtime, AaaMbmWeight<Runtime>>, | ||
); | ||
} | ||
|
||
parameter_types! { | ||
pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; | ||
} | ||
Comment on lines
+408
to
+410
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo: Double check if we should be more conservative here. Substrate doesn't have meaningful example value in their test runtime, but I think 80% should be ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity has now introduced the same weight as mine. 80% percent allowed usage of a max value seems to be the rule of thumb for any weight-limited operation: https://github.com/paritytech/polkadot-sdk/pull/4251/files |
||
|
||
impl pallet_migrations::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
type CursorMaxLen = ConstU32<65_536>; | ||
type IdentifierMaxLen = ConstU32<256>; | ||
type MigrationStatusHandler = LoggerMigrationStatusHandler; | ||
type FailedMigrationHandler = frame_support::migrations::FreezeChainOnFailedMigration; | ||
type MaxServiceWeight = MbmServiceWeight; | ||
type WeightInfo = weights::pallet_migrations::WeightInfo<Runtime>; | ||
#[cfg(feature = "runtime-benchmarks")] | ||
type Migrations = pallet_migrations::mock_helpers::MockedMigrations; | ||
#[cfg(not(feature = "runtime-benchmarks"))] | ||
type Migrations = MultiBlockMigrations; | ||
} | ||
|
||
/// Records all started and completed upgrades in `UpgradesStarted` and `UpgradesCompleted`. | ||
pub struct LoggerMigrationStatusHandler; | ||
impl MigrationStatusHandler for LoggerMigrationStatusHandler { | ||
fn started() { | ||
log::info!("MigrationStatusHandler started"); | ||
} | ||
|
||
fn completed() { | ||
log::info!("MigrationStatusHandler completed"); | ||
} | ||
} | ||
|
||
/// Records all failed upgrades in `UpgradesFailed`. | ||
pub struct MockedFailedMigrationHandler; | ||
impl FailedMigrationHandler for MockedFailedMigrationHandler { | ||
fn failed(migration: Option<u32>) -> FailedMigrationHandling { | ||
log::error!("FailedMigrationHandler failed at: {migration:?}"); | ||
FailedMigrationHandling::KeepStuck | ||
} | ||
} | ||
|
||
impl pallet_sudo::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
type RuntimeCall = RuntimeCall; | ||
|
@@ -893,6 +951,7 @@ construct_runtime!( | |
Proxy: pallet_proxy = 7, | ||
Scheduler: pallet_scheduler = 8, | ||
Preimage: pallet_preimage = 9, | ||
Migrations: pallet_migrations = 10, | ||
|
||
// Monetary stuff. | ||
Balances: pallet_balances = 15, | ||
|
@@ -961,6 +1020,7 @@ mod benches { | |
[pallet_membership, CouncilMembership] | ||
// [pallet_membership, TechnicalCommitteeMembership] // writes to the same file | ||
[pallet_message_queue, MessageQueue] | ||
[pallet_migrations, Migrations] | ||
[pallet_multisig, Multisig] | ||
[pallet_preimage, Preimage] | ||
[pallet_proxy, Proxy] | ||
|
@@ -971,12 +1031,13 @@ mod benches { | |
// [pallet_treasury, Treasury] // treasury config is broken, needs fixes | ||
[pallet_utility, Utility] | ||
[pallet_ajuna_awesome_avatars, AwesomeAvatarsBench::<Runtime>] | ||
// Note: We have to update the path to the `WeightInfo` definition after | ||
// running the benchmarks: `pallet_ajuna_awesome_avatars::migration::v6::WeightInfo` | ||
[pallet_ajuna_awesome_avatars_mbm, AwesomeAvatars] | ||
[pallet_nfts, Nft] | ||
); | ||
// Use this section if you want to benchmark individual pallets | ||
// define_benchmarks!( | ||
// [orml_vesting, Vesting] | ||
// ) | ||
// define_benchmarks!([pallet_ajuna_awesome_avatars_mbm, AwesomeAvatars]); | ||
} | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Ajuna Node | ||
// Copyright (C) 2022 BlogaTech AG | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Autogenerated weights for `pallet_ajuna_awesome_avatars_mbm` | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 36.0.0 | ||
//! DATE: 2024-04-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! WORST CASE MAP SIZE: `1000000` | ||
//! HOSTNAME: `DESKTOP-0F6V7QQ`, CPU: `Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz` | ||
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bajun-rococo-local")`, DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// ./target/release/bajun-node | ||
// benchmark | ||
// pallet | ||
// --chain=bajun-rococo-local | ||
// --steps=50 | ||
// --repeat=20 | ||
// --pallet=pallet_ajuna_awesome_avatars_mbm | ||
// --extrinsic=* | ||
// --wasm-execution=compiled | ||
// --heap-pages=4096 | ||
// --header=./HEADER-AGPL | ||
// --output=./runtime/bajun/src/weights/pallet_ajuna_awesome_avatars_mbm.rs | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
#![allow(missing_docs)] | ||
|
||
use frame_support::{traits::Get, weights::Weight}; | ||
use core::marker::PhantomData; | ||
|
||
/// Weight functions for `pallet_ajuna_awesome_avatars_mbm`. | ||
pub struct WeightInfo<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> pallet_ajuna_awesome_avatars::migration::v6::WeightInfo for WeightInfo<T> { | ||
/// Storage: `AwesomeAvatars::PlayerSeasonConfigs` (r:2 w:1) | ||
/// Proof: `AwesomeAvatars::PlayerSeasonConfigs` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) | ||
/// Storage: `AwesomeAvatars::TradeStatsMap` (r:0 w:1) | ||
/// Proof: `AwesomeAvatars::TradeStatsMap` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) | ||
fn player_season_configs_step() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `156` | ||
// Estimated: `6048` | ||
// Minimum execution time: 26_000_000 picoseconds. | ||
Weight::from_parts(57_200_000, 0) | ||
.saturating_add(Weight::from_parts(0, 6048)) | ||
.saturating_add(T::DbWeight::get().reads(2)) | ||
.saturating_add(T::DbWeight::get().writes(2)) | ||
} | ||
/// Storage: `AwesomeAvatars::SeasonStats` (r:2 w:1) | ||
/// Proof: `AwesomeAvatars::SeasonStats` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) | ||
/// Storage: `AwesomeAvatars::TradeStatsMap` (r:1 w:1) | ||
/// Proof: `AwesomeAvatars::TradeStatsMap` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) | ||
fn season_stats_step() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `199` | ||
// Estimated: `6048` | ||
// Minimum execution time: 40_200_000 picoseconds. | ||
Weight::from_parts(46_000_000, 0) | ||
.saturating_add(Weight::from_parts(0, 6048)) | ||
.saturating_add(T::DbWeight::get().reads(3)) | ||
.saturating_add(T::DbWeight::get().writes(2)) | ||
} | ||
/// Storage: `AwesomeAvatars::Avatars` (r:2 w:1) | ||
/// Proof: `AwesomeAvatars::Avatars` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) | ||
fn avatar_step() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `168` | ||
// Estimated: `6294` | ||
// Minimum execution time: 31_400_000 picoseconds. | ||
Weight::from_parts(32_900_000, 0) | ||
.saturating_add(Weight::from_parts(0, 6294)) | ||
.saturating_add(T::DbWeight::get().reads(2)) | ||
.saturating_add(T::DbWeight::get().writes(1)) | ||
} | ||
/// Storage: `AwesomeAvatars::TradeStatsMap` (r:2 w:1) | ||
/// Proof: `AwesomeAvatars::TradeStatsMap` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) | ||
fn trade_stats_map_cleanup_step() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `136` | ||
// Estimated: `6024` | ||
// Minimum execution time: 25_900_000 picoseconds. | ||
Weight::from_parts(32_200_000, 0) | ||
.saturating_add(Weight::from_parts(0, 6024)) | ||
.saturating_add(T::DbWeight::get().reads(2)) | ||
.saturating_add(T::DbWeight::get().writes(1)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is obsolete now, the single block migrations are also configured in frame-system now.