Skip to content

Commit

Permalink
fix: do not allow validators with zero weight to be LSM staked. (#795)
Browse files Browse the repository at this point in the history
* do not allow validators with zero weight to be LSM staked.

* update CHANGELOG.md

* update CHANGELOG.md

* add test.
  • Loading branch information
puneet2019 authored Mar 22, 2024
1 parent 3ba94af commit 65f5dbc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

- [792](https://github.com/persistenceOne/pstake-native/pull/792) Use GetHostChainFromHostDenom in ICA Transfer
unsuccessfulAck instead of GetHostChainFromDelegatorAddress as Rewards account too uses ICA Transfer to autocompound
- [795](https://github.com/persistenceOne/pstake-native/pull/795) Reject zero weight validator LSM shares for
liquidstakeibc

## [v2.11.0] - 2024-03-12

Expand Down
4 changes: 4 additions & 0 deletions x/liquidstakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,10 @@ func (k msgServer) validateLiquidStakeLSMDeposit(
return nil, nil, nil, errorsmod.Wrapf(types.ErrLSMValidatorInvalidState, "validator %s is not in the bonded state, it is in %s", operatorAddress, validator.Status)
}

if validator.Weight.Equal(sdktypes.ZeroDec()) {
return nil, nil, nil, errorsmod.Wrapf(types.ErrValidatorNotFound, "validator %s is not in the validator set, weight is %s", operatorAddress, validator.Weight)
}

// check delegator has enough LSM tokens
delegatorBalance := k.bankKeeper.GetBalance(ctx, delegatorAddress, delegation.Denom).Amount
if delegatorBalance.LT(delegation.Amount) {
Expand Down
37 changes: 37 additions & 0 deletions x/liquidstakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"context"
"fmt"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"reflect"
"testing"

Expand Down Expand Up @@ -112,11 +113,32 @@ func (suite *IntegrationTestSuite) Test_msgServer_LiquidStakeLSM() {
hc, found := pstakeapp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID)
suite.Require().True(found)

inactiveValoperAddr := "persistencevaloper1wrxz49hjmq434zg072kl2ka3kqnau0ejs0vqpm"
pstakeapp.LiquidStakeIBCKeeper.SetHostChainValidator(ctx, hc, &types.Validator{
OperatorAddress: inactiveValoperAddr,
Status: stakingtypes.BondStatusBonded,
Weight: sdk.ZeroDec(),
DelegatedAmount: sdk.OneInt(),
ExchangeRate: sdk.OneDec(),
UnbondingEpoch: 0,
Delegable: true,
})
hc, found = pstakeapp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID)
suite.Require().True(found)
lsmIbcDenom := ibctfrtypes.ParseDenomTrace(
ibctfrtypes.GetPrefixedDenom(hc.PortId, hc.ChannelId, hc.Validators[0].OperatorAddress+"/1"),
).IBCDenom()

suite.Require().Equal(nil, transfertypes.ValidateIBCDenom(lsmIbcDenom))

lsmIbcDenomZeroWeightTrace := ibctfrtypes.ParseDenomTrace(
ibctfrtypes.GetPrefixedDenom(hc.PortId, hc.ChannelId, inactiveValoperAddr+"/1"),
)
lsmIbcDenomZeroWeight := lsmIbcDenomZeroWeightTrace.IBCDenom()
pstakeapp.TransferKeeper.SetDenomTrace(ctx, lsmIbcDenomZeroWeightTrace)

suite.Require().Equal(nil, transfertypes.ValidateIBCDenom(lsmIbcDenomZeroWeight))

type args struct {
goCtx context.Context
msg *types.MsgLiquidStakeLSM
Expand Down Expand Up @@ -257,6 +279,21 @@ func (suite *IntegrationTestSuite) Test_msgServer_LiquidStakeLSM() {
want: nil,
wantErr: true,
},
{
name: "inactive validator",
args: args{
goCtx: ctx,
msg: &types.MsgLiquidStakeLSM{
DelegatorAddress: suite.chainA.SenderAccount.GetAddress().String(),
Delegations: sdk.NewCoins(sdk.NewCoin(lsmIbcDenomZeroWeight, sdk.NewInt(4))),
},
chainActive: true,
lsmActive: true,
createSecondDeposit: true,
},
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 65f5dbc

Please sign in to comment.