Skip to content

Commit

Permalink
improve sync ledges logic (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
mclyk authored Jul 19, 2023
1 parent 9657827 commit 3bc7647
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pallets/liquid-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ pub mod pallet {
FastUnstakeMatched(T::AccountId, BalanceOf<T>, BalanceOf<T>, BalanceOf<T>),
/// Incentive amount was updated
IncentiveUpdated(BalanceOf<T>),
/// Not the ideal staking ledger
NonIdealStakingLedger(DerivativeIndex),
}

#[pallet::error]
Expand Down Expand Up @@ -934,18 +936,24 @@ pub mod pallet {

Self::do_update_ledger(derivative_index, |ledger| {
ensure!(
!Self::is_updated(derivative_index)
&& XcmRequests::<T>::iter().count().is_zero(),
!Self::is_updated(derivative_index),
Error::<T>::StakingLedgerLocked
);
// only allow to feed rewards
// slashes should be handled properly offchain
ensure!(
staking_ledger.total > ledger.total
&& staking_ledger.active > ledger.active
&& staking_ledger.unlocking == ledger.unlocking,
Error::<T>::InvalidStakingLedger
);
let requests = XcmRequests::<T>::iter().count();
if staking_ledger.total < ledger.total
|| staking_ledger.active < ledger.active
|| staking_ledger.unlocking != ledger.unlocking
|| !requests.is_zero()
{
log::trace!(
target: "liquidStaking::set_staking_ledger::invalidStakingLedger",
"index: {:?}, staking_ledger: {:?}, xcm_request: {:?}",
&derivative_index,
&staking_ledger,
requests,
);
Self::deposit_event(Event::<T>::NonIdealStakingLedger(derivative_index));
}
let key = Self::get_staking_ledger_key(derivative_index);
let value = staking_ledger.encode();
ensure!(
Expand Down

0 comments on commit 3bc7647

Please sign in to comment.