Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike to test feasibility of downgrade to v0.45 #1902

Merged
merged 31 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
663e14f
pause
okwme Nov 15, 2022
64cc456
no vscode errors
okwme Nov 16, 2022
0fe4e8c
Merge branch 'main' into okwme/downgrade-v0-45
okwme Nov 16, 2022
fc8f2be
rewrite go.sum, go.work.sum and fix amino import
okwme Nov 16, 2022
fca3ab5
Merge branch 'main' into okwme/downgrade-v0-45
okwme Nov 16, 2022
5e7bd79
remove mauth docs
okwme Nov 16, 2022
d7e19d0
gofumpt
okwme Nov 16, 2022
180ca63
fix find
okwme Nov 16, 2022
75d0f9a
cant get docker to build locally
okwme Nov 16, 2022
824c208
debug ibc test
okwme Nov 16, 2022
5169a9b
fix ibc test
okwme Nov 16, 2022
43f495b
merge with main
okwme Nov 17, 2022
e7f9145
passing e2e
okwme Nov 17, 2022
02b3256
clean up commented out tests
okwme Nov 17, 2022
a266175
remove more mauth
okwme Nov 17, 2022
283ab55
forgot to save
okwme Nov 17, 2022
8435cc4
merge with main
okwme Nov 17, 2022
61743e1
Merge branch 'main' into okwme/downgrade-v0-45
okwme Nov 17, 2022
e55d9b2
merge with main
okwme Nov 17, 2022
3601da2
add back middleware test
okwme Nov 18, 2022
8f846a8
Merge branch 'main' into okwme/downgrade-v0-45
okwme Nov 18, 2022
18ccf80
fix upgrade
okwme Nov 18, 2022
785b267
fix test setup
okwme Nov 18, 2022
ed9c986
add TODO note
okwme Nov 18, 2022
0673b1b
remove multihop test
okwme Nov 18, 2022
1ed082c
Update docs/modules/gov.md
okwme Nov 30, 2022
ced396b
Update tests/e2e/query.go
okwme Nov 30, 2022
fd56668
remove groups and gov docs
okwme Nov 30, 2022
29fd7f0
Merge branch 'main' into okwme/downgrade-v0-45
okwme Nov 30, 2022
6b6583a
laurens comment re moduleAccountAddress
okwme Nov 30, 2022
63f45f9
remove commented code that should not be added back
okwme Nov 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
okwme marked this conversation as resolved.
Show resolved Hide resolved
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) {
glnro marked this conversation as resolved.
Show resolved Hide resolved
// 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