From 38227925b71b846d2bf7f741ebc8c8ac0763a5fe Mon Sep 17 00:00:00 2001 From: Matthew Orris <--help> Date: Sat, 16 Dec 2023 10:13:33 -0700 Subject: [PATCH] fix: update translate_lock_to_freeze weights and comments --- pallets/capacity/src/migration/v3.rs | 18 ++++++++++++++++-- pallets/time-release/src/migration/v2.rs | 9 ++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pallets/capacity/src/migration/v3.rs b/pallets/capacity/src/migration/v3.rs index 7044bbee7c..18ad5bf5e1 100644 --- a/pallets/capacity/src/migration/v3.rs +++ b/pallets/capacity/src/migration/v3.rs @@ -30,9 +30,23 @@ where account_id: T::AccountId, amount: OldCurrency::Balance, ) -> Weight { - // TODO: Confirm reads and writes + // 1 read get Locks: remove_lock: set locks + // 1 read get Freezes + // 1 read get Account + // 1 write set Account: update_locks->try_mutate_account->ensure_upgraded: if account is *not* already upgraded. + // We could avoid this write by calling the upgrade script before running the migration, + // which would ensure that all accounts are upgraded. + // 1 write set Account: update_locks->try_mutate_account: set account data + // 1 read get Locks: update_locks: set existed with `contains_key` + // 1 write set Locks: update_locks->Locks::remove: remove existed OldCurrency::remove_lock(STAKING_ID, &account_id); + // 1 read get Freezes: set_freeze: set locks + // 1 read get Locks: update_freezes: Locks::get().iter() + // 1 write set Account: update_freezes->mutate_account->try_mutate_account->ensure_upgraded: if account is *not* already upgraded. + // 1 write set Account: update_freezes->mutate_account->try_mutate_account: set account data + // 1 write set Freezes: update_freezes: Freezes::insert + ::Currency::set_freeze( &FreezeReason::Staked.into(), &account_id, @@ -43,7 +57,7 @@ where }); log::info!(target: LOG_TARGET, "🔄 migrated account 0x{:?}, amount:{:?}", HexDisplay::from(&account_id.encode()), amount.into()); - T::DbWeight::get().reads_writes(5, 3) + T::DbWeight::get().reads_writes(6, 4) } } diff --git a/pallets/time-release/src/migration/v2.rs b/pallets/time-release/src/migration/v2.rs index 213cbc598e..0829a14845 100644 --- a/pallets/time-release/src/migration/v2.rs +++ b/pallets/time-release/src/migration/v2.rs @@ -31,14 +31,16 @@ where amount: OldCurrency::Balance, ) -> Weight { // 1 read get Locks - // 1 read get Freeze + // 1 read get Freezes // 1 read get Account // 1 write set Account + // 1 read get Locks: update_locks: set existed with `contains_key` // 1 write set Locks OldCurrency::remove_lock(RELEASE_LOCK_ID, &account_id); // 1 read get Freeze // 1 read get Locks + // 1 write set Account: update_freezes->mutate_account->try_mutate_account: set account data // 1 write set Freeze T::Currency::set_freeze( &FreezeReason::TimeReleaseVesting.into(), @@ -55,7 +57,7 @@ where ); }); - T::DbWeight::get().reads_writes(5, 3) + T::DbWeight::get().reads_writes(6, 4) } } @@ -80,7 +82,8 @@ where } log::info!(target: LOG_TARGET, "🔄 Time Release Locks->Freezes migration started"); - let mut total_weight = T::DbWeight::get().reads_writes(0, 0); + // The migration started with 1r to get the on_chain_storage_version + let mut total_weight = T::DbWeight::get().reads_writes(1, 0); let mut total_accounts_migrated = 0u32; // Get all the keys(accounts) from the ReleaseSchedules storage