Skip to content

Commit

Permalink
spike to test feasibility of downgrade to v0.45 (#1902)
Browse files Browse the repository at this point in the history
* pause

* no vscode errors

* rewrite go.sum, go.work.sum and fix amino import

* remove mauth docs

* gofumpt

* fix find

* cant get docker to build locally

* debug ibc test

* fix ibc test

* passing e2e

* clean up commented out tests

* remove more mauth

* forgot to save

* add back middleware test

* fix upgrade

* fix test setup

* add TODO note

* remove multihop test

* Update docs/modules/gov.md

* Update tests/e2e/query.go

Co-authored-by: lg <8335464+glnro@users.noreply.github.com>

* remove groups and gov docs

* laurens comment re moduleAccountAddress

* remove commented code that should not be added back

Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
  • Loading branch information
okwme and glnro authored Nov 30, 2022
1 parent 6a0e221 commit 6742b71
Show file tree
Hide file tree
Showing 80 changed files with 773 additions and 6,151 deletions.
12 changes: 6 additions & 6 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibcante "github.com/cosmos/ibc-go/v5/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

gaiafeeante "github.com/cosmos/gaia/v8/x/globalfee/ante"
)
Expand Down Expand Up @@ -48,21 +47,22 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
// ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
gaiafeeante.NewFeeDecorator(opts.BypassMinFeeMsgTypes, opts.GlobalFeeSubspace, opts.StakingSubspace),
// if opts.TxFeeCheck is nil, it is the default fee check
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper),
// ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
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),
// todo check
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
// TODO: check what this is
// ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
44 changes: 18 additions & 26 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand All @@ -27,8 +26,8 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -44,7 +43,6 @@ import (
"github.com/cosmos/gaia/v8/app/upgrades"
v8 "github.com/cosmos/gaia/v8/app/upgrades/v8"
"github.com/cosmos/gaia/v8/x/globalfee"
gaiafeeante "github.com/cosmos/gaia/v8/x/globalfee/ante"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand Down Expand Up @@ -123,13 +121,17 @@ func NewGaiaApp(
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
}

moduleAccountAddresses := app.ModuleAccountAddrs()

// Setup keepers
app.AppKeepers = keepers.NewAppKeeper(
appCodec,
bApp,
legacyAmino,
maccPerms,
app.BlockedModuleAccountAddrs(),
moduleAccountAddresses,
app.BlockedModuleAccountAddrs(moduleAccountAddresses),
skipUpgradeHeights,
homePath,
invCheckPeriod,
Expand Down Expand Up @@ -196,17 +198,17 @@ func NewGaiaApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
// TxFeeChecker is not the default fee check, it will not check if the fee meets min_gas_price, this is checked in NewFeeWithBypassDecorator already.
TxFeeChecker: func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, 0, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
// TxFeeChecker: func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
// feeTx, ok := tx.(sdk.FeeTx)
// if !ok {
// return nil, 0, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
// }

feeCoins := feeTx.GetFee()
priority := gaiafeeante.GetTxPriority(feeCoins)
// feeCoins := feeTx.GetFee()
// priority := gaiafeeante.GetTxPriority(feeCoins)

return feeCoins, priority, nil
},
// return feeCoins, priority, nil
// },
},
IBCkeeper: app.IBCKeeper,
BypassMinFeeMsgTypes: bypassMinFeeMsgTypes,
Expand Down Expand Up @@ -285,13 +287,8 @@ func (app *GaiaApp) ModuleAccountAddrs() map[string]bool {

// BlockedModuleAccountAddrs returns all the app's blocked module account
// addresses.
func (app *GaiaApp) BlockedModuleAccountAddrs() map[string]bool {
modAccAddrs := app.ModuleAccountAddrs()

func (app *GaiaApp) BlockedModuleAccountAddrs(modAccAddrs map[string]bool) map[string]bool {
// remove module accounts that are ALLOWED to received funds
//
// TODO: Blocked on updating to v0.46.x
// delete(modAccAddrs, authtypes.NewModuleAddress(grouptypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

return modAccAddrs
Expand Down Expand Up @@ -348,12 +345,7 @@ func (app *GaiaApp) RegisterTxService(clientCtx client.Context) {

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *GaiaApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
app.Query,
)
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
Expand Down
15 changes: 8 additions & 7 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
db "github.com/tendermint/tm-db"

gaia "github.com/cosmos/gaia/v8/app"
gaiahelpers "github.com/cosmos/gaia/v8/app/helpers"
)

type EmptyAppOptions struct{}
Expand All @@ -31,14 +30,16 @@ func TestGaiaApp_BlockedModuleAccountAddrs(t *testing.T) {
gaia.MakeTestEncodingConfig(),
EmptyAppOptions{},
)
blockedAddrs := app.BlockedModuleAccountAddrs()
moduleAccountAddresses := app.ModuleAccountAddrs()
blockedAddrs := app.BlockedModuleAccountAddrs(moduleAccountAddresses)

require.NotContains(t, blockedAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
}

func TestGaiaApp_Export(t *testing.T) {
app := gaiahelpers.Setup(t)
// TODO: add back
// func TestGaiaApp_Export(t *testing.T) {
// app := gaiahelpers.Setup(t)

_, err := app.ExportAppStateAndValidators(true, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
// _, err := app.ExportAppStateAndValidators(true, []string{})
// require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
// }
31 changes: 18 additions & 13 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators (v0.46 version)
// app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// // donate any unwithdrawn outstanding reward fraction tokens to the community pool
// scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
// feePool := app.DistrKeeper.GetFeePool(ctx)
// feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
// app.DistrKeeper.SetFeePool(ctx, feePool)

// err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
// if err != nil {
// panic(err)
// }
// return false
// })

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
Expand All @@ -114,10 +129,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
if err != nil {
panic(err)
}
app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false
})

Expand All @@ -131,15 +143,8 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
if err != nil {
panic(err)
}
err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
if err != nil {
panic(err)
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
if err != nil {
panic(err)
}

app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
}

// reset context height
Expand Down
75 changes: 57 additions & 18 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"testing"
"time"

"cosmossdk.io/math"
"github.com/tendermint/tendermint/crypto"
// "github.com/tendermint/tendermint/crypto/secp256k1"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -48,28 +50,65 @@ var DefaultConsensusParams = &abci.ConsensusParams{
},
}

