-
Notifications
You must be signed in to change notification settings - Fork 0
/
unjail.go
executable file
·73 lines (62 loc) · 2.03 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package keeper
import (
"context"
"cosmossdk.io/errors"
"github.com/axiome-pro/axm-node/x/slashing/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Unjail calls the staking Unjail function to unjail a validator if the
// jailed period has concluded
func (k Keeper) Unjail(ctx context.Context, validatorAddr sdk.ValAddress) error {
validator, err := k.sk.Validator(ctx, validatorAddr)
if err != nil {
return err
}
if validator == nil {
return types.ErrNoValidatorForAddress
}
// cannot be unjailed if no self-delegation exists
selfDel, err := k.sk.Delegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr)
if err != nil {
return err
}
if selfDel == nil {
return types.ErrMissingSelfDelegation
}
tokens := validator.TokensFromShares(selfDel.GetShares()).TruncateInt()
minSelfBond := validator.GetMinSelfDelegation()
if tokens.LT(minSelfBond) {
return errors.Wrapf(
types.ErrSelfDelegationTooLowToUnjail, "%s less than %s", tokens, minSelfBond,
)
}
// cannot be unjailed if not jailed
if !validator.IsJailed() {
return types.ErrValidatorNotJailed
}
consAddr, err := validator.GetConsAddr()
if err != nil {
return err
}
// If the validator has a ValidatorSigningInfo object that signals that the
// validator was bonded and so we must check that the validator is not tombstoned
// and can be unjailed at the current block.
//
// A validator that is jailed but has no ValidatorSigningInfo object signals
// that the validator was never bonded and must've been jailed due to falling
// below their minimum self-delegation. The validator can unjail at any point
// assuming they've now bonded above their minimum self-delegation.
info, err := k.GetValidatorSigningInfo(ctx, consAddr)
if err == nil {
// cannot be unjailed if tombstoned
if info.Tombstoned {
return types.ErrValidatorJailed
}
// cannot be unjailed until out of jail
sdkCtx := sdk.UnwrapSDKContext(ctx)
if sdkCtx.BlockHeader().Time.Before(info.JailedUntil) {
return types.ErrValidatorJailed
}
}
return k.sk.Unjail(ctx, consAddr)
}