--- a/pallets/app-promotion/src/lib.rs +++ b/pallets/app-promotion/src/lib.rs @@ -84,7 +84,7 @@ use sp_runtime::{ Perbill, traits::{BlockNumberProvider, CheckedAdd, CheckedSub, AccountIdConversion, Zero}, - ArithmeticError, + ArithmeticError, DispatchError, }; pub const LOCK_IDENTIFIER: [u8; 8] = *b"appstake"; @@ -845,7 +845,7 @@ stakers .into_iter() .try_for_each(|s| -> Result<_, DispatchError> { - if let Some(lock) = Self::get_locked_balance(&s) { + if let Some(BalanceLock { amount, .. }) = Self::get_locked_balance(&s) { if let Some(_) = Self::get_frozen_balance(&s) { return Err(Error::::InconsistencyState.into()); } @@ -855,7 +855,7 @@ &s, ); - Self::set_freeze_unchecked(&s, lock.amount); + Self::set_freeze_with_result(&s, amount)?; Ok(()) } else { Ok(()) @@ -990,8 +990,8 @@ Self::get_frozen_balance(staker) .unwrap_or_default() .checked_add(&amount) - .map(|freeze| Self::set_freeze_unchecked(staker, freeze)) - .ok_or(ArithmeticError::Overflow.into()) + .map(|freeze| Self::set_freeze_with_result(staker, freeze)) + .ok_or::(ArithmeticError::Overflow.into())? } /// Sets the new state of a balance locked by the pallet. @@ -1019,17 +1019,25 @@ /// - `staker`: staker account. /// - `amount`: amount of frozen funds. fn set_freeze_unchecked(staker: &T::AccountId, amount: BalanceOf) { + Self::set_freeze_with_result(staker, amount); + } + + /// Sets the new state of a balance frozen by the pallet. + /// + /// - `staker`: staker account. + /// - `amount`: amount of frozen funds. + fn set_freeze_with_result(staker: &T::AccountId, amount: BalanceOf) -> DispatchResult { if amount.is_zero() { <::Currency as MutateFreeze>::thaw( &T::FreezeIdentifier::get(), &staker, - ); + ) } else { <::Currency as MutateFreeze>::set_freeze( &T::FreezeIdentifier::get(), staker, amount, - ); + ) } } --- a/runtime/common/config/substrate.rs +++ b/runtime/common/config/substrate.rs @@ -132,7 +132,8 @@ pub const ExistentialDeposit: u128 = EXISTENTIAL_DEPOSIT; pub const MaxLocks: u32 = 50; pub const MaxReserves: u32 = 50; - pub const MaxFreezes: u32 = 20; + pub const MaxHolds: u32 = 10; + pub const MaxFreezes: u32 = 10; } impl pallet_balances::Config for Runtime { @@ -150,7 +151,7 @@ type WeightInfo = pallet_balances::weights::SubstrateWeight; type HoldIdentifier = [u8; 16]; type FreezeIdentifier = [u8; 16]; - type MaxHolds = (); + type MaxHolds = MaxHolds; type MaxFreezes = MaxFreezes; }