Skip to content

Commit

Permalink
fix(migrations): Adjust versions of migration run (#3197)
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Aug 31, 2023
1 parent 9103e6f commit e9b6d89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
41 changes: 31 additions & 10 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,35 @@ where

log::info!("🚚 Running migration to gear-bank with current spec version {version:?}");

if version < 320 {
if version <= 320 {
let mut ops = 0u64;

// Depositing gas from gas nodes.
let gas_nodes_iter = GasNodesOf::<T>::iter();
for (node_id, gas_node) in gas_nodes_iter {
let external = GasHandlerOf::<T>::get_external(node_id)
.expect("Failed to get external id of the node");
let Ok(external) = GasHandlerOf::<T>::get_external(node_id) else {
log::error!("Failed to get external id of {node_id:?}");
continue;
};

let gas_amount = gas_node.total_value();

let gas_price = P::gas_price(gas_amount);
Balances::<T>::unreserve(&external, gas_price);
GearBank::<T>::deposit_gas::<P>(&external, gas_amount)
.expect("Failed to deposit gas");
log::debug!("Gas nodes: {node_id:?} = {gas_amount} ({gas_price:?})");
log::debug!(
"Gas nodes external: {external:?} = {:?}; {:?}",
Balances::<T>::free_balance(&external),
Balances::<T>::reserved_balance(&external)
);
if !Balances::<T>::unreserve(&external, gas_price).is_zero() {
log::error!(
"Failed to unreserve all requested value: {external:?} ({gas_price:?})"
)
}
if let Err(err) = GearBank::<T>::deposit_gas::<P>(&external, gas_amount) {
log::error!("Failed to deposit gas {err:?}: {external:?} ({gas_amount:?})");
continue;
};

// Just random approximate amount of operations,
// that will be meant as write operations.
Expand All @@ -80,8 +95,12 @@ where
let mut deposit = |source: ProgramId, value: u128| {
let source = AccountIdOf::<T>::from_origin(source.into_origin());
let value = value.unique_saturated_into();
Balances::<T>::unreserve(&source, value);
GearBank::<T>::deposit_value(&source, value).expect("Failed to deposit value");
if !Balances::<T>::unreserve(&source, value).is_zero() {
log::error!("Failed to unreserve all requested value: {source:?} ({value:?})");
}
if let Err(err) = GearBank::<T>::deposit_value(&source, value) {
log::error!("Failed to deposit value {err:?}: {source:?} ({value:?})");
};

// Just random approximate amount of operations,
// that will be meant as write operations.
Expand Down Expand Up @@ -119,8 +138,10 @@ where
let accounts_iter = AccountsOf::<T>::iter();
for (account_id, AccountInfo { data, .. }) in accounts_iter {
let reserve = data.reserved;
if !reserve.is_zero() {
Balances::<T>::unreserve(&account_id, reserve);
if !reserve.is_zero() && !Balances::<T>::unreserve(&account_id, reserve).is_zero() {
log::error!(
"Failed to unreserve all requested value: {account_id:?} ({reserve:?})"
);
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/vara/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pub type Migrations = (
pallet_gear_gas::migrations::v2::MigrateToV2<Runtime>,
pallet_gear_messenger::migrations::MigrateToV2<Runtime>,
pallet_gear_staking_rewards::migration::MigrateToV2<Runtime>,
runtime_common::migrations::MigrateToGearBank<Runtime, GasConverter>,
);

0 comments on commit e9b6d89

Please sign in to comment.