From eaf92c225cfa2420946ff738cdcf05cf8b402040 Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:12:26 +0530 Subject: [PATCH] fix(x/slashing): consensus failure after cons key rotation (#19038) --- x/slashing/keeper/infractions.go | 12 ++++++++++-- x/slashing/keeper/signing_info.go | 6 ++++++ x/slashing/keeper/signing_info_test.go | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/x/slashing/keeper/infractions.go b/x/slashing/keeper/infractions.go index 0260582c17e6..9a63414267d1 100644 --- a/x/slashing/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -32,15 +32,23 @@ func (k Keeper) HandleValidatorSignatureWithParams(ctx context.Context, params t consAddr := sdk.ConsAddress(addr) // don't update missed blocks when validator's jailed - isJailed, err := k.sk.IsValidatorJailed(ctx, consAddr) + val, err := k.sk.ValidatorByConsAddr(ctx, consAddr) if err != nil { return err } - if isJailed { + if val.IsJailed() { return nil } + // read the cons address again because validator may've rotated it's key + valConsAddr, err := val.GetConsAddr() + if err != nil { + return err + } + + consAddr = sdk.ConsAddress(valConsAddr) + // fetch signing info signInfo, err := k.ValidatorSigningInfo.Get(ctx, consAddr) if err != nil { diff --git a/x/slashing/keeper/signing_info.go b/x/slashing/keeper/signing_info.go index 7f991fcf2483..5eac3651a367 100644 --- a/x/slashing/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -252,6 +252,12 @@ func (k Keeper) performConsensusPubKeyUpdate(ctx context.Context, oldPubKey, new return types.ErrInvalidConsPubKey.Wrap("failed to get signing info for old public key") } + consAddr, err := k.sk.ConsensusAddressCodec().BytesToString(newPubKey.Address()) + if err != nil { + return err + } + + signingInfo.Address = consAddr if err := k.ValidatorSigningInfo.Set(ctx, sdk.ConsAddress(newPubKey.Address()), signingInfo); err != nil { return err } diff --git a/x/slashing/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go index 6b779c49a44e..824e3537281a 100644 --- a/x/slashing/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -124,7 +124,7 @@ func (s *KeeperTestSuite) TestPerformConsensusPubKeyUpdate() { newConsAddr := sdk.ConsAddress(pks[1].Address()) newInfo := slashingtypes.NewValidatorSigningInfo( - oldConsAddr.String(), + newConsAddr.String(), int64(4), int64(3), time.Unix(2, 0).UTC(),