From 8d83f8bc48933fccc38c3b758fa2c626d2bbb930 Mon Sep 17 00:00:00 2001 From: Oren Date: Sun, 15 Dec 2024 16:21:34 +0200 Subject: [PATCH] do automatic unfreeze only for going over min stake --- x/dualstaking/keeper/delegate.go | 3 +-- x/pairing/keeper/staking.go | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/x/dualstaking/keeper/delegate.go b/x/dualstaking/keeper/delegate.go index 3bf28f4343..c4a398c8aa 100644 --- a/x/dualstaking/keeper/delegate.go +++ b/x/dualstaking/keeper/delegate.go @@ -165,9 +165,8 @@ func (k Keeper) AfterDelegationModified(ctx sdk.Context, delegator, provider str details["stake"] = entry.TotalStake().String() utils.LogLavaEvent(ctx, k.Logger(ctx), types.FreezeFromUnbond, details, "freezing provider due to stake below min spec stake") entry.Freeze() - } else if delegator == entry.Vault && entry.IsFrozen() && !entry.IsJailed(ctx.BlockTime().UTC().Unix()) { - entry.UnFreeze(k.epochstorageKeeper.GetCurrentNextEpoch(ctx) + 1) } + k.epochstorageKeeper.SetStakeEntryCurrent(ctx, *entry) } diff --git a/x/pairing/keeper/staking.go b/x/pairing/keeper/staking.go index 4e4d8ae221..f9c04cf7fc 100644 --- a/x/pairing/keeper/staking.go +++ b/x/pairing/keeper/staking.go @@ -84,6 +84,14 @@ func (k Keeper) StakeNewEntry(ctx sdk.Context, validator, creator, chainID strin // new staking takes effect from the next block stakeAppliedBlock := uint64(ctx.BlockHeight()) + 1 + nextEpoch, err := k.epochStorageKeeper.GetNextEpoch(ctx, uint64(ctx.BlockHeight())) + if err != nil { + return utils.LavaFormatWarning("cannot get next epoch to count past delegations", err, + utils.LogAttr("provider", senderAddr.String()), + utils.LogAttr("block", nextEpoch), + ) + } + existingEntry, entryExists := k.epochStorageKeeper.GetStakeEntryCurrent(ctx, chainID, creator) if entryExists { // modify the entry (check who's modifying - vault/provider) @@ -175,6 +183,13 @@ func (k Keeper) StakeNewEntry(ctx sdk.Context, validator, creator, chainID strin details..., ) } + + // automatically unfreeze the provider if it was frozen due to stake below min spec stake + minSpecStake := k.specKeeper.GetMinStake(ctx, chainID) + if beforeAmount.IsLT(minSpecStake) && existingEntry.IsFrozen() && !existingEntry.IsJailed(ctx.BlockTime().UTC().Unix()) && amount.IsGTE(minSpecStake) { + existingEntry.UnFreeze(nextEpoch) + k.epochStorageKeeper.SetStakeEntryCurrent(ctx, existingEntry) + } } else if decrease { // unbond the difference diffAmount := beforeAmount.Sub(amount) @@ -228,15 +243,8 @@ func (k Keeper) StakeNewEntry(ctx sdk.Context, validator, creator, chainID strin // if there are registered delegations to the provider, count them in the delegateTotal delegateTotal := sdk.ZeroInt() - nextEpoch, err := k.epochStorageKeeper.GetNextEpoch(ctx, uint64(ctx.BlockHeight())) - if err != nil { - return utils.LavaFormatWarning("cannot get next epoch to count past delegations", err, - utils.LogAttr("provider", senderAddr.String()), - utils.LogAttr("block", nextEpoch), - ) - } - stakeAmount := amount + // creating a new provider, fetch old delegation if len(metadata.Chains) == 1 { delegations, err := k.dualstakingKeeper.GetProviderDelegators(ctx, provider)