Skip to content

Commit

Permalink
fix(x/slashing): consensus failure after cons key rotation (#19038)
Browse files Browse the repository at this point in the history
  • Loading branch information
atheeshp authored Jan 12, 2024
1 parent b98b6eb commit eaf92c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions x/slashing/keeper/infractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions x/slashing/keeper/signing_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keeper/signing_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit eaf92c2

Please sign in to comment.