github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/slashing/internal/keeper/unjail.go (about) 1 package keeper 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/slashing/internal/types" 6 ) 7 8 // Unjail calls the staking Unjail function to unjail a validator if the 9 // jailed period has concluded 10 func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) error { 11 validator := k.sk.Validator(ctx, validatorAddr) 12 if validator == nil { 13 return types.ErrNoValidatorForAddress 14 } 15 16 // cannot be unjailed if no self-delegation exists 17 selfDel := k.sk.Delegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr) 18 if selfDel == nil { 19 return types.ErrMissingSelfDelegation 20 } 21 22 if validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) { 23 return types.ErrSelfDelegationTooLowToUnjail 24 } 25 26 // cannot be unjailed if not jailed 27 if !validator.IsJailed() { 28 return types.ErrValidatorNotJailed 29 } 30 31 consAddr := sdk.ConsAddress(validator.GetConsPubKey().Address()) 32 33 info, found := k.GetValidatorSigningInfo(ctx, consAddr) 34 if !found { 35 return types.ErrNoValidatorForAddress 36 } 37 38 // cannot be unjailed if tombstoned 39 if info.Tombstoned { 40 return types.ErrValidatorJailed 41 } 42 43 // cannot be unjailed until out of jail 44 if ctx.BlockHeader().Time.Before(info.JailedUntil) { 45 return types.ErrValidatorJailed 46 } 47 48 k.sk.Unjail(ctx, consAddr) 49 return nil 50 }