Skip to content

Commit

Permalink
refactor SigningInfoCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Feb 22, 2024
1 parent 47bb099 commit 48c466f
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,41 +291,45 @@ func SigningInfoCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes
return err
}
if valSigningInfo.Tombstoned {
consAddr, err := addressutils.AddressFromBech32(valSigningInfo.Address, "")
if err != nil {
return err
}
valAddr, found := k.GetValidatorAddrByConsAddr(ctx, zone.ChainId, consAddr)
if !found {
return fmt.Errorf("can not get validator address from consensus address: %s", valSigningInfo.Address)
}
return handleTombstonedValidator(k, ctx, &zone, valSigningInfo)
}
return nil
}

func handleTombstonedValidator(k *Keeper, ctx sdk.Context, zone *types.Zone, valSigningInfo slashingtypes.ValidatorSigningInfo) error {
consAddr, err := addressutils.AddressFromBech32(valSigningInfo.Address, "")
if err != nil {
return err
}
valAddr, found := k.GetValidatorAddrByConsAddr(ctx, zone.ChainId, consAddr)
if !found {
return fmt.Errorf("can not get validator address from consensus address: %s", valSigningInfo.Address)
}

k.Logger(ctx).Info("tombstoned validator found", "valoper", valAddr)
k.Logger(ctx).Info("tombstoned validator found", "valoper", valAddr)

valAddrBytes, err := addressutils.ValAddressFromBech32(valAddr, zone.GetValoperPrefix())
valAddrBytes, err := addressutils.ValAddressFromBech32(valAddr, zone.GetValoperPrefix())
if err != nil {
return err
}
val, found := k.GetValidator(ctx, zone.ChainId, valAddrBytes)
if !found {
err := k.SetValidator(ctx, zone.ChainId, types.Validator{
ValoperAddress: valAddr,
Jailed: true,
Tombstoned: true,
})
if err != nil {
return err
}
val, found := k.GetValidator(ctx, zone.ChainId, valAddrBytes)
// NOTE: this shouldn't be reachable, but keeping here as it doesn't do any harm.
if !found {
err := k.SetValidator(ctx, zone.ChainId, types.Validator{
ValoperAddress: valAddr,
Jailed: true,
Tombstoned: true,
})
if err != nil {
return err
}
} else {
val.Tombstoned = true
if err = k.SetValidator(ctx, zone.ChainId, val); err != nil {
return err
}
} else {
val.Tombstoned = true
if err = k.SetValidator(ctx, zone.ChainId, val); err != nil {
return err
}
k.Logger(ctx).Info(fmt.Sprintf("%q on chainID: %q was found to already have been tombstoned, added information", val.ValoperAddress, zone.ChainId))

}
k.Logger(ctx).Info(fmt.Sprintf("%q on chainID: %q was found to already have been tombstoned, added information", val.ValoperAddress, zone.ChainId))

return nil
}

Expand Down

0 comments on commit 48c466f

Please sign in to comment.