Skip to content

Commit

Permalink
deps!: bring cosmos-sdk v50 deps to gaia (#3171)
Browse files Browse the repository at this point in the history
* upgrade gaia to v50 cosmos-sdk

* minor fix

* autocli fix, remove old and add new(init) upgrade file

* fix autocli errors(update client dep)

* sw upgrade tests fixed (without doc update)

* keep ModuleBasics.AddTxCommands call for legacy proposal cmds

* move ModulBasics in app, register codecs and interfaces in app

* Revert "move ModulBasics in app, register codecs and interfaces in app"

This reverts commit 89f22e3.

* fix provider param change test

* fix ica-register and rest interfaces tests

* update test provider param change

* lint fix part 1

* ics version update

* MsgSoftwareUpgrade proposal doc and script update

* lint fix

* remove dummy vote extension impl

* additional minor fixes

* libwasmvm version update

* integration tests fix

* unsafe-start-local-validator fix

* lint fix

* add tendermint module

* ibc fee test fix

* fix liveness test

* register ibc app param keytables

* build: update cosmos-sdk-lsm version; update ics to release/v5.1.x

* account for ics v5.1.x details

---------

Co-authored-by: MSalopek <[email protected]>
  • Loading branch information
stana-miric and MSalopek authored Jul 18, 2024
1 parent 8a9bbf7 commit b06e7ea
Show file tree
Hide file tree
Showing 80 changed files with 1,264 additions and 3,252 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ format:
start-localnet-ci: build
rm -rf ~/.gaiad-liveness
./build/gaiad init liveness --chain-id liveness --home ~/.gaiad-liveness
./build/gaiad config chain-id liveness --home ~/.gaiad-liveness
./build/gaiad config keyring-backend test --home ~/.gaiad-liveness
./build/gaiad keys add val --home ~/.gaiad-liveness
./build/gaiad config set client chain-id liveness --home ~/.gaiad-liveness
./build/gaiad config set client keyring-backend test --home ~/.gaiad-liveness
./build/gaiad keys add val --home ~/.gaiad-liveness --keyring-backend test
./build/gaiad genesis add-genesis-account val 10000000000000000000000000stake --home ~/.gaiad-liveness --keyring-backend test
./build/gaiad genesis gentx val 1000000000stake --home ~/.gaiad-liveness --chain-id liveness
./build/gaiad genesis gentx val 1000000000stake --home ~/.gaiad-liveness --chain-id liveness --keyring-backend test
./build/gaiad genesis collect-gentxs --home ~/.gaiad-liveness
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatom"/' ~/.gaiad-liveness/config/app.toml
./build/gaiad start --home ~/.gaiad-liveness --x-crisis-skip-assert-invariants
Expand Down
22 changes: 11 additions & 11 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"

ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

corestoretypes "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand All @@ -28,13 +28,13 @@ var UseFeeMarketDecorator = true
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
TxFeeChecker ante.TxFeeChecker
TxCounterStoreKey storetypes.StoreKey
WasmConfig *wasmtypes.WasmConfig
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
TxFeeChecker ante.TxFeeChecker
TXCounterStoreService corestoretypes.KVStoreService
WasmConfig *wasmtypes.WasmConfig
}

