/
msg_server_unfreeze.go
44 lines (38 loc) · 1.98 KB
/
msg_server_unfreeze.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package keeper
import (
"context"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/x/pairing/types"
)
func (k msgServer) UnfreezeProvider(goCtx context.Context, msg *types.MsgUnfreezeProvider) (*types.MsgUnfreezeProviderResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
unfreezeBlock := k.epochStorageKeeper.GetCurrentNextEpoch(ctx) + 1
unfrozen_chains := []string{}
for _, chainId := range msg.GetChainIds() {
stakeEntry, found := k.epochStorageKeeper.GetStakeEntryByAddressCurrent(ctx, chainId, msg.Creator)
if !found {
return nil, utils.LavaFormatWarning("Unfreeze_cant_get_stake_entry", types.FreezeStakeEntryNotFoundError, []utils.Attribute{{Key: "chainID", Value: chainId}, {Key: "providerAddress", Value: msg.GetCreator()}}...)
}
minStake := k.Keeper.specKeeper.GetMinStake(ctx, chainId)
if stakeEntry.EffectiveStake().LT(minStake.Amount) {
return nil, utils.LavaFormatWarning("Unfreeze_insufficient_stake", types.UnFreezeInsufficientStakeError,
[]utils.Attribute{
{Key: "chainID", Value: chainId},
{Key: "providerAddress", Value: msg.GetCreator()},
{Key: "stake", Value: stakeEntry.Stake},
{Key: "minStake", Value: minStake},
}...)
}
if stakeEntry.StakeAppliedBlock > unfreezeBlock {
// unfreeze the provider by making the StakeAppliedBlock the current block. This will let the provider be added to the pairing list in the next epoch, when current entries becomes the front of epochStorage
stakeEntry.UnFreeze(unfreezeBlock)
k.epochStorageKeeper.ModifyStakeEntryCurrent(ctx, chainId, stakeEntry)
unfrozen_chains = append(unfrozen_chains, chainId)
}
// else case does not throw an error because we don't want to fail unfreezing other chains
}
utils.LogLavaEvent(ctx, ctx.Logger(), "unfreeze_provider", map[string]string{"providerAddress": msg.GetCreator(), "chainIDs": strings.Join(unfrozen_chains, ",")}, "Provider Unfreeze")
return &types.MsgUnfreezeProviderResponse{}, nil
}