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 14 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ good to test functionality after the runtime upgrade happened.
The following command overrides the runtime with the local build of the upgraded runtime and will run the migration
upon the next block, which means as soon as we send an arbitrary extrinsic.

#### Test Runtime Upgrades with chopsticks

We now have a zombienet setup that is intended to test runtime upgrades at `zombienet/`. See the documentation there.

```bash
nvm use 20
npx @acala-network/chopsticks@latest --config ./chopsticks/bajun.yml --wasm-override ./target/release/wbuild/bajun-runtime/bajun_runtime.compact.compressed.wasm
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::ForceUnstuck
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 will make the chain resume normal operation and allow extrinsics again, but it will not continue the migration. Here, I suggest we assume that it works now after testing with the production data. Otherwise we could start integrating the pallet-safe-mode, which is not audited yet though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest keeping it at ForceUnstuck. The only thing that could go wrong here is that a few entries are messed up, but no system logic is touched. pallet-safe-mode can be evaluated at another time.

Copy link

@ggwpez ggwpez Apr 26, 2024

Choose a reason for hiding this comment

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

To me it looks like you are actually using the freeze option @clangenb :
type FailedMigrationHandler = frame_support::migrations::FreezeChainOnFailedMigration;.
Anything starting with "Mock" should only be used for testing/benchmarking - not prod.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooops, good catch. Fuck up on my end. Thanks for pointing this out!

}
}

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
Loading
Loading