From 3bc76474ea01a2a84f91dd0c7161926e31ffdc71 Mon Sep 17 00:00:00 2001 From: MrPai <1164934857@qq.com> Date: Wed, 19 Jul 2023 11:52:48 +0800 Subject: [PATCH] improve sync ledges logic (#1943) --- pallets/liquid-staking/src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pallets/liquid-staking/src/lib.rs b/pallets/liquid-staking/src/lib.rs index 74b95650d..c9d74b6d3 100644 --- a/pallets/liquid-staking/src/lib.rs +++ b/pallets/liquid-staking/src/lib.rs @@ -290,6 +290,8 @@ pub mod pallet { FastUnstakeMatched(T::AccountId, BalanceOf, BalanceOf, BalanceOf), /// Incentive amount was updated IncentiveUpdated(BalanceOf), + /// Not the ideal staking ledger + NonIdealStakingLedger(DerivativeIndex), } #[pallet::error] @@ -934,18 +936,24 @@ pub mod pallet { Self::do_update_ledger(derivative_index, |ledger| { ensure!( - !Self::is_updated(derivative_index) - && XcmRequests::::iter().count().is_zero(), + !Self::is_updated(derivative_index), Error::::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::::InvalidStakingLedger - ); + let requests = XcmRequests::::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::::NonIdealStakingLedger(derivative_index)); + } let key = Self::get_staking_ledger_key(derivative_index); let value = staking_ledger.encode(); ensure!(