type PV struct {
PrivKey cryptotypes.PrivKey
}

func NewPV() PV {
return PV{ed25519.GenPrivKey()}
}

// GetPubKey implements PrivValidator interface
func (pv PV) GetPubKey() (crypto.PubKey, error) {
return cryptocodec.ToTmPubKeyInterface(pv.PrivKey.PubKey())
}

type EmptyAppOptions struct{}

func (EmptyAppOptions) Get(o string) interface{} { return nil }

func Setup(t *testing.T) *gaiaapp.GaiaApp {
func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *gaiaapp.GaiaApp {
t.Helper()

privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)
// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100000000000000))),
// TODO: investigate the following:
// The following has been modified to work with v0.45 but it's incomplete somehow. It causes tests to break because the changes
// are not properly integrated into the v0.45 test suite. It deserves a closer look to determine why adding custom validator and
// populated accounts was an improvement and whether it's important to add them back to this versin of the test suite.

// privVal := NewPV()
// pubKey, err := privVal.GetPubKey()
// require.NoError(t, err)
// // create validator set with single validator
// validator := tmtypes.NewValidator(pubKey, 1)
// valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// // generate genesis account
// senderPrivKey := secp256k1.GenPrivKey()
// senderPubKey := senderPrivKey.PubKey()

// acc := authtypes.NewBaseAccount(senderPubKey.Address().Bytes(), senderPubKey, 0, 0)
// balance := banktypes.Balance{
// Address: acc.GetAddress().String(),
// Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
// }
// genesisState := []authtypes.GenesisAccount{acc}
// app := SetupWithGenesisValSet(t, valSet, genesisState, balance)

app, genesisState := setup(!isCheckTx, invCheckPeriod)
if !isCheckTx {
// InitChain must be called to stop deliverState from being nil
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
}
app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)

return app
}
Expand Down
Loading

0 comments on commit 6742b71

Please sign in to comment.