tangle
tangle copied to clipboard
[TASK] Seperate roles.withdraw_unbonded from stake.withdraw_unbonded
Problem: Currently roles.withdraw_unbonded wraps stake.withdraw_unbonded
/// Withdraw unbond funds after un-bonding period has passed.
///
/// # Parameters
///
/// - `origin`: Origin of the transaction.
///
/// This function will return error if
/// - If there is any active role assigned to the user.
/// NOTE : This call wraps pallet_staking.withdraw_unbonded, so the
/// pallet_staking.withdraw_unbonded call should be blocked in runtime
#[pallet::weight(<T as pallet::Config>::WeightInfo::withdraw_unbonded())]
#[pallet::call_index(5)]
pub fn withdraw_unbonded(origin: OriginFor<T>) -> DispatchResult {
let restaker_account = ensure_signed(origin.clone())?;
// Ensure no role is assigned to the restaker_account and is eligible to withdraw.
ensure!(Self::can_exit(restaker_account.clone()), Error::<T>::HasRoleAssigned);
// if any unlocking restake, then remove any eligible restake
let mut ledger =
Ledger::<T>::get(&restaker_account.clone()).ok_or(Error::<T>::NoProfileFound)?;
if !ledger.unlocking.is_empty() {
let current_era =
Self::active_restaker_era().ok_or(Error::<T>::InvalidEraToReward)?.index;
ledger.unlocking.retain(|x| x.era >= current_era);
Ledger::<T>::insert(restaker_account, ledger);
}
// Withdraw unbond funds.
let res = pallet_staking::Pallet::<T>::withdraw_unbonded(origin, 0);
match res {
Ok(_) => Ok(()),
Err(dispatch_post_info) => Err(dispatch_post_info.error),
}
}
But since we split restaking to be based on eras, I could "unbond" my restake in roles.update_profile
and then "withdraw_unbond" to release my restake. But this extrinsic will fail since pallet_staking.withdraw_unbonded will fail.
Solution:
- Create an extrinsic to release "unbonded" restake for restakers
Problem:
- The restakers have no financial incentive to call this extrinsic, maybe this should be a precondition before unbond call