From 9cb832c46e3467ec2bce552a1901e386347cadbf Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Fri, 15 Sep 2023 17:57:04 -0500 Subject: [PATCH 01/14] Add change rate decorator --- app/ante.go | 1 + app/decorators/change-rate-decorator.go | 97 +++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 app/decorators/change-rate-decorator.go diff --git a/app/ante.go b/app/ante.go index b3d3e0289..8be2af6a8 100644 --- a/app/ante.go +++ b/app/ante.go @@ -79,6 +79,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), decorators.MsgFilterDecorator{}, + decorators.NewChangeRateDecorator(options.StakingKeeper), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(options.AccountKeeper), diff --git a/app/decorators/change-rate-decorator.go b/app/decorators/change-rate-decorator.go new file mode 100644 index 000000000..c952eaa82 --- /dev/null +++ b/app/decorators/change-rate-decorator.go @@ -0,0 +1,97 @@ +package decorators + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +const ( + MaxChangeRate = "0.05" +) + +// MsgChangeRateDecorator defines the AnteHandler that filters & prevents messages +// that create validators and exceed the max change rate of 5%. +type MsgChangeRateDecorator struct { + sk stakingkeeper.Keeper + maxCommissionChangeRate sdk.Dec +} + +// Create new Change Rate Decorator +func NewChangeRateDecorator(sk stakingkeeper.Keeper) MsgChangeRateDecorator { + + rate, err := sdk.NewDecFromStr(MaxChangeRate) + if err != nil { + panic(err) + } + + return MsgChangeRateDecorator{ + sk: sk, + maxCommissionChangeRate: rate, + } +} + +// The AnteHandle checks for transactions that exceed the max change rate of 5% on the +// creation of a validator. +func (mcr MsgChangeRateDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + + ctx.Logger().Error("MsgChangeRateDecorator", "Called", true) + + err := mcr.hasInvalidCommissionRateMsgs(ctx, tx.GetMsgs()) + if err != nil { + return ctx, err + } + + return next(ctx, tx, simulate) +} + +// Check if a tx's messages exceed a validator's max change rate +func (mcr MsgChangeRateDecorator) hasInvalidCommissionRateMsgs(ctx sdk.Context, msgs []sdk.Msg) error { + for _, msg := range msgs { + + // Check for create validator messages + if msg, ok := msg.(*stakingtypes.MsgCreateValidator); ok && mcr.isInvalidCreateMessage(msg) { + return fmt.Errorf("max change rate must not exceed %f%%", mcr.maxCommissionChangeRate) + } + + // Check for edit validator messages + if msg, ok := msg.(*stakingtypes.MsgEditValidator); ok { + err := mcr.isInvalidEditMessage(ctx, msg) + if err != nil { + return err + } + } + } + + return nil +} + +// Check if the create validator message is invalid +func (mcr MsgChangeRateDecorator) isInvalidCreateMessage(msg *stakingtypes.MsgCreateValidator) bool { + return msg.Commission.MaxChangeRate.GT(mcr.maxCommissionChangeRate) +} + +// Check if the edit validator message is invalid +func (mcr MsgChangeRateDecorator) isInvalidEditMessage(ctx sdk.Context, msg *stakingtypes.MsgEditValidator) error { + + // Skip if the commission rate is not being modified + if msg.CommissionRate == nil { + return nil + } + + // Get validator info, if exists + valInfo, found := mcr.sk.GetValidator(ctx, sdk.ValAddress(msg.ValidatorAddress)) + if !found { + return fmt.Errorf("validator not found") + } + + // Check if new commission rate is out of bounds of the max change rate + if msg.CommissionRate.LT(valInfo.Commission.Rate.Sub(mcr.maxCommissionChangeRate)) || msg.CommissionRate.GT(valInfo.Commission.Rate.Add(mcr.maxCommissionChangeRate)) { + return fmt.Errorf("commission rate cannot change by more than %f%%", mcr.maxCommissionChangeRate) + } + + return nil +} From 7199551306d4967e9a347221cc4fa93ff9dadada Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Fri, 15 Sep 2023 18:12:44 -0500 Subject: [PATCH 02/14] Fix file name --- .../{change-rate-decorator.go => change_rate_decorator.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/decorators/{change-rate-decorator.go => change_rate_decorator.go} (100%) diff --git a/app/decorators/change-rate-decorator.go b/app/decorators/change_rate_decorator.go similarity index 100% rename from app/decorators/change-rate-decorator.go rename to app/decorators/change_rate_decorator.go From f4403da6ba602ffb199940bb77b21c15125702fa Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Sat, 16 Sep 2023 12:42:42 -0500 Subject: [PATCH 03/14] Filter authz messages (WIP) --- app/ante.go | 2 +- app/decorators/change_rate_decorator.go | 36 +++++++++++++++++++++++-- scripts/test_node.sh | 3 ++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/ante.go b/app/ante.go index 8be2af6a8..2119b9657 100644 --- a/app/ante.go +++ b/app/ante.go @@ -79,7 +79,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), decorators.MsgFilterDecorator{}, - decorators.NewChangeRateDecorator(options.StakingKeeper), + decorators.NewChangeRateDecorator(options.StakingKeeper, options.Cdc), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(options.AccountKeeper), diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index c952eaa82..aba7612f8 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -1,10 +1,13 @@ package decorators import ( + "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -17,11 +20,12 @@ const ( // that create validators and exceed the max change rate of 5%. type MsgChangeRateDecorator struct { sk stakingkeeper.Keeper + cdc codec.BinaryCodec maxCommissionChangeRate sdk.Dec } // Create new Change Rate Decorator -func NewChangeRateDecorator(sk stakingkeeper.Keeper) MsgChangeRateDecorator { +func NewChangeRateDecorator(sk stakingkeeper.Keeper, cdc codec.BinaryCodec) MsgChangeRateDecorator { rate, err := sdk.NewDecFromStr(MaxChangeRate) if err != nil { @@ -30,6 +34,7 @@ func NewChangeRateDecorator(sk stakingkeeper.Keeper) MsgChangeRateDecorator { return MsgChangeRateDecorator{ sk: sk, + cdc: cdc, maxCommissionChangeRate: rate, } } @@ -52,6 +57,28 @@ func (mcr MsgChangeRateDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat func (mcr MsgChangeRateDecorator) hasInvalidCommissionRateMsgs(ctx sdk.Context, msgs []sdk.Msg) error { for _, msg := range msgs { + // Check if an authz message, loop through all inner messages, and recursively call this function + if execMsg, ok := msg.(*authz.MsgExec); ok { + + ctx.Logger().Error("MsgChangeRateDecorator", "Authz", execMsg.Msgs) + + // Unmarshal the inner messages + var msgs []sdk.Msg + for _, v := range execMsg.Msgs { + var innerMsg sdk.Msg + if err := json.Unmarshal(v.Value, &innerMsg); err != nil { + return fmt.Errorf("cannot unmarshal authz exec msgs") + } + msgs = append(msgs, innerMsg) + } + + // Recursively call this function with the inner messages + err := mcr.hasInvalidCommissionRateMsgs(ctx, msgs) + if err != nil { + return err + } + } + // Check for create validator messages if msg, ok := msg.(*stakingtypes.MsgCreateValidator); ok && mcr.isInvalidCreateMessage(msg) { return fmt.Errorf("max change rate must not exceed %f%%", mcr.maxCommissionChangeRate) @@ -82,8 +109,13 @@ func (mcr MsgChangeRateDecorator) isInvalidEditMessage(ctx sdk.Context, msg *sta return nil } + bech32Addr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + return fmt.Errorf("invalid validator address") + } + // Get validator info, if exists - valInfo, found := mcr.sk.GetValidator(ctx, sdk.ValAddress(msg.ValidatorAddress)) + valInfo, found := mcr.sk.GetValidator(ctx, sdk.ValAddress(bech32Addr)) if !found { return fmt.Errorf("validator not found") } diff --git a/scripts/test_node.sh b/scripts/test_node.sh index eda9db6da..4e33f74c3 100755 --- a/scripts/test_node.sh +++ b/scripts/test_node.sh @@ -90,10 +90,11 @@ from_scratch () { update_test_genesis '.app_state["builder"]["params"]["min_bid_increment"]["amount"]="1000000"' update_test_genesis '.app_state["builder"]["params"]["reserve_fee"]["denom"]="ujuno"' update_test_genesis '.app_state["builder"]["params"]["reserve_fee"]["amount"]="1000000"' + update_test_genesis '.app_state["staking"]["params"]["max_validators"]=1' # Allocate genesis accounts BINARY genesis add-genesis-account $KEY 10000000ujuno,1000utest --keyring-backend $KEYRING - BINARY genesis add-genesis-account $KEY2 1000000ujuno,1000utest --keyring-backend $KEYRING + BINARY genesis add-genesis-account $KEY2 10000000ujuno,1000utest --keyring-backend $KEYRING BINARY genesis add-genesis-account juno1see0htr47uapjvcvh0hu6385rp8lw3emu85lh5 100000000000ujuno --keyring-backend $KEYRING BINARY genesis gentx $KEY 1000000ujuno --keyring-backend $KEYRING --chain-id $CHAIN_ID From 9af04a126c5743f739b2e4a8ea89fc887f1d5c3e Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Sat, 28 Oct 2023 16:43:23 -0500 Subject: [PATCH 04/14] Fix unnecessary conversion --- app/decorators/change_rate_decorator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index aba7612f8..23c0847eb 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -115,7 +115,7 @@ func (mcr MsgChangeRateDecorator) isInvalidEditMessage(ctx sdk.Context, msg *sta } // Get validator info, if exists - valInfo, found := mcr.sk.GetValidator(ctx, sdk.ValAddress(bech32Addr)) + valInfo, found := mcr.sk.GetValidator(ctx, bech32Addr) if !found { return fmt.Errorf("validator not found") } From c29ce8505a266357fdb8ec1e2d1dfdac857e2448 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Mon, 6 Nov 2023 23:57:05 -0600 Subject: [PATCH 05/14] Add Std Msg Unit Tests --- app/ante.go | 2 +- app/decorators/change_rate_decorator.go | 9 +- app/decorators/change_rate_decorator_test.go | 245 +++++++++++++++++++ 3 files changed, 248 insertions(+), 8 deletions(-) create mode 100644 app/decorators/change_rate_decorator_test.go diff --git a/app/ante.go b/app/ante.go index e21bff853..60cba12ad 100644 --- a/app/ante.go +++ b/app/ante.go @@ -96,7 +96,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), decorators.MsgFilterDecorator{}, - decorators.NewChangeRateDecorator(options.StakingKeeper, options.Cdc), + decorators.NewChangeRateDecorator(&options.StakingKeeper), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(options.AccountKeeper), diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index 23c0847eb..8b4f6828b 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" @@ -19,13 +18,12 @@ const ( // MsgChangeRateDecorator defines the AnteHandler that filters & prevents messages // that create validators and exceed the max change rate of 5%. type MsgChangeRateDecorator struct { - sk stakingkeeper.Keeper - cdc codec.BinaryCodec + sk *stakingkeeper.Keeper maxCommissionChangeRate sdk.Dec } // Create new Change Rate Decorator -func NewChangeRateDecorator(sk stakingkeeper.Keeper, cdc codec.BinaryCodec) MsgChangeRateDecorator { +func NewChangeRateDecorator(sk *stakingkeeper.Keeper) MsgChangeRateDecorator { rate, err := sdk.NewDecFromStr(MaxChangeRate) if err != nil { @@ -34,7 +32,6 @@ func NewChangeRateDecorator(sk stakingkeeper.Keeper, cdc codec.BinaryCodec) MsgC return MsgChangeRateDecorator{ sk: sk, - cdc: cdc, maxCommissionChangeRate: rate, } } @@ -43,8 +40,6 @@ func NewChangeRateDecorator(sk stakingkeeper.Keeper, cdc codec.BinaryCodec) MsgC // creation of a validator. func (mcr MsgChangeRateDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - ctx.Logger().Error("MsgChangeRateDecorator", "Called", true) - err := mcr.hasInvalidCommissionRateMsgs(ctx, tx.GetMsgs()) if err != nil { return ctx, err diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go new file mode 100644 index 000000000..8ab4ed528 --- /dev/null +++ b/app/decorators/change_rate_decorator_test.go @@ -0,0 +1,245 @@ +package decorators_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + "github.com/CosmosContracts/juno/v18/app" + "github.com/stretchr/testify/suite" + + decorators "github.com/CosmosContracts/juno/v18/app/decorators" + appparams "github.com/CosmosContracts/juno/v18/app/params" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + protov2 "google.golang.org/protobuf/proto" +) + +// Define an empty ante handle +var ( + EmptyAnte = func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { + return ctx, nil + } +) + +type AnteTestSuite struct { + suite.Suite + + ctx sdk.Context + app *app.App + stakingKeeper *stakingkeeper.Keeper +} + +func (s *AnteTestSuite) SetupTest() { + isCheckTx := false + s.app = app.Setup(s.T()) + + s.ctx = s.app.BaseApp.NewContext(isCheckTx, tmproto.Header{ + ChainID: "testing", + Height: 10, + Time: time.Now().UTC(), + }) + + s.stakingKeeper = s.app.AppKeepers.StakingKeeper +} + +func TestAnteTestSuite(t *testing.T) { + suite.Run(t, new(AnteTestSuite)) +} + +func (s *AnteTestSuite) TestAnteCreateValidator() { + + testCases := []struct { + name string + maxChangeRate string + expPass bool + }{ + { + name: "success - maxChangeRate < 5%", + maxChangeRate: "0.01", + expPass: true, + }, + { + name: "success - maxChangeRate = 5%", + maxChangeRate: "0.05", + expPass: true, + }, + { + name: "fail - maxChangeRate > 5%", + maxChangeRate: "0.06", + expPass: false, + }, + { + name: "fail - maxChangeRate = 5.1%", + maxChangeRate: "0.051", + expPass: false, + }, + } + + for _, tc := range testCases { + tc := tc + + // Create change rate decorator + ante := decorators.NewChangeRateDecorator(s.stakingKeeper) + + // Create validator params + _, msg, err := createValidatorMsg(tc.maxChangeRate) + s.Require().NoError(err) + + // Submit the creation tx + _, err = ante.AnteHandle(s.ctx, NewMockTx(msg), false, EmptyAnte) + + // Check if the error is expected + if tc.expPass { + s.Require().NoError(err) + } else { + s.Require().Error(err) + s.Require().Contains(err.Error(), "max change rate must not exceed") + } + } +} + +func (s *AnteTestSuite) TestAnteEditValidator() { + + testCases := []struct { + name string + maxChangeRate string + expPass bool + }{ + { + name: "success - maxChangeRate < 5%", + maxChangeRate: "0.01", + expPass: true, + }, + { + name: "success - maxChangeRate = 5%", + maxChangeRate: "0.05", + expPass: true, + }, + { + name: "fail - maxChangeRate > 5%", + maxChangeRate: "0.06", + expPass: false, + }, + { + name: "fail - maxChangeRate = 5.1%", + maxChangeRate: "0.051", + expPass: false, + }, + } + + for _, tc := range testCases { + tc := tc + + // Create change rate decorator + ante := decorators.NewChangeRateDecorator(s.stakingKeeper) + + // Create validator + valPub, createMsg, err := createValidatorMsg("0.05") + s.Require().NoError(err) + + // Submit the creation tx + _, err = ante.AnteHandle(s.ctx, NewMockTx(createMsg), false, EmptyAnte) + s.Require().NoError(err) + + // Create the validator + val, err := stakingtypes.NewValidator( + sdk.ValAddress(valPub.Address()), + valPub, + createMsg.Description, + ) + s.Require().NoError(err) + + // Set the validator + s.stakingKeeper.SetValidator(s.ctx, val) + s.Require().NoError(err) + + // Edit validator params + valAddr := sdk.ValAddress(valPub.Address()) + description := stakingtypes.NewDescription("test_moniker", "", "", "", "") + newRate := math.LegacyMustNewDecFromStr(tc.maxChangeRate) + minDelegation := sdk.OneInt() + + // Edit existing validator msg + editMsg := stakingtypes.NewMsgEditValidator( + valAddr, + description, + &newRate, + &minDelegation, + ) + + // Submit the edit tx + _, err = ante.AnteHandle(s.ctx, NewMockTx(editMsg), false, EmptyAnte) + + // Check if the error is expected + if tc.expPass { + s.Require().NoError(err) + } else { + s.Require().Error(err) + s.Require().Contains(err.Error(), "commission rate cannot change by more than") + } + } +} + +// A helper function for getting a validator create msg +func createValidatorMsg(maxChangeRate string) (cryptotypes.PubKey, *stakingtypes.MsgCreateValidator, error) { + // Create validator params + valPub := secp256k1.GenPrivKey().PubKey() + valAddr := sdk.ValAddress(valPub.Address()) + bondDenom := appparams.BondDenom + selfBond := sdk.NewCoins(sdk.Coin{Amount: sdk.NewInt(100), Denom: bondDenom}) + stakingCoin := sdk.NewCoin(bondDenom, selfBond[0].Amount) + description := stakingtypes.NewDescription("test_moniker", "", "", "", "") + commission := stakingtypes.NewCommissionRates( + math.LegacyMustNewDecFromStr("0.1"), + math.LegacyMustNewDecFromStr("1"), + math.LegacyMustNewDecFromStr(maxChangeRate), + ) + + // Creating a Validator + msg, err := stakingtypes.NewMsgCreateValidator( + valAddr, + valPub, + stakingCoin, + description, + commission, + sdk.OneInt(), + ) + + // Return generated pub address, creation msg, and err + return valPub, msg, err +} + +func setBlockHeader(ctx sdk.Context, height uint64) sdk.Context { + h := ctx.BlockHeader() + h.Height = int64(height) + return ctx.WithBlockHeader(h) +} + +type MockTx struct { + msgs []sdk.Msg +} + +func NewMockTx(msgs ...sdk.Msg) MockTx { + return MockTx{ + msgs: msgs, + } +} + +func (tx MockTx) GetMsgs() []sdk.Msg { + return tx.msgs +} + +func (tx MockTx) GetMsgsV2() ([]protov2.Message, error) { + return nil, nil +} + +func (tx MockTx) ValidateBasic() error { + return nil +} From d9c7388fa9736f9c8045e9e4881a6ee343edaa39 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Tue, 7 Nov 2023 17:17:12 -0600 Subject: [PATCH 06/14] Test All Change Rate Values --- app/decorators/change_rate_decorator_test.go | 88 ++++++-------------- 1 file changed, 27 insertions(+), 61 deletions(-) diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index 8ab4ed528..ceb847c0e 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -1,6 +1,7 @@ package decorators_test import ( + "fmt" "testing" "time" @@ -55,48 +56,24 @@ func TestAnteTestSuite(t *testing.T) { func (s *AnteTestSuite) TestAnteCreateValidator() { - testCases := []struct { - name string - maxChangeRate string - expPass bool - }{ - { - name: "success - maxChangeRate < 5%", - maxChangeRate: "0.01", - expPass: true, - }, - { - name: "success - maxChangeRate = 5%", - maxChangeRate: "0.05", - expPass: true, - }, - { - name: "fail - maxChangeRate > 5%", - maxChangeRate: "0.06", - expPass: false, - }, - { - name: "fail - maxChangeRate = 5.1%", - maxChangeRate: "0.051", - expPass: false, - }, - } + // Loop through all possible change rates + for i := 0; i <= 100; i++ { - for _, tc := range testCases { - tc := tc + // Calculate change rate + maxChangeRate := getChangeRate(i) // Create change rate decorator ante := decorators.NewChangeRateDecorator(s.stakingKeeper) // Create validator params - _, msg, err := createValidatorMsg(tc.maxChangeRate) + _, msg, err := createValidatorMsg(maxChangeRate) s.Require().NoError(err) // Submit the creation tx _, err = ante.AnteHandle(s.ctx, NewMockTx(msg), false, EmptyAnte) // Check if the error is expected - if tc.expPass { + if i <= 5 { s.Require().NoError(err) } else { s.Require().Error(err) @@ -106,36 +83,11 @@ func (s *AnteTestSuite) TestAnteCreateValidator() { } func (s *AnteTestSuite) TestAnteEditValidator() { + // Loop through all possible change rates + for i := 0; i <= 100; i++ { - testCases := []struct { - name string - maxChangeRate string - expPass bool - }{ - { - name: "success - maxChangeRate < 5%", - maxChangeRate: "0.01", - expPass: true, - }, - { - name: "success - maxChangeRate = 5%", - maxChangeRate: "0.05", - expPass: true, - }, - { - name: "fail - maxChangeRate > 5%", - maxChangeRate: "0.06", - expPass: false, - }, - { - name: "fail - maxChangeRate = 5.1%", - maxChangeRate: "0.051", - expPass: false, - }, - } - - for _, tc := range testCases { - tc := tc + // Calculate change rate + maxChangeRate := getChangeRate(i) // Create change rate decorator ante := decorators.NewChangeRateDecorator(s.stakingKeeper) @@ -163,7 +115,7 @@ func (s *AnteTestSuite) TestAnteEditValidator() { // Edit validator params valAddr := sdk.ValAddress(valPub.Address()) description := stakingtypes.NewDescription("test_moniker", "", "", "", "") - newRate := math.LegacyMustNewDecFromStr(tc.maxChangeRate) + newRate := math.LegacyMustNewDecFromStr(maxChangeRate) minDelegation := sdk.OneInt() // Edit existing validator msg @@ -178,7 +130,7 @@ func (s *AnteTestSuite) TestAnteEditValidator() { _, err = ante.AnteHandle(s.ctx, NewMockTx(editMsg), false, EmptyAnte) // Check if the error is expected - if tc.expPass { + if i <= 5 { s.Require().NoError(err) } else { s.Require().Error(err) @@ -187,6 +139,20 @@ func (s *AnteTestSuite) TestAnteEditValidator() { } } +// Convert an integer to a percentage, formatted as a string +// Example: 5 -> "0.05", 10 -> "0.1" +func getChangeRate(i int) string { + maxChangeRate := "0." + + if i < 10 { + maxChangeRate += fmt.Sprint("0", i) + } else { + maxChangeRate += fmt.Sprint(i) + } + + return maxChangeRate +} + // A helper function for getting a validator create msg func createValidatorMsg(maxChangeRate string) (cryptotypes.PubKey, *stakingtypes.MsgCreateValidator, error) { // Create validator params From c0a021f561f4e057437914f8f94fcaa4a5ec2b55 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Tue, 7 Nov 2023 17:43:49 -0600 Subject: [PATCH 07/14] Lint --- app/decorators/change_rate_decorator.go | 4 ---- app/decorators/change_rate_decorator_test.go | 24 ++++++++------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index 8b4f6828b..6cbb8230a 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -5,7 +5,6 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -24,7 +23,6 @@ type MsgChangeRateDecorator struct { // Create new Change Rate Decorator func NewChangeRateDecorator(sk *stakingkeeper.Keeper) MsgChangeRateDecorator { - rate, err := sdk.NewDecFromStr(MaxChangeRate) if err != nil { panic(err) @@ -39,7 +37,6 @@ func NewChangeRateDecorator(sk *stakingkeeper.Keeper) MsgChangeRateDecorator { // The AnteHandle checks for transactions that exceed the max change rate of 5% on the // creation of a validator. func (mcr MsgChangeRateDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - err := mcr.hasInvalidCommissionRateMsgs(ctx, tx.GetMsgs()) if err != nil { return ctx, err @@ -98,7 +95,6 @@ func (mcr MsgChangeRateDecorator) isInvalidCreateMessage(msg *stakingtypes.MsgCr // Check if the edit validator message is invalid func (mcr MsgChangeRateDecorator) isInvalidEditMessage(ctx sdk.Context, msg *stakingtypes.MsgEditValidator) error { - // Skip if the commission rate is not being modified if msg.CommissionRate == nil { return nil diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index ceb847c0e..8764c9092 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -5,21 +5,22 @@ import ( "testing" "time" - "cosmossdk.io/math" - "github.com/CosmosContracts/juno/v18/app" "github.com/stretchr/testify/suite" - - decorators "github.com/CosmosContracts/juno/v18/app/decorators" - appparams "github.com/CosmosContracts/juno/v18/app/params" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + protov2 "google.golang.org/protobuf/proto" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - protov2 "google.golang.org/protobuf/proto" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/CosmosContracts/juno/v18/app" + decorators "github.com/CosmosContracts/juno/v18/app/decorators" + appparams "github.com/CosmosContracts/juno/v18/app/params" ) // Define an empty ante handle @@ -55,7 +56,6 @@ func TestAnteTestSuite(t *testing.T) { } func (s *AnteTestSuite) TestAnteCreateValidator() { - // Loop through all possible change rates for i := 0; i <= 100; i++ { @@ -182,12 +182,6 @@ func createValidatorMsg(maxChangeRate string) (cryptotypes.PubKey, *stakingtypes return valPub, msg, err } -func setBlockHeader(ctx sdk.Context, height uint64) sdk.Context { - h := ctx.BlockHeader() - h.Height = int64(height) - return ctx.WithBlockHeader(h) -} - type MockTx struct { msgs []sdk.Msg } From 75ca9e3da409d2e02f2ef6b7c2ebb6fc13c645b8 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Wed, 8 Nov 2023 17:41:47 -0600 Subject: [PATCH 08/14] Fix Authz Decoding --- app/decorators/change_rate_decorator.go | 14 ++-- app/decorators/change_rate_decorator_test.go | 67 +++++++++++++++----- go.mod | 2 +- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index 6cbb8230a..2ce8feeaf 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -1,7 +1,6 @@ package decorators import ( - "encoding/json" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,18 +53,13 @@ func (mcr MsgChangeRateDecorator) hasInvalidCommissionRateMsgs(ctx sdk.Context, ctx.Logger().Error("MsgChangeRateDecorator", "Authz", execMsg.Msgs) - // Unmarshal the inner messages - var msgs []sdk.Msg - for _, v := range execMsg.Msgs { - var innerMsg sdk.Msg - if err := json.Unmarshal(v.Value, &innerMsg); err != nil { - return fmt.Errorf("cannot unmarshal authz exec msgs") - } - msgs = append(msgs, innerMsg) + msgs, err := execMsg.GetMessages() + if err != nil { + return err } // Recursively call this function with the inner messages - err := mcr.hasInvalidCommissionRateMsgs(ctx, msgs) + err = mcr.hasInvalidCommissionRateMsgs(ctx, msgs) if err != nil { return err } diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index 8764c9092..982106b84 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -55,9 +56,14 @@ func TestAnteTestSuite(t *testing.T) { suite.Run(t, new(AnteTestSuite)) } +// Test the change rate decorator with standard create msgs, +// authz create messages, and inline authz create messages func (s *AnteTestSuite) TestAnteCreateValidator() { + // Grantee used for authz msgs + grantee := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + // Loop through all possible change rates - for i := 0; i <= 100; i++ { + for i := 0; i <= 0; i++ { // Calculate change rate maxChangeRate := getChangeRate(i) @@ -71,18 +77,26 @@ func (s *AnteTestSuite) TestAnteCreateValidator() { // Submit the creation tx _, err = ante.AnteHandle(s.ctx, NewMockTx(msg), false, EmptyAnte) + validateCreateMsg(s, err, i) - // Check if the error is expected - if i <= 5 { - s.Require().NoError(err) - } else { - s.Require().Error(err) - s.Require().Contains(err.Error(), "max change rate must not exceed") - } + // Submit the creation tx with authz + authzMsg := authz.NewMsgExec(grantee, []sdk.Msg{msg}) + _, err = ante.AnteHandle(s.ctx, NewMockTx(&authzMsg), false, EmptyAnte) + validateCreateMsg(s, err, i) + + // Submit the creation tx with inline authz + inlineAuthzMsg := authz.NewMsgExec(grantee, []sdk.Msg{&authzMsg}) + _, err = ante.AnteHandle(s.ctx, NewMockTx(&inlineAuthzMsg), false, EmptyAnte) + validateCreateMsg(s, err, i) } } +// Test the change rate decorator with standard edit msgs, +// authz edit messages, and inline authz edit messages func (s *AnteTestSuite) TestAnteEditValidator() { + // Grantee used for authz msgs + grantee := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + // Loop through all possible change rates for i := 0; i <= 100; i++ { @@ -128,14 +142,17 @@ func (s *AnteTestSuite) TestAnteEditValidator() { // Submit the edit tx _, err = ante.AnteHandle(s.ctx, NewMockTx(editMsg), false, EmptyAnte) + validateEditMsg(s, err, i) - // Check if the error is expected - if i <= 5 { - s.Require().NoError(err) - } else { - s.Require().Error(err) - s.Require().Contains(err.Error(), "commission rate cannot change by more than") - } + // Submit the edit tx with authz + authzMsg := authz.NewMsgExec(grantee, []sdk.Msg{editMsg}) + _, err = ante.AnteHandle(s.ctx, NewMockTx(&authzMsg), false, EmptyAnte) + validateEditMsg(s, err, i) + + // Submit the edit tx with inline authz + inlineAuthzMsg := authz.NewMsgExec(grantee, []sdk.Msg{&authzMsg}) + _, err = ante.AnteHandle(s.ctx, NewMockTx(&inlineAuthzMsg), false, EmptyAnte) + validateEditMsg(s, err, i) } } @@ -182,6 +199,26 @@ func createValidatorMsg(maxChangeRate string) (cryptotypes.PubKey, *stakingtypes return valPub, msg, err } +// Validate the create msg err is expected +func validateCreateMsg(s *AnteTestSuite, err error, i int) { + if i <= 5 { + s.Require().NoError(err) + } else { + s.Require().Error(err) + s.Require().Contains(err.Error(), "max change rate must not exceed") + } +} + +// Validate the edit msg err is expected +func validateEditMsg(s *AnteTestSuite, err error, i int) { + if i <= 5 { + s.Require().NoError(err) + } else { + s.Require().Error(err) + s.Require().Contains(err.Error(), "commission rate cannot change by more than") + } +} + type MockTx struct { msgs []sdk.Msg } diff --git a/go.mod b/go.mod index c47f01463..e058d0e9a 100644 --- a/go.mod +++ b/go.mod @@ -180,7 +180,7 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect - google.golang.org/protobuf v1.31.0 // indirect + google.golang.org/protobuf v1.31.0 gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.7 // indirect From 49dfdb217fa10ad67655be14eb1ddbd873da4969 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Wed, 8 Nov 2023 17:42:56 -0600 Subject: [PATCH 09/14] Remove Debug Statements --- app/decorators/change_rate_decorator.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/decorators/change_rate_decorator.go b/app/decorators/change_rate_decorator.go index 2ce8feeaf..ab464657e 100644 --- a/app/decorators/change_rate_decorator.go +++ b/app/decorators/change_rate_decorator.go @@ -51,8 +51,6 @@ func (mcr MsgChangeRateDecorator) hasInvalidCommissionRateMsgs(ctx sdk.Context, // Check if an authz message, loop through all inner messages, and recursively call this function if execMsg, ok := msg.(*authz.MsgExec); ok { - ctx.Logger().Error("MsgChangeRateDecorator", "Authz", execMsg.Msgs) - msgs, err := execMsg.GetMessages() if err != nil { return err From 0d171c3db55dbac826dd9bbecad92f900f1dacba Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Wed, 8 Nov 2023 18:15:44 -0600 Subject: [PATCH 10/14] Fix Change Rate Test Loop --- app/decorators/change_rate_decorator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index 982106b84..2271ab48b 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -63,7 +63,7 @@ func (s *AnteTestSuite) TestAnteCreateValidator() { grantee := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) // Loop through all possible change rates - for i := 0; i <= 0; i++ { + for i := 0; i <= 100; i++ { // Calculate change rate maxChangeRate := getChangeRate(i) From 9401bc680075d2f917396ba9636082a80154c1a2 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Wed, 8 Nov 2023 19:45:19 -0600 Subject: [PATCH 11/14] Revert Test Node Script Changes --- scripts/test_node.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/test_node.sh b/scripts/test_node.sh index 4aed1a86d..bd8a2e1b7 100755 --- a/scripts/test_node.sh +++ b/scripts/test_node.sh @@ -90,11 +90,10 @@ from_scratch () { update_test_genesis '.app_state["builder"]["params"]["min_bid_increment"]["amount"]="1000000"' update_test_genesis '.app_state["builder"]["params"]["reserve_fee"]["denom"]="ujuno"' update_test_genesis '.app_state["builder"]["params"]["reserve_fee"]["amount"]="1000000"' - update_test_genesis '.app_state["staking"]["params"]["max_validators"]=1' # Allocate genesis accounts BINARY genesis add-genesis-account $KEY 10000000ujuno,1000utest --keyring-backend $KEYRING - BINARY genesis add-genesis-account $KEY2 10000000ujuno,1000utest --keyring-backend $KEYRING + BINARY genesis add-genesis-account $KEY2 1000000ujuno,1000utest --keyring-backend $KEYRING BINARY genesis add-genesis-account juno1see0htr47uapjvcvh0hu6385rp8lw3emu85lh5 100000000000ujuno --keyring-backend $KEYRING # BINARY genesis add-genesis-account juno1xgj5vkjknnvwu3je3usm2fasvr6a9ust9q7gxm 100000000000ujuno --keyring-backend $KEYRING # feeprepay From efda9e4e8fc4e121c6d1f9f00b5f4796f26d0ccd Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 21 Nov 2023 18:33:40 -0600 Subject: [PATCH 12/14] simplify `getChangeRate` --- app/decorators/change_rate_decorator_test.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index 2271ab48b..42a6a6e72 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -128,14 +128,13 @@ func (s *AnteTestSuite) TestAnteEditValidator() { // Edit validator params valAddr := sdk.ValAddress(valPub.Address()) - description := stakingtypes.NewDescription("test_moniker", "", "", "", "") newRate := math.LegacyMustNewDecFromStr(maxChangeRate) minDelegation := sdk.OneInt() // Edit existing validator msg editMsg := stakingtypes.NewMsgEditValidator( valAddr, - description, + createMsg.Description, &newRate, &minDelegation, ) @@ -159,15 +158,11 @@ func (s *AnteTestSuite) TestAnteEditValidator() { // Convert an integer to a percentage, formatted as a string // Example: 5 -> "0.05", 10 -> "0.1" func getChangeRate(i int) string { - maxChangeRate := "0." - - if i < 10 { - maxChangeRate += fmt.Sprint("0", i) - } else { - maxChangeRate += fmt.Sprint(i) + if i >= 100 { + return "1.00" } - return maxChangeRate + return fmt.Sprintf("0.%02d", i) } // A helper function for getting a validator create msg From 170cdfabfaa60d8f54bdc33cf49005a813d2c38a Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Mon, 11 Dec 2023 18:25:16 -0600 Subject: [PATCH 13/14] Ensure Max Change Rate on Upgrade --- app/decorators/change_rate_decorator_test.go | 6 +-- app/upgrades/v19/upgrade_test.go | 45 ++++++++++++++++++-- app/upgrades/v19/upgrades.go | 15 ++++++- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/app/decorators/change_rate_decorator_test.go b/app/decorators/change_rate_decorator_test.go index 42a6a6e72..fb98f1d1e 100644 --- a/app/decorators/change_rate_decorator_test.go +++ b/app/decorators/change_rate_decorator_test.go @@ -19,9 +19,9 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/CosmosContracts/juno/v18/app" - decorators "github.com/CosmosContracts/juno/v18/app/decorators" - appparams "github.com/CosmosContracts/juno/v18/app/params" + "github.com/CosmosContracts/juno/v19/app" + decorators "github.com/CosmosContracts/juno/v19/app/decorators" + appparams "github.com/CosmosContracts/juno/v19/app/params" ) // Define an empty ante handle diff --git a/app/upgrades/v19/upgrade_test.go b/app/upgrades/v19/upgrade_test.go index 7b07b4b93..07e3ac969 100644 --- a/app/upgrades/v19/upgrade_test.go +++ b/app/upgrades/v19/upgrade_test.go @@ -1,12 +1,18 @@ package v19_test import ( + "fmt" "testing" "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/CosmosContracts/juno/v19/app/apptesting" - v18 "github.com/CosmosContracts/juno/v19/app/upgrades/v18" + decorators "github.com/CosmosContracts/juno/v19/app/decorators" + v19 "github.com/CosmosContracts/juno/v19/app/upgrades/v19" ) type UpgradeTestSuite struct { @@ -28,13 +34,44 @@ func (s *UpgradeTestSuite) TestUpgrade() { preUpgradeChecks(s) upgradeHeight := int64(5) - s.ConfirmUpgradeSucceeded(v18.UpgradeName, upgradeHeight) + s.ConfirmUpgradeSucceeded(v19.UpgradeName, upgradeHeight) postUpgradeChecks(s) } -func preUpgradeChecks(_ *UpgradeTestSuite) { +func preUpgradeChecks(s *UpgradeTestSuite) { + // Change Rate Decorator Test + // Create a validator with a max change rate of 20% + for i := 0; i < 100; i++ { + + // Create validator keys & desc + valPub := secp256k1.GenPrivKey().PubKey() + valAddr := sdk.ValAddress(valPub.Address()) + description := stakingtypes.NewDescription(fmt.Sprintf("test_moniker%d", i), "", "", "", "") + validator, err := stakingtypes.NewValidator( + valAddr, + valPub, + description, + ) + s.Require().NoError(err) + + // Set validator commission + changeRate := "1.00" + if i < 100 { + changeRate = fmt.Sprintf("0.%02d", i) + } + validator.Commission.MaxChangeRate.Set(sdk.MustNewDecFromStr(changeRate)) + + // Set validator in kv store + s.App.AppKeepers.StakingKeeper.SetValidator(s.Ctx, validator) + } } -func postUpgradeChecks(_ *UpgradeTestSuite) { +func postUpgradeChecks(s *UpgradeTestSuite) { + // Change Rate Decorator Test + // Ensure all validators have a max change rate of 5% + validators := s.App.AppKeepers.StakingKeeper.GetAllValidators(s.Ctx) + for _, validator := range validators { + s.Require().True(validator.Commission.MaxChangeRate.LTE(sdk.MustNewDecFromStr(decorators.MaxChangeRate))) + } } diff --git a/app/upgrades/v19/upgrades.go b/app/upgrades/v19/upgrades.go index cc935fc91..246bd2214 100644 --- a/app/upgrades/v19/upgrades.go +++ b/app/upgrades/v19/upgrades.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + decorators "github.com/CosmosContracts/juno/v19/app/decorators" "github.com/CosmosContracts/juno/v19/app/keepers" "github.com/CosmosContracts/juno/v19/app/upgrades" ) @@ -14,7 +15,7 @@ import ( func CreateV19UpgradeHandler( mm *module.Manager, cfg module.Configurator, - _ *keepers.AppKeepers, + ak *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) @@ -30,6 +31,18 @@ func CreateV19UpgradeHandler( } logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) + // Change Rate Decorator Migration + // Ensure all Validators have a max change rate of 5% + maxChangeRate := sdk.MustNewDecFromStr(decorators.MaxChangeRate) + validators := ak.StakingKeeper.GetAllValidators(ctx) + + for _, validator := range validators { + if validator.Commission.MaxChangeRate.GT(maxChangeRate) { + validator.Commission.MaxChangeRate.Set(maxChangeRate) + ak.StakingKeeper.SetValidator(ctx, validator) + } + } + return versionMap, err } } From f4364e94e37e01c194b39e606f0209804a6b050c Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Mon, 11 Dec 2023 19:51:36 -0600 Subject: [PATCH 14/14] nits --- app/ante.go | 4 ++-- app/upgrades/v19/upgrades.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/ante.go b/app/ante.go index 1eb21d29c..47153d18e 100644 --- a/app/ante.go +++ b/app/ante.go @@ -90,14 +90,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { gfd := globalfeeante.NewFeeDecorator(options.BypassMinFeeMsgTypes, options.GlobalFeeKeeper, options.StakingKeeper, maxBypassMinFeeMsgGasUsage, &isFeePayTx) anteDecorators := []sdk.AnteDecorator{ - // GLobalFee query params for minimum fee + // GlobalFee query params for minimum fee ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), decorators.MsgFilterDecorator{}, - decorators.NewChangeRateDecorator(&options.StakingKeeper), ante.NewValidateBasicDecorator(), + decorators.NewChangeRateDecorator(&options.StakingKeeper), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), diff --git a/app/upgrades/v19/upgrades.go b/app/upgrades/v19/upgrades.go index 246bd2214..ab3fe61c6 100644 --- a/app/upgrades/v19/upgrades.go +++ b/app/upgrades/v19/upgrades.go @@ -15,7 +15,7 @@ import ( func CreateV19UpgradeHandler( mm *module.Manager, cfg module.Configurator, - ak *keepers.AppKeepers, + k *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) @@ -34,12 +34,12 @@ func CreateV19UpgradeHandler( // Change Rate Decorator Migration // Ensure all Validators have a max change rate of 5% maxChangeRate := sdk.MustNewDecFromStr(decorators.MaxChangeRate) - validators := ak.StakingKeeper.GetAllValidators(ctx) + validators := k.StakingKeeper.GetAllValidators(ctx) for _, validator := range validators { if validator.Commission.MaxChangeRate.GT(maxChangeRate) { validator.Commission.MaxChangeRate.Set(maxChangeRate) - ak.StakingKeeper.SetValidator(ctx, validator) + k.StakingKeeper.SetValidator(ctx, validator) } }