func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
Expand Down Expand Up @@ -66,7 +66,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(opts.TxCounterStoreKey),
wasmkeeper.NewCountTXDecorator(opts.TXCounterStoreService),
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down
3 changes: 0 additions & 3 deletions ante/gov_expedited_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func SetExpeditedProposalsEnabled(val bool) {
var expeditedPropsWhitelist = map[string]struct{}{
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {},
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {},
// legacy proposals can still be submitted using govv1.MsgSubmitProposal
"/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal": {},
"/cosmos.upgrade.v1beta1.CancelSoftwareUpgradeProposal": {},
}

// Check if the proposal is whitelisted for expedited voting.
Expand Down
66 changes: 7 additions & 59 deletions ante/gov_expedited_ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (

"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"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/gaia/v19/ante"
"github.com/cosmos/gaia/v19/app/helpers"
Expand Down Expand Up @@ -41,14 +43,6 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
},
expectErr: false,
},
{
name: "expedited - govv1.MsgSubmitProposal - LegacySoftwareUpgrade",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newLegacyUpgradeProp(true), // expedite
},
expectErr: false,
},
{
name: "expedited - govv1.MsgSubmitProposal - MsgCancelUpgrade",
ctx: sdk.Context{},
Expand All @@ -59,30 +53,6 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
},
expectErr: false,
},
{
name: "expedited - govv1.MsgSubmitProposal - LegacyCancelUpgrade",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newLegacyCancelProp(true), // expedite
},
expectErr: false,
},
{
name: "normal - govv1.MsgSubmitProposal - LegacySoftwareUpgrade",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newLegacyUpgradeProp(false), // normal
},
expectErr: false,
},
{
name: "normal - govv1.MsgSubmitProposal - LegacyCancelUpgrade",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newLegacyCancelProp(false), // normal
},
expectErr: false,
},
{
name: "normal - govv1.MsgSubmitProposal - TextProposal",
ctx: sdk.Context{},
Expand All @@ -98,7 +68,7 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
newGovProp([]sdk.Msg{&distrtypes.MsgCommunityPoolSpend{
Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Recipient: sdk.AccAddress{}.String(),
Amount: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))),
}}, false), // normal
},
expectErr: false,
Expand All @@ -110,7 +80,7 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
newGovProp([]sdk.Msg{&banktypes.MsgSend{
FromAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
ToAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Amount: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))),
}}, false), // normal
},
expectErr: false,
Expand Down Expand Up @@ -164,7 +134,7 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
newGovProp([]sdk.Msg{&distrtypes.MsgCommunityPoolSpend{
Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Recipient: sdk.AccAddress{}.String(),
Amount: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))),
}}, true),
},
expectErr: true,
Expand All @@ -176,7 +146,7 @@ func TestGovExpeditedProposalsDecorator(t *testing.T) {
newGovProp([]sdk.Msg{&banktypes.MsgSend{
FromAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
ToAddress: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Amount: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))),
}}, true),
},
expectErr: true,
Expand Down Expand Up @@ -223,19 +193,6 @@ func newLegacyTextProp(expedite bool) *govv1.MsgSubmitProposal {
return newGovProp([]sdk.Msg{msgContent}, expedite)
}

func newLegacyUpgradeProp(expedite bool) *govv1.MsgSubmitProposal {
prop := upgradetypes.NewSoftwareUpgradeProposal("test legacy upgrade", "test legacy upgrade", upgradetypes.Plan{
Name: "upgrade plan-plan",
Info: "some text here",
Height: 123456789,
})
msgContent, err := govv1.NewLegacyContent(prop, "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",
Expand All @@ -254,15 +211,6 @@ func newGovV1BETA1LegacyCancelUpgradeProp() *govv1beta1.MsgSubmitProposal {
return msg
}

func newLegacyCancelProp(expedite bool) *govv1.MsgSubmitProposal {
prop := upgradetypes.NewCancelSoftwareUpgradeProposal("test legacy upgrade", "test legacy upgrade")
msgContent, err := govv1.NewLegacyContent(prop, "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn")
if err != nil {
return nil
}
return newGovProp([]sdk.Msg{msgContent}, expedite)
}

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)
Expand Down
19 changes: 12 additions & 7 deletions ante/gov_vote_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -15,13 +16,13 @@ import (
)

var (
minStakedTokens = sdk.NewDec(1000000) // 1_000_000 uatom (or 1 atom)
maxDelegationsChecked = 100 // number of delegation to check for the minStakedTokens
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 sdk.Dec) {
func SetMinStakedTokens(tokens math.LegacyDec) {
minStakedTokens = tokens
}

Expand Down Expand Up @@ -82,14 +83,14 @@ func (g GovVoteDecorator) ValidateVoteMsgs(ctx sdk.Context, msgs []sdk.Msg) erro

enoughStake := false
delegationCount := 0
stakedTokens := sdk.NewDec(0)
g.stakingKeeper.IterateDelegatorDelegations(ctx, accAddr, func(delegation stakingtypes.Delegation) bool {
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, found := g.stakingKeeper.GetValidator(ctx, validatorAddr)
if found {
validator, err := g.stakingKeeper.GetValidator(ctx, validatorAddr)
if err == nil {
shares := delegation.Shares
tokens := validator.TokensFromSharesTruncated(shares)
stakedTokens = stakedTokens.Add(tokens)
Expand All @@ -103,6 +104,10 @@ func (g GovVoteDecorator) ValidateVoteMsgs(ctx sdk.Context, msgs []sdk.Msg) erro
return delegationCount >= maxDelegationsChecked
})

if err != nil {
return err
}

if !enoughStake {
return errorsmod.Wrapf(gaiaerrors.ErrInsufficientStake, "insufficient stake for voting - min required %v", minStakedTokens)
}
Expand Down
Loading

0 comments on commit b06e7ea

Please sign in to comment.