fix(x/slashing): consensus failure after cons key rotation (#19038)

This commit is contained in:
atheeshp 2024-01-12 20:12:26 +05:30 committed by GitHub
parent b98b6eb076
commit eaf92c225c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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(),