Merge PR #2176: Ensure Legacy Validator Delegation Invariants
* Test and allow jailed validator to self-bond * Implement TestJailedValidatorDelegations * Restructure TestJailedValidatorDelegations * Add Delegation to Validator type and update handleMsgUnjail accordingly * Update ErrMissingSelfDelegation error message * Update democoin mock validator set impl * Update pending log * Add comment to ValidatorSet
This commit is contained in:
committed by
Rigel
parent
2d92803b9f
commit
df33452490
@@ -19,35 +19,38 @@ func NewHandler(k Keeper) sdk.Handler {
|
||||
// Validators must submit a transaction to unjail itself after
|
||||
// having been jailed (and thus unbonded) for downtime
|
||||
func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {
|
||||
|
||||
// Validator must exist
|
||||
validator := k.validatorSet.Validator(ctx, msg.ValidatorAddr)
|
||||
if validator == nil {
|
||||
return ErrNoValidatorForAddress(k.codespace).Result()
|
||||
}
|
||||
|
||||
// cannot be unjailed if no self-delegation exists
|
||||
selfDel := k.validatorSet.Delegation(ctx, msg.ValidatorAddr, msg.ValidatorAddr)
|
||||
if selfDel == nil {
|
||||
return ErrMissingSelfDelegation(k.codespace).Result()
|
||||
}
|
||||
|
||||
if !validator.GetJailed() {
|
||||
return ErrValidatorNotJailed(k.codespace).Result()
|
||||
}
|
||||
|
||||
addr := sdk.ValAddress(validator.GetPubKey().Address())
|
||||
|
||||
// Signing info must exist
|
||||
info, found := k.getValidatorSigningInfo(ctx, addr)
|
||||
if !found {
|
||||
return ErrNoValidatorForAddress(k.codespace).Result()
|
||||
}
|
||||
|
||||
// Cannot be unjailed until out of jail
|
||||
// cannot be unjailed until out of jail
|
||||
if ctx.BlockHeader().Time.Before(info.JailedUntil) {
|
||||
return ErrValidatorJailed(k.codespace).Result()
|
||||
}
|
||||
|
||||
// Update the starting height (so the validator can't be immediately jailed again)
|
||||
// update the starting height so the validator can't be immediately jailed
|
||||
// again
|
||||
info.StartHeight = ctx.BlockHeight()
|
||||
k.setValidatorSigningInfo(ctx, addr, info)
|
||||
|
||||
// Unjail the validator
|
||||
k.validatorSet.Unjail(ctx, validator.GetPubKey())
|
||||
|
||||
tags := sdk.NewTags("action", []byte("unjail"), "validator", []byte(msg.ValidatorAddr.String()))
|
||||
|
||||
Reference in New Issue
Block a user