-
Notifications
You must be signed in to change notification settings - Fork 180
/
unjail.go
55 lines (45 loc) · 1.46 KB
/
unjail.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
45
46
47
48
49
50
51
52
53
54
55
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/okex/exchain/x/slashing/internal/types"
)
// Unjail calls the staking Unjail function to unjail a validator if the
// jailed period has concluded
func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) error {
validator := k.sk.Validator(ctx, validatorAddr)
if validator == nil {
return types.ErrNoValidatorForAddress
}
// cannot be unjailed if no self-delegation exists
//selfDel := k.sk.Delegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr)
//if selfDel == nil {
// return types.ErrMissingSelfDelegation
//}
//
//if validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) {
// return types.ErrSelfDelegationTooLowToUnjail
//}
// cannot be unjailed if not jailed
if !validator.IsJailed() {
return types.ErrValidatorNotJailed
}
consAddr := sdk.ConsAddress(validator.GetConsPubKey().Address())
info, found := k.GetValidatorSigningInfo(ctx, consAddr)
if !found {
return types.ErrNoValidatorForAddress
}
if info.ValidatorStatus == types.Destroying {
//cannot be unjailed while target validator was destroying
return types.ErrValidatorDestroying
}
// cannot be unjailed if tombstoned
if info.Tombstoned {
return types.ErrValidatorJailed
}
// cannot be unjailed until out of jail
if ctx.BlockHeader().Time.Before(info.JailedUntil) {
return types.ErrValidatorJailed
}
k.sk.Unjail(ctx, consAddr)
return nil
}