Skip to content

Commit

Permalink
do automatic unfreeze only for going over min stake
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 15, 2024
1 parent cc0a6a3 commit 8d83f8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 1 addition & 2 deletions x/dualstaking/keeper/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 16 additions & 8 deletions x/pairing/keeper/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8d83f8b

Please sign in to comment.