Restore claim_deallocation call to validator-sets pallet

This commit is contained in:
Luke Parker
2025-09-15 21:32:01 -04:00
parent 55e845fe12
commit c0a4d85ae6
2 changed files with 37 additions and 17 deletions

View File

@@ -725,7 +725,7 @@ mod pallet {
impl<T: Config> Pallet<T> { impl<T: Config> Pallet<T> {
/* /*
#[pallet::call_index(0)] #[pallet::call_index(0)]
#[pallet::weight(0)] // TODO #[pallet::weight((0, DispatchClass::Operational))] // TODO
pub fn set_keys( pub fn set_keys(
origin: OriginFor<T>, origin: OriginFor<T>,
network: ExternalNetworkId, network: ExternalNetworkId,
@@ -758,7 +758,7 @@ mod pallet {
} }
#[pallet::call_index(1)] #[pallet::call_index(1)]
#[pallet::weight(0)] // TODO #[pallet::weight((0, DispatchClass::Operational))] // TODO
pub fn report_slashes( pub fn report_slashes(
origin: OriginFor<T>, origin: OriginFor<T>,
network: ExternalNetworkId, network: ExternalNetworkId,
@@ -787,7 +787,7 @@ mod pallet {
*/ */
#[pallet::call_index(2)] #[pallet::call_index(2)]
#[pallet::weight(0)] // TODO #[pallet::weight((0, DispatchClass::Normal))] // TODO
pub fn set_embedded_elliptic_curve_keys( pub fn set_embedded_elliptic_curve_keys(
origin: OriginFor<T>, origin: OriginFor<T>,
keys: serai_primitives::crypto::SignedEmbeddedEllipticCurveKeys, keys: serai_primitives::crypto::SignedEmbeddedEllipticCurveKeys,
@@ -801,7 +801,7 @@ mod pallet {
} }
#[pallet::call_index(3)] #[pallet::call_index(3)]
#[pallet::weight(0)] // TODO #[pallet::weight((0, DispatchClass::Normal))] // TODO
pub fn allocate(origin: OriginFor<T>, network: NetworkId, amount: Amount) -> DispatchResult { pub fn allocate(origin: OriginFor<T>, network: NetworkId, amount: Amount) -> DispatchResult {
let validator = ensure_signed(origin)?; let validator = ensure_signed(origin)?;
Coins::<T>::transfer_fn(validator, Self::account(), Balance { coin: Coin::Serai, amount })?; Coins::<T>::transfer_fn(validator, Self::account(), Balance { coin: Coin::Serai, amount })?;
@@ -811,7 +811,7 @@ mod pallet {
} }
#[pallet::call_index(4)] #[pallet::call_index(4)]
#[pallet::weight(0)] // TODO #[pallet::weight((0, DispatchClass::Normal))] // TODO
pub fn deallocate(origin: OriginFor<T>, network: NetworkId, amount: Amount) -> DispatchResult { pub fn deallocate(origin: OriginFor<T>, network: NetworkId, amount: Amount) -> DispatchResult {
let account = ensure_signed(origin)?; let account = ensure_signed(origin)?;
@@ -824,27 +824,19 @@ mod pallet {
Ok(()) Ok(())
} }
/*
#[pallet::call_index(5)] #[pallet::call_index(5)]
#[pallet::weight((0, DispatchClass::Operational))] // TODO #[pallet::weight((0, DispatchClass::Normal))] // TODO
pub fn claim_deallocation( pub fn claim_deallocation(
origin: OriginFor<T>, origin: OriginFor<T>,
network: NetworkId, network: NetworkId,
session: Session, session: Session,
) -> DispatchResult { ) -> DispatchResult {
let account = ensure_signed(origin)?; let account = ensure_signed(origin)?;
let Some(amount) = Self::take_deallocatable_amount(network, session, account) else { let amount = Abstractions::<T>::claim_delayed_deallocation(account, network, session)
Err(Error::<T>::NonExistentDeallocation)? .map_err(Error::<T>::DeallocationError)?;
}; Coins::<T>::transfer_fn(Self::account(), account, Balance { coin: Coin::Serai, amount })?;
Coins::<T>::transfer_fn(
Self::account(),
account,
Balance { coin: Coin::Serai, amount },
)?;
Self::deposit_event(Event::DeallocationClaimed { validator: account, network, session });
Ok(()) Ok(())
} }
*/
} }
/* /*

View File

@@ -123,6 +123,10 @@ pub enum DeallocationError {
NotEnoughAllocated, NotEnoughAllocated,
/// The remaining allocation was non-zero and would be less than a key share. /// The remaining allocation was non-zero and would be less than a key share.
RemainingAllocationLessThanKeyShare, RemainingAllocationLessThanKeyShare,
/// The delay has yet to be satisfied.
DelayNotSatisfied,
/// No delayed deallocation was present.
NoDelayedDeallocation,
} }
pub(crate) trait Sessions { pub(crate) trait Sessions {
@@ -164,6 +168,16 @@ pub(crate) trait Sessions {
validator: Public, validator: Public,
amount: Amount, amount: Amount,
) -> Result<DeallocationTimeline, DeallocationError>; ) -> Result<DeallocationTimeline, DeallocationError>;
/// Claim a delayed allocation.
///
/// This does not perform any transfers of any coins/tokens. It solely performs the book-keeping
/// of it.
fn claim_delayed_deallocation(
validator: Public,
network: NetworkId,
session: Session,
) -> Result<Amount, DeallocationError>;
} }
impl<Storage: SessionsStorage> Sessions for Storage { impl<Storage: SessionsStorage> Sessions for Storage {
@@ -432,4 +446,18 @@ impl<Storage: SessionsStorage> Sessions for Storage {
// immediately handle the deallocation // immediately handle the deallocation
Ok(DeallocationTimeline::Immediate) Ok(DeallocationTimeline::Immediate)
} }
fn claim_delayed_deallocation(
validator: Public,
network: NetworkId,
session: Session,
) -> Result<Amount, DeallocationError> {
if Storage::CurrentSession::get(network).map(|session| session.0) <
Some(session).map(|session| session.0)
{
Err(DeallocationError::DelayNotSatisfied)?;
}
Storage::DelayedDeallocations::take(validator, session)
.ok_or(DeallocationError::NoDelayedDeallocation)
}
} }