Skip to content

Commit f5c99e9

Browse files
authored
Remove unused extrinsic from dapp staking (#1348)
1 parent 2d0aa10 commit f5c99e9

File tree

3 files changed

+0
-123
lines changed

3 files changed

+0
-123
lines changed

pallets/dapp-staking/src/lib.rs

-46
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ pub mod pallet {
392392
NoExpiredEntries,
393393
/// Force call is not allowed in production.
394394
ForceNotAllowed,
395-
/// Account doesn't have the freeze inconsistency
396-
AccountNotInconsistent, // TODO: can be removed after call `fix_account` is removed
397395
}
398396

399397
/// General information about dApp staking protocol state.
@@ -1520,50 +1518,6 @@ pub mod pallet {
15201518

15211519
Self::internal_claim_bonus_reward_for(account, smart_contract)
15221520
}
1523-
1524-
/// A call used to fix accounts with inconsistent state, where frozen balance is actually higher than what's available.
1525-
///
1526-
/// The approach is as simple as possible:
1527-
/// 1. Caller provides an account to fix.
1528-
/// 2. If account is eligible for the fix, all unlocking chunks are modified to be claimable immediately.
1529-
/// 3. The `claim_unlocked` call is executed using the provided account as the origin.
1530-
/// 4. All states are updated accordingly, and the account is no longer in an inconsistent state.
1531-
///
1532-
/// The benchmarked weight of the `claim_unlocked` call is used as a base, and additional overestimated weight is added.
1533-
/// Call doesn't touch any storage items that aren't already touched by the `claim_unlocked` call, hence the simplified approach.
1534-
#[pallet::call_index(100)]
1535-
#[pallet::weight(T::DbWeight::get().reads_writes(4, 1))]
1536-
pub fn fix_account(
1537-
origin: OriginFor<T>,
1538-
account: T::AccountId,
1539-
) -> DispatchResultWithPostInfo {
1540-
Self::ensure_pallet_enabled()?;
1541-
ensure_signed(origin)?;
1542-
1543-
let mut ledger = Ledger::<T>::get(&account);
1544-
let locked_amount_ledger = ledger.total_locked_amount();
1545-
let total_balance = T::Currency::total_balance(&account);
1546-
1547-
if locked_amount_ledger > total_balance {
1548-
// 1. Modify all unlocking chunks so they can be unlocked immediately.
1549-
let current_block: BlockNumber =
1550-
frame_system::Pallet::<T>::block_number().saturated_into();
1551-
ledger
1552-
.unlocking
1553-
.iter_mut()
1554-
.for_each(|chunk| chunk.unlock_block = current_block);
1555-
Ledger::<T>::insert(&account, ledger);
1556-
1557-
// 2. Execute the unlock call, clearing all of the unlocking chunks.
1558-
Self::internal_claim_unlocked(account)?;
1559-
1560-
// 3. In case of success, ensure no fee is paid.
1561-
Ok(Pays::No.into())
1562-
} else {
1563-
// The above logic is designed for a specific scenario and cannot be used otherwise.
1564-
Err(Error::<T>::AccountNotInconsistent.into())
1565-
}
1566-
}
15671521
}
15681522

15691523
impl<T: Config> Pallet<T> {

pallets/dapp-staking/src/test/tests.rs

-72
Original file line numberDiff line numberDiff line change
@@ -3373,78 +3373,6 @@ fn lock_correctly_considers_unlocking_amount() {
33733373
})
33743374
}
33753375

3376-
#[test]
3377-
fn fix_account_scenarios_work() {
3378-
ExtBuilder::default().build_and_execute(|| {
3379-
// 1. Lock some amount correctly, unstake it, try to fix it, and ensure the call fails
3380-
let (account_1, lock_1) = (1, 100);
3381-
assert_lock(account_1, lock_1);
3382-
assert_noop!(
3383-
DappStaking::fix_account(RuntimeOrigin::signed(11), account_1),
3384-
Error::<Test>::AccountNotInconsistent
3385-
);
3386-
3387-
assert_unlock(account_1, lock_1);
3388-
assert_noop!(
3389-
DappStaking::fix_account(RuntimeOrigin::signed(11), account_1),
3390-
Error::<Test>::AccountNotInconsistent
3391-
);
3392-
3393-
// 2. Reproduce the issue where the account has more frozen than balance
3394-
let (account_2, unlock_2) = (2, 13);
3395-
let lock_2 = Balances::total_balance(&account_2);
3396-
assert_lock(account_2, lock_2);
3397-
assert_unlock(account_2, unlock_2);
3398-
3399-
// With the fix implemented, the scenario needs to be reproduced by hand.
3400-
// Account calls `lock`, specifying the amount that is undergoing the unlocking process.
3401-
// It can be either more or less, it doesn't matter for the test or the issue.
3402-
3403-
// But first, a sanity check.
3404-
assert_noop!(
3405-
DappStaking::lock(RuntimeOrigin::signed(account_2), unlock_2),
3406-
Error::<Test>::ZeroAmount,
3407-
);
3408-
3409-
// Now reproduce the incorrect lock/freeze operation.
3410-
let mut ledger = Ledger::<Test>::get(&account_2);
3411-
ledger.add_lock_amount(unlock_2);
3412-
assert_ok!(DappStaking::update_ledger(&account_2, ledger));
3413-
use crate::CurrentEraInfo;
3414-
CurrentEraInfo::<Test>::mutate(|era_info| {
3415-
era_info.add_locked(unlock_2);
3416-
});
3417-
assert!(
3418-
Balances::free_balance(&account_2)
3419-
< Ledger::<Test>::get(&account_2).total_locked_amount(),
3420-
"Sanity check."
3421-
);
3422-
3423-
// Now fix the account
3424-
assert_ok!(DappStaking::fix_account(
3425-
RuntimeOrigin::signed(11),
3426-
account_2
3427-
));
3428-
System::assert_last_event(RuntimeEvent::DappStaking(Event::ClaimedUnlocked {
3429-
account: account_2,
3430-
amount: unlock_2,
3431-
}));
3432-
3433-
// Post-fix checks
3434-
assert_eq!(
3435-
Balances::free_balance(&account_2),
3436-
Ledger::<Test>::get(&account_2).total_locked_amount(),
3437-
"After the fix, balances should be equal."
3438-
);
3439-
3440-
// Cannot fix the same account again.
3441-
assert_noop!(
3442-
DappStaking::fix_account(RuntimeOrigin::signed(11), account_2),
3443-
Error::<Test>::AccountNotInconsistent
3444-
);
3445-
})
3446-
}
3447-
34483376
#[test]
34493377
fn claim_staker_rewards_for_basic_example_is_ok() {
34503378
ExtBuilder::default().build_and_execute(|| {

pallets/dapp-staking/src/types.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1618,11 +1618,6 @@ pub struct TiersConfiguration<NT: Get<u32>, T: TierSlotsFunc, P: Get<FixedU128>>
16181618
pub(crate) _phantom: PhantomData<(T, P)>,
16191619
}
16201620

1621-
// Some TODOs:
1622-
// Some parts regarding tiers should be refactored.
1623-
// * There's no need to keep thresholds in two separate storage items since the calculation can always be done compared to the
1624-
// anchor value of 5 cents. This still needs to be checked & investigated, but it's worth a try.
1625-
16261621
impl<NT: Get<u32>, T: TierSlotsFunc, P: Get<FixedU128>> TiersConfiguration<NT, T, P> {
16271622
/// Check if parameters are valid.
16281623
pub fn is_valid(&self) -> bool {

0 commit comments

Comments
 (0)