From 6166c69e13125baa432c58c8628311ef56983a99 Mon Sep 17 00:00:00 2001 From: KeefeL <90749943+KeefeL@users.noreply.github.com> Date: Wed, 8 Feb 2023 21:59:31 +0800 Subject: [PATCH] fix impeach validator (#100) Co-authored-by: Keefe Liu --- x/slashing/keeper/msg_server.go | 3 +-- x/slashing/keeper/signing_info.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/x/slashing/keeper/msg_server.go b/x/slashing/keeper/msg_server.go index b6a9cb8499..ed5d60da0f 100644 --- a/x/slashing/keeper/msg_server.go +++ b/x/slashing/keeper/msg_server.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "time" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -80,7 +79,7 @@ func (k msgServer) Impeach(goCtx context.Context, msg *types.MsgImpeach) (*types } // Jail forever. - k.JailUntil(ctx, consAddr, time.Unix(253402300800, 0)) + k.JailForever(ctx, consAddr) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/slashing/keeper/signing_info.go b/x/slashing/keeper/signing_info.go index d65b773ebc..74bb4e7dbf 100644 --- a/x/slashing/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -113,6 +113,29 @@ func (k Keeper) JailUntil(ctx sdk.Context, consAddr sdk.ConsAddress, jailTime ti k.SetValidatorSigningInfo(ctx, consAddr, signInfo) } +// JailForever attempts to set the validator's JailedUntil attribute in its signing +// info to a very big value. When no signing info found, it will create a new signing +// info for the validator. +func (k Keeper) JailForever(ctx sdk.Context, consAddr sdk.ConsAddress) { + signingInfo, found := k.GetValidatorSigningInfo(ctx, consAddr) + if !found { + // Allow jail forever a no signing info validator. + signingInfo = types.NewValidatorSigningInfo( + consAddr, + ctx.BlockHeight(), + 0, + time.Unix(0, 0), + false, + 0, + ) + } + + // Jail to 10000-1-1 08:00:00. + signingInfo.JailedUntil = time.Unix(253402300800, 0) + + k.SetValidatorSigningInfo(ctx, consAddr, signingInfo) +} + // Tombstone attempts to tombstone a validator. It will panic if signing info for // the given validator does not exist. func (k Keeper) Tombstone(ctx sdk.Context, consAddr sdk.ConsAddress) {