Skip to content

Commit

Permalink
fix: update translate_lock_to_freeze weights and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Orris committed Dec 16, 2023
1 parent e12d616 commit 3822792
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 16 additions & 2 deletions pallets/capacity/src/migration/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 42 in pallets/capacity/src/migration/v3.rs

View check run for this annotation

Codecov / codecov/patch

pallets/capacity/src/migration/v3.rs#L42

Added line #L42 was not covered by tests

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

<T as Config>::Currency::set_freeze(
&FreezeReason::Staked.into(),

Check warning on line 51 in pallets/capacity/src/migration/v3.rs

View check run for this annotation

Codecov / codecov/patch

pallets/capacity/src/migration/v3.rs#L50-L51

Added lines #L50 - L51 were not covered by tests
&account_id,
Expand All @@ -43,7 +57,7 @@ where
});

Check warning on line 57 in pallets/capacity/src/migration/v3.rs

View check run for this annotation

Codecov / codecov/patch

pallets/capacity/src/migration/v3.rs#L55-L57

Added lines #L55 - L57 were not covered by tests

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)
}

Check warning on line 61 in pallets/capacity/src/migration/v3.rs

View check run for this annotation

Codecov / codecov/patch

pallets/capacity/src/migration/v3.rs#L59-L61

Added lines #L59 - L61 were not covered by tests
}

Expand Down
9 changes: 6 additions & 3 deletions pallets/time-release/src/migration/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 39 in pallets/time-release/src/migration/v2.rs

View check run for this annotation

Codecov / codecov/patch

pallets/time-release/src/migration/v2.rs#L39

Added line #L39 was not covered by tests

// 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(),
Expand All @@ -55,7 +57,7 @@ where
);
});

Check warning on line 58 in pallets/time-release/src/migration/v2.rs

View check run for this annotation

Codecov / codecov/patch

pallets/time-release/src/migration/v2.rs#L58

Added line #L58 was not covered by tests

T::DbWeight::get().reads_writes(5, 3)
T::DbWeight::get().reads_writes(6, 4)
}

Check warning on line 61 in pallets/time-release/src/migration/v2.rs

View check run for this annotation

Codecov / codecov/patch

pallets/time-release/src/migration/v2.rs#L60-L61

Added lines #L60 - L61 were not covered by tests
}

Expand All @@ -80,7 +82,8 @@ where
}

log::info!(target: LOG_TARGET, "🔄 Time Release Locks->Freezes migration started");

Check warning on line 84 in pallets/time-release/src/migration/v2.rs

View check run for this annotation

Codecov / codecov/patch

pallets/time-release/src/migration/v2.rs#L84

Added line #L84 was not covered by tests
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;

Check warning on line 87 in pallets/time-release/src/migration/v2.rs

View check run for this annotation

Codecov / codecov/patch

pallets/time-release/src/migration/v2.rs#L86-L87

Added lines #L86 - L87 were not covered by tests

// Get all the keys(accounts) from the ReleaseSchedules storage
Expand Down

0 comments on commit 3822792

Please sign in to comment.