github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/keeper/unjail.go (about) 1 package keeper 2 3 import ( 4 sdk "github.com/Finschia/finschia-sdk/types" 5 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 6 "github.com/Finschia/finschia-sdk/x/slashing/types" 7 ) 8 9 // Unjail calls the staking Unjail function to unjail a validator if the 10 // jailed period has concluded 11 func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) error { 12 validator := k.sk.Validator(ctx, validatorAddr) 13 if validator == nil { 14 return types.ErrNoValidatorForAddress 15 } 16 17 // cannot be unjailed if no self-delegation exists 18 selfDel := k.sk.Delegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr) 19 if selfDel == nil { 20 return types.ErrMissingSelfDelegation 21 } 22 23 tokens := validator.TokensFromShares(selfDel.GetShares()).TruncateInt() 24 minSelfBond := validator.GetMinSelfDelegation() 25 if tokens.LT(minSelfBond) { 26 return sdkerrors.Wrapf( 27 types.ErrSelfDelegationTooLowToUnjail, "%s less than %s", tokens, minSelfBond, 28 ) 29 } 30 31 // cannot be unjailed if not jailed 32 if !validator.IsJailed() { 33 return types.ErrValidatorNotJailed 34 } 35 36 consAddr, err := validator.GetConsAddr() 37 if err != nil { 38 return err 39 } 40 // If the validator has a ValidatorSigningInfo object that signals that the 41 // validator was bonded and so we must check that the validator is not tombstoned 42 // and can be unjailed at the current block. 43 // 44 // A validator that is jailed but has no ValidatorSigningInfo object signals 45 // that the validator was never bonded and must've been jailed due to falling 46 // below their minimum self-delegation. The validator can unjail at any point 47 // assuming they've now bonded above their minimum self-delegation. 48 info, found := k.GetValidatorSigningInfo(ctx, consAddr) 49 if found { 50 // cannot be unjailed if tombstoned 51 if info.Tombstoned { 52 return types.ErrValidatorJailed 53 } 54 55 // cannot be unjailed until out of jail 56 if ctx.BlockHeader().Time.Before(info.JailedUntil) { 57 return types.ErrValidatorJailed 58 } 59 } 60 61 k.sk.Unjail(ctx, consAddr) 62 return nil 63 }