Skip to content

Commit

Permalink
update logic check tombstoned
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanhNhann committed Oct 18, 2023
1 parent ded965b commit 6185cb3
Show file tree
Hide file tree
Showing 8 changed files with 1,666 additions and 5,544 deletions.
6,787 changes: 1,485 additions & 5,302 deletions docs/swagger.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package quicksilver.interchainstaking.v1;
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types";
Expand Down Expand Up @@ -158,8 +157,6 @@ message Validator {
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
// consensus_pubkey is the consensus public key of the validator, as a Protobuf Any.
google.protobuf.Any consensus_pubkey = 10 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
}

message DelegatorIntent {
Expand Down
11 changes: 10 additions & 1 deletion x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,16 @@ func SigningInfoCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes
return err
}
if valSigningInfo.Tombstoned {
k.Logger(ctx).Error("Tombstoned validator found", "valoper", valSigningInfo.Address)
consAddr, err := sdk.ConsAddressFromBech32(valSigningInfo.Address)
if err != nil {
return err
}
valAddr, found := k.GetValidatorAddrByConsAddr(ctx, zone.ChainId, consAddr)

Check failure on line 279 in x/interchainstaking/keeper/callbacks.go

View workflow job for this annotation

GitHub Actions / lint

SA4006: this value of `found` is never used (staticcheck)
if !found {

Check warning on line 280 in x/interchainstaking/keeper/callbacks.go

View workflow job for this annotation

GitHub Actions / lint

empty-block: this block is empty, you can remove it (revive)

Check failure on line 281 in x/interchainstaking/keeper/callbacks.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/quicksilver-zone/quicksilver) --custom-order (gci)
}

k.Logger(ctx).Error("Tombstoned validator found", "valoper", valAddr)

valAddrBytes, err := addressutils.ValAddressFromBech32(valSigningInfo.Address, zone.GetValoperPrefix())
if err != nil {
Expand Down
34 changes: 26 additions & 8 deletions x/interchainstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,17 @@ func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []b

jailTime := time.Time{}
if validator.IsJailed() {
consAddr, err := validator.GetConsAddr()
if err != nil {
return err
}
k.SetValidatorAddrByConsAddr(ctx, zone.ChainId, validator.OperatorAddress, consAddr)

Check failure on line 277 in x/interchainstaking/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.SetValidatorAddrByConsAddr` is not checked (errcheck)
jailTime = ctx.BlockTime()

err = k.EmitSigningInfoQuery(ctx, zone.ConnectionId, zone.ChainId, validator)
if err != nil {
return err
}
}
if err := k.SetValidator(ctx, zone.ChainId, types.Validator{
ValoperAddress: validator.OperatorAddress,
Expand All @@ -297,7 +307,17 @@ func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []b

if !val.Jailed && validator.IsJailed() {
k.Logger(ctx).Info("Transitioning validator to jailed state", "valoper", validator.OperatorAddress, "old_vp", val.VotingPower, "new_vp", validator.Tokens, "new_shares", validator.DelegatorShares, "old_shares", val.DelegatorShares)

Check failure on line 310 in x/interchainstaking/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/quicksilver-zone/quicksilver) --custom-order (gci)
consAddr, err := validator.GetConsAddr()
if err != nil {
return err
}
k.SetValidatorAddrByConsAddr(ctx, zone.ChainId, validator.OperatorAddress, consAddr)

Check failure on line 315 in x/interchainstaking/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.SetValidatorAddrByConsAddr` is not checked (errcheck)

err = k.EmitSigningInfoQuery(ctx, zone.ConnectionId, zone.ChainId, validator)
if err != nil {
return err
}
val.Jailed = true
val.JailedSince = ctx.BlockTime()
if !val.VotingPower.IsPositive() {
Expand All @@ -315,6 +335,12 @@ func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []b
return err
}
} else if val.Jailed && !validator.IsJailed() {
consAddr, err := validator.GetConsAddr()
if err != nil {
return err
}
k.DeleteValidatorAddrByConsAddr(ctx, zone.ChainId, consAddr)

k.Logger(ctx).Info("Transitioning validator to unjailed state", "valoper", validator.OperatorAddress)

val.Jailed = false
Expand Down Expand Up @@ -353,14 +379,6 @@ func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []b
}
}

// checking whether validator was tombstoned or not
if val.Jailed {
err := k.EmitSigningInfoQuery(ctx, zone.ConnectionId, zone.ChainId, validator)
if err != nil {
return err
}
}

return nil
}

Expand Down
13 changes: 5 additions & 8 deletions x/interchainstaking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,14 @@ func (suite *KeeperTestSuite) TestStoreGetDeleteValidatorByConsAddr() {
pkAny, err := codectypes.NewAnyWithValue(PKs[0])
suite.Require().NoError(err)

newValidator := types.Validator{
ValoperAddress: validator.String(),
CommissionRate: sdk.NewDec(5.0),
DelegatorShares: sdk.NewDec(1000.0),
VotingPower: sdk.NewInt(1000),
Status: stakingtypes.BondStatusBonded,
Score: sdk.NewDec(0),
newValidator := stakingtypes.Validator{
OperatorAddress: validator.String(),

Check failure on line 81 in x/interchainstaking/keeper/validator_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/quicksilver-zone/quicksilver) --custom-order (gci)
ConsensusPubkey: pkAny,
}
consAddr, err := newValidator.GetConsAddr()
suite.NoError(err)

err = app.InterchainstakingKeeper.SetValidatorAddrByConsAddr(ctx, zone.ChainId, newValidator)
err = app.InterchainstakingKeeper.SetValidatorAddrByConsAddr(ctx, zone.ChainId, newValidator.OperatorAddress, consAddr)
suite.NoError(err)

_, found = app.InterchainstakingKeeper.GetValidatorAddrByConsAddr(ctx, zone.ChainId, sdk.ConsAddress(PKs[0].Address()))
Expand Down
8 changes: 2 additions & 6 deletions x/interchainstaking/keeper/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,9 @@ func (k Keeper) GetValidatorAddrByConsAddr(ctx sdk.Context, chainID string, cons
}

// SetValidatorAddrByConsAddr set validator address by Consensus address.
func (k Keeper) SetValidatorAddrByConsAddr(ctx sdk.Context, chainID string, val types.Validator) error {
func (k Keeper) SetValidatorAddrByConsAddr(ctx sdk.Context, chainID string, valAddr string, consAddr sdk.ConsAddress) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetZoneValidatorAddrsByConsAddrKey(chainID))
consPk, err := val.GetConsAddr()
if err != nil {
return err
}
store.Set(consPk, []byte(val.ValoperAddress))
store.Set(consAddr, []byte(valAddr))
return nil
}

Expand Down
Loading

0 comments on commit 6185cb3

Please sign in to comment.