From 163b4cbb3ee4c747bf8cba7989105d6db7922511 Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Tue, 17 Dec 2024 14:38:25 +0900 Subject: [PATCH 1/4] chore: release v4 --- ...48ff35bf05cd2d09bdad445d6c40e41b6fe4f362af4270ce7e.yaml | 6 ------ ...f055a293299b782c79785a8c6c3f7034ebe62f3ea878266583.yaml | 6 ------ ...4643c917fac3a9cdc719c94b9c81a14a08a448e9ec1c4da887.yaml | 6 ------ CHANGELOG.md | 7 +++++++ 4 files changed, 7 insertions(+), 18 deletions(-) delete mode 100644 .changeset/entries/0578182a108ccf48ff35bf05cd2d09bdad445d6c40e41b6fe4f362af4270ce7e.yaml delete mode 100644 .changeset/entries/861a96d7026170f055a293299b782c79785a8c6c3f7034ebe62f3ea878266583.yaml delete mode 100644 .changeset/entries/d4515e7fd747054643c917fac3a9cdc719c94b9c81a14a08a448e9ec1c4da887.yaml diff --git a/.changeset/entries/0578182a108ccf48ff35bf05cd2d09bdad445d6c40e41b6fe4f362af4270ce7e.yaml b/.changeset/entries/0578182a108ccf48ff35bf05cd2d09bdad445d6c40e41b6fe4f362af4270ce7e.yaml deleted file mode 100644 index 62afb7d9..00000000 --- a/.changeset/entries/0578182a108ccf48ff35bf05cd2d09bdad445d6c40e41b6fe4f362af4270ce7e.yaml +++ /dev/null @@ -1,6 +0,0 @@ -type: feat -module: none -pull_request: 222 -description: Added `v4` upgrade handler -backward_compatible: true -date: 2024-12-17T01:38:30.312655103Z diff --git a/.changeset/entries/861a96d7026170f055a293299b782c79785a8c6c3f7034ebe62f3ea878266583.yaml b/.changeset/entries/861a96d7026170f055a293299b782c79785a8c6c3f7034ebe62f3ea878266583.yaml deleted file mode 100644 index ab62de2a..00000000 --- a/.changeset/entries/861a96d7026170f055a293299b782c79785a8c6c3f7034ebe62f3ea878266583.yaml +++ /dev/null @@ -1,6 +0,0 @@ -type: refactor -module: none -pull_request: 208 -description: Apply Cosmos SDK v0.50 conventions -backward_compatible: true -date: 2024-12-10T08:38:13.018999Z diff --git a/.changeset/entries/d4515e7fd747054643c917fac3a9cdc719c94b9c81a14a08a448e9ec1c4da887.yaml b/.changeset/entries/d4515e7fd747054643c917fac3a9cdc719c94b9c81a14a08a448e9ec1c4da887.yaml deleted file mode 100644 index 6dcf9bb7..00000000 --- a/.changeset/entries/d4515e7fd747054643c917fac3a9cdc719c94b9c81a14a08a448e9ec1c4da887.yaml +++ /dev/null @@ -1,6 +0,0 @@ -type: deps -module: none -pull_request: 221 -description: Updated `github.com/cosmos/cosmos-sdk` to `v0.50.11` -backward_compatible: false -date: 2024-12-17T00:59:04.783742663Z diff --git a/CHANGELOG.md b/CHANGELOG.md index a5fc8461..2558433c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --> +## Version 4.0.0 +### Features +- ([\#222](https://github.com/milkyway-labs/milkyway/pull/222)) Added `v4` upgrade handler + +### Dependencies +- ([\#221](https://github.com/milkyway-labs/milkyway/pull/221)) Updated `github.com/cosmos/cosmos-sdk` to `v0.50.11` + ## Version 3.0.0 ### Features #### Liquid Vesting From ba5dff27a08eb00f5289b3172970006cee3c15aa Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 18 Dec 2024 14:13:21 +0900 Subject: [PATCH 2/4] feat: remove gov ante decorators --- ante/ante.go | 8 +- ante/gov_expedited_ante.go | 80 ---------- ante/gov_expedited_ante_test.go | 218 ------------------------- ante/gov_vote_ante.go | 145 ----------------- ante/gov_vote_ante_test.go | 273 -------------------------------- app/app.go | 2 +- 6 files changed, 4 insertions(+), 722 deletions(-) delete mode 100644 ante/gov_expedited_ante.go delete mode 100644 ante/gov_expedited_ante_test.go delete mode 100644 ante/gov_vote_ante.go delete mode 100644 ante/gov_vote_ante_test.go diff --git a/ante/ante.go b/ante/ante.go index 1b9dce20..9893ddc3 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -39,7 +39,7 @@ type HandlerOptions struct { AccountKeeper feemarketante.AccountKeeper BankKeeper feemarketante.BankKeeper Codec codec.BinaryCodec - IBCkeeper *ibckeeper.Keeper + IBCKeeper *ibckeeper.Keeper StakingKeeper *stakingkeeper.Keeper FeeMarketKeeper *feemarketkeeper.Keeper TxFeeChecker ante.TxFeeChecker @@ -57,7 +57,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { if opts.SignModeHandler == nil { return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "sign mode handler is required for AnteHandler") } - if opts.IBCkeeper == nil { + if opts.IBCKeeper == nil { return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "IBC keeper is required for AnteHandler") } if opts.FeeMarketKeeper == nil { @@ -82,14 +82,12 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(opts.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), - NewGovVoteDecorator(opts.Codec, opts.StakingKeeper), - NewGovExpeditedProposalsDecorator(opts.Codec), ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(opts.AccountKeeper), ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer), ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler), ante.NewIncrementSequenceDecorator(opts.AccountKeeper), - ibcante.NewRedundantRelayDecorator(opts.IBCkeeper), + ibcante.NewRedundantRelayDecorator(opts.IBCKeeper), } if UseFeeMarketDecorator { diff --git a/ante/gov_expedited_ante.go b/ante/gov_expedited_ante.go deleted file mode 100644 index 4d801246..00000000 --- a/ante/gov_expedited_ante.go +++ /dev/null @@ -1,80 +0,0 @@ -package ante - -import ( - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - - milkywayerrors "github.com/milkyway-labs/milkyway/v4/types/errors" -) - -var expeditedPropDecoratorEnabled = true - -// SetExpeditedProposalsEnabled toggles the expedited proposals decorator on/off. -// Should only be used in testing - this is to allow simtests to pass. -func SetExpeditedProposalsEnabled(val bool) { - expeditedPropDecoratorEnabled = val -} - -var expeditedPropsWhitelist = map[string]struct{}{ - "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {}, - "/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {}, -} - -// Check if the proposal is whitelisted for expedited voting. -type GovExpeditedProposalsDecorator struct { - cdc codec.BinaryCodec -} - -func NewGovExpeditedProposalsDecorator(cdc codec.BinaryCodec) GovExpeditedProposalsDecorator { - return GovExpeditedProposalsDecorator{ - cdc: cdc, - } -} - -// AnteHandle checks if the proposal is whitelisted for expedited voting. -// Only proposals submitted using "milkywayd tx gov submit-proposal" can be expedited. -// Legacy proposals submitted using "milkywayd tx gov submit-legacy-proposal" cannot be marked as expedited. -func (g GovExpeditedProposalsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - if expeditedPropDecoratorEnabled { - for _, msg := range tx.GetMsgs() { - prop, ok := msg.(*govv1.MsgSubmitProposal) - if !ok { - continue - } - if prop.Expedited { - if err := g.validateExpeditedGovProp(prop); err != nil { - return ctx, err - } - } - } - } - return next(ctx, tx, simulate) -} - -func (g GovExpeditedProposalsDecorator) isWhitelisted(msgType string) bool { - _, ok := expeditedPropsWhitelist[msgType] - return ok -} - -func (g GovExpeditedProposalsDecorator) validateExpeditedGovProp(prop *govv1.MsgSubmitProposal) error { - msgs := prop.GetMessages() - if len(msgs) == 0 { - return milkywayerrors.ErrInvalidExpeditedProposal - } - for _, message := range msgs { - // in case of legacy content submitted using govv1.MsgSubmitProposal - if sdkMsg, isLegacy := message.GetCachedValue().(*govv1.MsgExecLegacyContent); isLegacy { - if !g.isWhitelisted(sdkMsg.Content.TypeUrl) { - return errorsmod.Wrapf(milkywayerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", sdkMsg.Content.TypeUrl) - } - continue - } - if !g.isWhitelisted(message.TypeUrl) { - return errorsmod.Wrapf(milkywayerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", message.TypeUrl) - } - } - return nil -} diff --git a/ante/gov_expedited_ante_test.go b/ante/gov_expedited_ante_test.go deleted file mode 100644 index a3e73946..00000000 --- a/ante/gov_expedited_ante_test.go +++ /dev/null @@ -1,218 +0,0 @@ -package ante_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - upgradetypes "cosmossdk.io/x/upgrade/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/milkyway-labs/milkyway/v4/ante" - "github.com/milkyway-labs/milkyway/v4/app/helpers" -) - -func TestGovExpeditedProposalsDecorator(t *testing.T) { - milkyWayApp := helpers.Setup(t) - - testCases := []struct { - name string - ctx sdk.Context - msgs []sdk.Msg - expectErr bool - }{ - // these cases should pass - { - name: "expedited - govv1.MsgSubmitProposal - MsgSoftwareUpgrade", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&upgradetypes.MsgSoftwareUpgrade{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - Plan: upgradetypes.Plan{ - Name: "upgrade plan-plan", - Info: "some text here", - Height: 123456789, - }, - }}, true), - }, - expectErr: false, - }, - { - name: "expedited - govv1.MsgSubmitProposal - MsgCancelUpgrade", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&upgradetypes.MsgCancelUpgrade{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }}, true), - }, - expectErr: false, - }, - { - name: "normal - govv1.MsgSubmitProposal - TextProposal", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newLegacyTextProp(false), // normal - }, - expectErr: false, - }, - { - name: "normal - govv1.MsgSubmitProposal - MsgCommunityPoolSpend", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&distrtypes.MsgCommunityPoolSpend{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - Recipient: sdk.AccAddress{}.String(), - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), - }}, false), // normal - }, - expectErr: false, - }, - { - name: "normal - govv1.MsgSubmitProposal - MsgTransfer", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&banktypes.MsgSend{ - FromAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - ToAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), - }}, false), // normal - }, - expectErr: false, - }, - { - name: "normal - govv1.MsgSubmitProposal - MsgUpdateParams", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&banktypes.MsgUpdateParams{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }}, false), - }, - expectErr: false, - }, - // legacy proposals - antehandler should not affect them - // submitted using "milkywayd tx gov submit-legacy-proposal" - { - name: "normal - govv1beta.MsgSubmitProposal - LegacySoftwareUpgrade", - ctx: sdk.Context{}, - msgs: []sdk.Msg{newGovV1BETA1LegacyUpgradeProp()}, - expectErr: false, - }, - { - name: "normal - govv1beta.MsgSubmitProposal - LegacyCancelSoftwareUpgrade", - ctx: sdk.Context{}, - msgs: []sdk.Msg{newGovV1BETA1LegacyCancelUpgradeProp()}, - expectErr: false, - }, - // these cases should fail - // these are normal proposals, not whitelisted for expedited voting - { - name: "fail - expedited - govv1.MsgSubmitProposal - Empty", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{}, true), - }, - expectErr: true, - }, - { - name: "fail - expedited - govv1.MsgSubmitProposal - TextProposal", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newLegacyTextProp(true), // expedite - }, - expectErr: true, - }, - { - name: "fail - expedited - govv1.MsgSubmitProposal - MsgCommunityPoolSpend", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&distrtypes.MsgCommunityPoolSpend{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - Recipient: sdk.AccAddress{}.String(), - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), - }}, true), - }, - expectErr: true, - }, - { - name: "fail - expedited - govv1.MsgSubmitProposal - MsgTransfer", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&banktypes.MsgSend{ - FromAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - ToAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), - }}, true), - }, - expectErr: true, - }, - { - name: "fail - expedited - govv1.MsgSubmitProposal - MsgUpdateParams", - ctx: sdk.Context{}, - msgs: []sdk.Msg{ - newGovProp([]sdk.Msg{&banktypes.MsgUpdateParams{ - Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - }}, true), - }, - expectErr: true, - }, - } - - for _, tc := range testCases { - tc := tc - - t.Run(tc.name, func(t *testing.T) { - txCfg := milkyWayApp.GetTxConfig() - decorator := ante.NewGovExpeditedProposalsDecorator(milkyWayApp.AppCodec()) - - txBuilder := txCfg.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs(tc.msgs...)) - - _, err := decorator.AnteHandle(tc.ctx, txBuilder.GetTx(), false, - func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { return ctx, nil }) - if tc.expectErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) - } -} - -func newLegacyTextProp(expedite bool) *govv1.MsgSubmitProposal { - testProposal := govv1beta1.NewTextProposal("Proposal", "Test as normal proposal") - msgContent, err := govv1.NewLegacyContent(testProposal, "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn") - if err != nil { - return nil - } - return newGovProp([]sdk.Msg{msgContent}, expedite) -} - -func newGovV1BETA1LegacyUpgradeProp() *govv1beta1.MsgSubmitProposal { - legacyContent := upgradetypes.NewSoftwareUpgradeProposal("test legacy upgrade", "test legacy upgrade", upgradetypes.Plan{ - Name: "upgrade plan-plan", - Info: "some text here", - Height: 123456789, - }) - - msg, _ := govv1beta1.NewMsgSubmitProposal(legacyContent, sdk.NewCoins(), sdk.AccAddress{}) - return msg -} - -func newGovV1BETA1LegacyCancelUpgradeProp() *govv1beta1.MsgSubmitProposal { - legacyContent := upgradetypes.NewCancelSoftwareUpgradeProposal("test legacy upgrade", "test legacy upgrade") - - msg, _ := govv1beta1.NewMsgSubmitProposal(legacyContent, sdk.NewCoins(), sdk.AccAddress{}) - return msg -} - -func newGovProp(msgs []sdk.Msg, expedite bool) *govv1.MsgSubmitProposal { - msg, _ := govv1.NewMsgSubmitProposal(msgs, sdk.NewCoins(), sdk.AccAddress{}.String(), "", "expedite", "expedite", expedite) - // fmt.Println("### msg ###", msg, "err", err) - return msg -} diff --git a/ante/gov_vote_ante.go b/ante/gov_vote_ante.go deleted file mode 100644 index 1efad4f1..00000000 --- a/ante/gov_vote_ante.go +++ /dev/null @@ -1,145 +0,0 @@ -package ante - -import ( - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - milkywayerrors "github.com/milkyway-labs/milkyway/v4/types/errors" -) - -var ( - minStakedTokens = math.LegacyNewDec(1000000) // 1_000_000 uatom (or 1 atom) - maxDelegationsChecked = 100 // number of delegation to check for the minStakedTokens -) - -// SetMinStakedTokens sets the minimum amount of staked tokens required to vote -// Should only be used in testing -func SetMinStakedTokens(tokens math.LegacyDec) { - minStakedTokens = tokens -} - -type GovVoteDecorator struct { - stakingKeeper *stakingkeeper.Keeper - cdc codec.BinaryCodec -} - -func NewGovVoteDecorator(cdc codec.BinaryCodec, stakingKeeper *stakingkeeper.Keeper) GovVoteDecorator { - return GovVoteDecorator{ - stakingKeeper: stakingKeeper, - cdc: cdc, - } -} - -func (g GovVoteDecorator) AnteHandle( - ctx sdk.Context, tx sdk.Tx, - simulate bool, next sdk.AnteHandler, -) (newCtx sdk.Context, err error) { - // do not run check during simulations - if simulate { - return next(ctx, tx, simulate) - } - - msgs := tx.GetMsgs() - if err = g.ValidateVoteMsgs(ctx, msgs); err != nil { - return ctx, err - } - - return next(ctx, tx, simulate) -} - -// ValidateVoteMsgs checks if a voter has enough stake to vote -func (g GovVoteDecorator) ValidateVoteMsgs(ctx sdk.Context, msgs []sdk.Msg) error { - validMsg := func(m sdk.Msg) error { - var accAddr sdk.AccAddress - var err error - - switch msg := m.(type) { - case *govv1beta1.MsgVote: - accAddr, err = sdk.AccAddressFromBech32(msg.Voter) - if err != nil { - return err - } - case *govv1.MsgVote: - accAddr, err = sdk.AccAddressFromBech32(msg.Voter) - if err != nil { - return err - } - default: - // not a vote message - nothing to validate - return nil - } - - if minStakedTokens.IsZero() { - return nil - } - - enoughStake := false - delegationCount := 0 - stakedTokens := math.LegacyNewDec(0) - err = g.stakingKeeper.IterateDelegatorDelegations(ctx, accAddr, func(delegation stakingtypes.Delegation) bool { - validatorAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) - if err != nil { - panic(err) // shouldn't happen - } - validator, err := g.stakingKeeper.GetValidator(ctx, validatorAddr) - if err == nil { - shares := delegation.Shares - tokens := validator.TokensFromSharesTruncated(shares) - stakedTokens = stakedTokens.Add(tokens) - if stakedTokens.GTE(minStakedTokens) { - enoughStake = true - return true // break the iteration - } - } - delegationCount++ - // break the iteration if maxDelegationsChecked were already checked - return delegationCount >= maxDelegationsChecked - }) - if err != nil { - return err - } - - if !enoughStake { - return errorsmod.Wrapf(milkywayerrors.ErrInsufficientStake, "insufficient stake for voting - min required %v", minStakedTokens) - } - - return nil - } - - validAuthz := func(execMsg *authz.MsgExec) error { - for _, v := range execMsg.Msgs { - var innerMsg sdk.Msg - if err := g.cdc.UnpackAny(v, &innerMsg); err != nil { - return errorsmod.Wrap(milkywayerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs") - } - if err := validMsg(innerMsg); err != nil { - return err - } - } - - return nil - } - - for _, m := range msgs { - if msg, ok := m.(*authz.MsgExec); ok { - if err := validAuthz(msg); err != nil { - return err - } - continue - } - - // validate normal msgs - if err := validMsg(m); err != nil { - return err - } - } - return nil -} diff --git a/ante/gov_vote_ante_test.go b/ante/gov_vote_ante_test.go deleted file mode 100644 index 8ddd959f..00000000 --- a/ante/gov_vote_ante_test.go +++ /dev/null @@ -1,273 +0,0 @@ -package ante_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - - "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/milkyway-labs/milkyway/v4/ante" - "github.com/milkyway-labs/milkyway/v4/app/helpers" -) - -// Test that the GovVoteDecorator rejects v1beta1 vote messages from accounts with less than 1 atom staked -// Submitting v1beta1.VoteMsg should not be possible through the CLI, but it's still possible to craft a transaction -func TestVoteSpamDecoratorGovV1Beta1(t *testing.T) { - milkyWayApp := helpers.Setup(t) - ctx := milkyWayApp.NewUncachedContext(true, tmproto.Header{}) - decorator := ante.NewGovVoteDecorator(milkyWayApp.AppCodec(), milkyWayApp.StakingKeeper) - stakingKeeper := milkyWayApp.StakingKeeper - - // Get validator - validators, err := stakingKeeper.GetAllValidators(ctx) - require.NoError(t, err) - valAddr1, err := stakingKeeper.ValidatorAddressCodec().StringToBytes(validators[0].GetOperator()) - require.NoError(t, err) - valAddr1 = sdk.ValAddress(valAddr1) - - // Create one more validator - pk := ed25519.GenPrivKeyFromSecret([]byte{uint8(13)}).PubKey() - validator2, err := stakingtypes.NewValidator( - sdk.ValAddress(pk.Address()).String(), - pk, - stakingtypes.Description{}, - ) - require.NoError(t, err) - valAddr2, err := stakingKeeper.ValidatorAddressCodec().StringToBytes(validator2.GetOperator()) - valAddr2 = sdk.ValAddress(valAddr2) - require.NoError(t, err) - // Make sure the validator is bonded so it's not removed on Undelegate - validator2.Status = stakingtypes.Bonded - err = stakingKeeper.SetValidator(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.SetValidatorByConsAddr(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.SetNewValidatorByPowerIndex(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.Hooks().AfterValidatorCreated(ctx, valAddr2) - require.NoError(t, err) - - // Get delegator (this account was created during setup) - addr, err := milkyWayApp.AccountKeeper.Accounts.Indexes.Number.MatchExact(ctx, 0) - require.NoError(t, err) - delegator, err := sdk.AccAddressFromBech32(addr.String()) - require.NoError(t, err) - - tests := []struct { - name string - bondAmt math.Int - validators []sdk.ValAddress - expectPass bool - }{ - { - name: "delegate 0 atom", - bondAmt: math.ZeroInt(), - validators: []sdk.ValAddress{valAddr1}, - expectPass: false, - }, - { - name: "delegate 0.1 atom", - bondAmt: math.NewInt(100000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: false, - }, - { - name: "delegate 1 atom", - bondAmt: math.NewInt(1000000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: true, - }, - { - name: "delegate 1 atom to two validators", - bondAmt: math.NewInt(1000000), - validators: []sdk.ValAddress{valAddr1, valAddr2}, - expectPass: true, - }, - { - name: "delegate 0.9 atom to two validators", - bondAmt: math.NewInt(900000), - validators: []sdk.ValAddress{valAddr1, valAddr2}, - expectPass: false, - }, - { - name: "delegate 10 atom", - bondAmt: math.NewInt(10000000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: true, - }, - } - - for _, tc := range tests { - // Unbond all tokens for this delegator - delegations, err := stakingKeeper.GetAllDelegatorDelegations(ctx, delegator) - require.NoError(t, err) - for _, del := range delegations { - valAddr, err := sdk.ValAddressFromBech32(del.GetValidatorAddr()) - require.NoError(t, err) - _, _, err = stakingKeeper.Undelegate(ctx, delegator, valAddr, del.GetShares()) - require.NoError(t, err) - } - - // Delegate tokens - if !tc.bondAmt.IsZero() { - amt := tc.bondAmt.Quo(math.NewInt(int64(len(tc.validators)))) - for _, valAddr := range tc.validators { - val, err := stakingKeeper.GetValidator(ctx, valAddr) - require.NoError(t, err) - _, err = stakingKeeper.Delegate(ctx, delegator, amt, stakingtypes.Unbonded, val, true) - require.NoError(t, err) - } - } - - // Create vote message - msg := govv1beta1.NewMsgVote( - delegator, - 0, - govv1beta1.OptionYes, - ) - - // Validate vote message - err = decorator.ValidateVoteMsgs(ctx, []sdk.Msg{msg}) - if tc.expectPass { - require.NoError(t, err, "expected %v to pass", tc.name) - } else { - require.Error(t, err, "expected %v to fail", tc.name) - } - } -} - -// Test that the GovVoteDecorator rejects v1 vote messages from accounts with less than 1 atom staked -// Usually, only v1.VoteMsg can be submitted using the CLI. -func TestVoteSpamDecoratorGovV1(t *testing.T) { - milkyWayApp := helpers.Setup(t) - ctx := milkyWayApp.NewUncachedContext(true, tmproto.Header{}) - decorator := ante.NewGovVoteDecorator(milkyWayApp.AppCodec(), milkyWayApp.StakingKeeper) - stakingKeeper := milkyWayApp.StakingKeeper - - // Get validator - validators, err := stakingKeeper.GetAllValidators(ctx) - require.NoError(t, err) - valAddr1, err := stakingKeeper.ValidatorAddressCodec().StringToBytes(validators[0].GetOperator()) - require.NoError(t, err) - valAddr1 = sdk.ValAddress(valAddr1) - - // Create one more validator - pk := ed25519.GenPrivKeyFromSecret([]byte{uint8(13)}).PubKey() - validator2, err := stakingtypes.NewValidator( - sdk.ValAddress(pk.Address()).String(), - pk, - stakingtypes.Description{}, - ) - require.NoError(t, err) - valAddr2, err := stakingKeeper.ValidatorAddressCodec().StringToBytes(validator2.GetOperator()) - require.NoError(t, err) - valAddr2 = sdk.ValAddress(valAddr2) - // Make sure the validator is bonded so it's not removed on Undelegate - validator2.Status = stakingtypes.Bonded - err = stakingKeeper.SetValidator(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.SetValidatorByConsAddr(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.SetNewValidatorByPowerIndex(ctx, validator2) - require.NoError(t, err) - err = stakingKeeper.Hooks().AfterValidatorCreated(ctx, valAddr2) - require.NoError(t, err) - - // Get delegator (this account was created during setup) - addr, err := milkyWayApp.AccountKeeper.Accounts.Indexes.Number.MatchExact(ctx, 0) - require.NoError(t, err) - delegator, err := sdk.AccAddressFromBech32(addr.String()) - require.NoError(t, err) - - tests := []struct { - name string - bondAmt math.Int - validators []sdk.ValAddress - expectPass bool - }{ - { - name: "delegate 0 atom", - bondAmt: math.ZeroInt(), - validators: []sdk.ValAddress{valAddr1}, - expectPass: false, - }, - { - name: "delegate 0.1 atom", - bondAmt: math.NewInt(100000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: false, - }, - { - name: "delegate 1 atom", - bondAmt: math.NewInt(1000000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: true, - }, - { - name: "delegate 1 atom to two validators", - bondAmt: math.NewInt(1000000), - validators: []sdk.ValAddress{valAddr1, valAddr2}, - expectPass: true, - }, - { - name: "delegate 0.9 atom to two validators", - bondAmt: math.NewInt(900000), - validators: []sdk.ValAddress{valAddr1, valAddr2}, - expectPass: false, - }, - { - name: "delegate 10 atom", - bondAmt: math.NewInt(10000000), - validators: []sdk.ValAddress{valAddr1}, - expectPass: true, - }, - } - - for _, tc := range tests { - // Unbond all tokens for this delegator - delegations, err := stakingKeeper.GetAllDelegatorDelegations(ctx, delegator) - require.NoError(t, err) - for _, del := range delegations { - valAddr, err := sdk.ValAddressFromBech32(del.GetValidatorAddr()) - require.NoError(t, err) - _, _, err = stakingKeeper.Undelegate(ctx, delegator, valAddr, del.GetShares()) - require.NoError(t, err) - } - - // Delegate tokens - if !tc.bondAmt.IsZero() { - amt := tc.bondAmt.Quo(math.NewInt(int64(len(tc.validators)))) - for _, valAddr := range tc.validators { - val, err := stakingKeeper.GetValidator(ctx, valAddr) - require.NoError(t, err) - _, err = stakingKeeper.Delegate(ctx, delegator, amt, stakingtypes.Unbonded, val, true) - require.NoError(t, err) - } - } - - // Create vote message - msg := govv1.NewMsgVote( - delegator, - 0, - govv1.VoteOption_VOTE_OPTION_YES, - "new-v1-vote-message-test", - ) - - // Validate vote message - err = decorator.ValidateVoteMsgs(ctx, []sdk.Msg{msg}) - if tc.expectPass { - require.NoError(t, err, "expected %v to pass", tc.name) - } else { - require.Error(t, err, "expected %v to fail", tc.name) - } - } -} diff --git a/app/app.go b/app/app.go index b798220e..45401ae6 100644 --- a/app/app.go +++ b/app/app.go @@ -295,7 +295,7 @@ func NewMilkyWayApp( SigGasConsumer: ante.DefaultSigVerificationGasConsumer, Codec: appCodec, - IBCkeeper: app.IBCKeeper, + IBCKeeper: app.IBCKeeper, StakingKeeper: app.StakingKeeper, FeeMarketKeeper: app.FeeMarketKeeper, WasmConfig: &wasmConfig, From 00d8c72e5b68082ab7bd1d1a5e0fa1032a7c1762 Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 18 Dec 2024 14:18:29 +0900 Subject: [PATCH 3/4] chore: add changeset entry --- ...393cb47e3affb7f9494b6a86876104e682650508e06ba486f15.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/entries/7387b176ec568393cb47e3affb7f9494b6a86876104e682650508e06ba486f15.yaml diff --git a/.changeset/entries/7387b176ec568393cb47e3affb7f9494b6a86876104e682650508e06ba486f15.yaml b/.changeset/entries/7387b176ec568393cb47e3affb7f9494b6a86876104e682650508e06ba486f15.yaml new file mode 100644 index 00000000..890ad5bb --- /dev/null +++ b/.changeset/entries/7387b176ec568393cb47e3affb7f9494b6a86876104e682650508e06ba486f15.yaml @@ -0,0 +1,6 @@ +type: feat +module: other +pull_request: 224 +description: Removed gov ante decorators to allow any proposal to be run as expedited +backward_compatible: false +date: 2024-12-18T05:18:18.516560841Z From efb26b1515e7e608fc2f221650d2565aa415924c Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 18 Dec 2024 14:29:14 +0900 Subject: [PATCH 4/4] fix(tests): fixed tests --- app/sim_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/sim_test.go b/app/sim_test.go index ace81f85..06905cba 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -14,7 +14,6 @@ import ( dbm "github.com/cosmos/cosmos-db" "cosmossdk.io/log" - "cosmossdk.io/math" "cosmossdk.io/store" "github.com/cosmos/cosmos-sdk/baseapp" @@ -106,14 +105,6 @@ func TestAppStateDeterminism(t *testing.T) { baseapp.SetChainID(AppChainID), ) - // NOTE: setting to zero to avoid failing the simulation - // due to the minimum staked tokens required to submit a vote - ante.SetMinStakedTokens(math.LegacyZeroDec()) - - // NOTE: setting to zero to avoid failing the simulation - // milkyway ante allows only certain proposals to be expedited - the simulation doesn't know about this - ante.SetExpeditedProposalsEnabled(false) - fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,