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

Add awesome avatars multi-block-migration with pallet-migrations #21

Merged
merged 15 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
31 changes: 26 additions & 5 deletions Cargo.lock

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

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pallet-identity = { version = "32.0.0", default-featu
pallet-insecure-randomness-collective-flip = { version = "20.0.0", default-features = false }
pallet-message-queue = { version = "35.0.0", default-features = false }
pallet-membership = { version = "32.0.0", default-features = false }
pallet-migrations = { version = "2.0.0", default-features = false }
pallet-multisig = { version = "32.0.0", default-features = false }
pallet-nfts = { version = "26.0.0", default-features = false }
pallet-preimage = { version = "32.0.0", default-features = false }
Expand Down Expand Up @@ -155,13 +156,13 @@ orml-vesting = { version = "0.10.0", default-features = false }
bajun-runtime = { path = "runtime/bajun" }

# Ajuna Pallets
pallet-ajuna-affiliates = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-awesome-avatars = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-battle-mogs = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-awesome-avatars-benchmarking = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-nft-transfer = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-nft-staking = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-tournament = { git = "https://github.com/ajuna-network/ajuna-pallets.git", tag = "v0.6.0", default-features = false }
pallet-ajuna-affiliates = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-awesome-avatars = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-battle-mogs = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-awesome-avatars-benchmarking = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-nft-transfer = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-nft-staking = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }
pallet-ajuna-tournament = { git = "https://github.com/ajuna-network/ajuna-pallets.git", branch = "cl/multiblock-migration", default-features = false }

[profile.production]
codegen-units = 1
Expand Down
4 changes: 4 additions & 0 deletions runtime/bajun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pallet-identity = { workspace = true }
pallet-insecure-randomness-collective-flip = { workspace = true }
pallet-membership = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-migrations = { workspace = true }
pallet-multisig = { workspace = true }
pallet-nfts = { workspace = true }
pallet-preimage = { workspace = true }
Expand Down Expand Up @@ -129,6 +130,7 @@ std = [
"pallet-identity/std",
"pallet-membership/std",
"pallet-message-queue/std",
"pallet-migrations/std",
"pallet-multisig/std",
"pallet-nfts/std",
"pallet-preimage/std",
Expand Down Expand Up @@ -179,6 +181,7 @@ runtime-benchmarks = [
"pallet-identity/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-migrations/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
Expand Down Expand Up @@ -217,6 +220,7 @@ try-runtime = [
"pallet-identity/try-runtime",
"pallet-membership/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-migrations/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
Expand Down
81 changes: 71 additions & 10 deletions runtime/bajun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -157,13 +158,8 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
Copy link
Contributor Author

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.

>;

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.
///
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@clangenb clangenb Apr 24, 2024

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions runtime/bajun/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ pub mod cumulus_pallet_parachain_system;
pub mod cumulus_pallet_xcmp_queue;
pub mod frame_system;
pub mod orml_vesting;
pub mod pallet_ajuna_awesome_avatars_mbm;
pub mod pallet_balances;
pub mod pallet_collator_selection;
pub mod pallet_collective;
pub mod pallet_democracy;
pub mod pallet_identity;
pub mod pallet_membership;
pub mod pallet_message_queue;
pub mod pallet_migrations;
pub mod pallet_multisig;
pub mod pallet_nfts;
pub mod pallet_preimage;
Expand Down
102 changes: 102 additions & 0 deletions runtime/bajun/src/weights/pallet_ajuna_awesome_avatars_mbm.rs
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))
}
}
Loading
Loading