Skip to content

Commit

Permalink
cleanup app
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Feb 27, 2024
1 parent 72aec6a commit c9a2f9f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 49 deletions.
43 changes: 28 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server"

"github.com/gorilla/mux"
"github.com/spf13/cast"
Expand Down Expand Up @@ -241,8 +242,6 @@ func NewEthermintApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
invCheckPeriod uint,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *EthermintApp {
Expand Down Expand Up @@ -302,6 +301,7 @@ func NewEthermintApp(
os.Exit(1)
}

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app := &EthermintApp{
BaseApp: bApp,
cdc: legacyAmino,
Expand Down Expand Up @@ -343,7 +343,8 @@ func NewEthermintApp(
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix()
// use custom Ethermint account for contracts
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]),
appCodec,
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
ethermint.ProtoAccount,
maccPerms,
address.NewBech32Codec(bech32PrefixAccAddr),
Expand Down Expand Up @@ -404,8 +405,14 @@ func NewEthermintApp(
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[feegrant.StoreKey]),
app.AccountKeeper)
app.AccountKeeper,
)

// get skipUpgradeHeights from the app options
skipUpgradeHeights := map[int64]bool{}
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = *upgradekeeper.NewKeeper(
skipUpgradeHeights,
Expand All @@ -417,17 +424,28 @@ func NewEthermintApp(
)

// register the staking hooks
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks()),
)
app.StakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
))

app.AuthzKeeper = authzkeeper.NewKeeper(
runtime.NewKVStoreService(keys[authzkeeper.StoreKey]),
appCodec,
app.MsgServiceRouter(),
app.AccountKeeper)

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authAddr,
)

tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))

// Create Ethermint keepers
Expand All @@ -450,19 +468,14 @@ func NewEthermintApp(
allKeys[k] = v
}
app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
appCodec,
keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
tracer,
evmSs, nil,
allKeys,
)

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authAddr,
)

// register the proposal types
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
Expand Down
2 changes: 0 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func TestEthermintAppExport(t *testing.T) {
db,
nil,
true,
map[int64]bool{},
0,
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
4 changes: 0 additions & 4 deletions app/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
0,
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down Expand Up @@ -50,8 +48,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
0,
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd
// withdraw all delegator rewards
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
return err
}
for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
Expand Down
5 changes: 4 additions & 1 deletion app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/server"

simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"

Expand Down Expand Up @@ -71,7 +72,9 @@ func (ao EmptyAppOptions) Get(o string) interface{} {

// NewSimApp disable feemarket on native tx, otherwise the cosmos-sdk simulation tests will fail.
func NewSimApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*baseapp.BaseApp)) (*EthermintApp, error) {
app := NewEthermintApp(logger, db, nil, false, map[int64]bool{}, simcli.FlagPeriodValue, EmptyAppOptions{}, baseAppOptions...)
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
app := NewEthermintApp(logger, db, nil, false, appOptions, baseAppOptions...)
// disable feemarket on native tx
anteHandler, err := ante.NewAnteHandler(ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand Down
5 changes: 3 additions & 2 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
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/server"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -79,12 +80,12 @@ const ChainID = "ethermint_9000-1"

// SetupWithDB initializes a new EthermintApp. A Nop logger is set in EthermintApp.
func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, GenesisState) GenesisState, db dbm.DB) *EthermintApp {
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = 5
app := NewEthermintApp(log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
5,
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
16 changes: 5 additions & 11 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"os"

"github.com/spf13/cast"
"github.com/spf13/cobra"

cmtlog "cosmossdk.io/log"
Expand Down Expand Up @@ -82,8 +81,8 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
tempApp := app.NewEthermintApp(
cmtlog.NewNopLogger(),
dbm.NewMemDB(),
nil, true, nil,
0,
nil,
true,
EmptyAppOptions{},
)
encodingConfig := tempApp.EncodingConfig()
Expand Down Expand Up @@ -263,14 +262,9 @@ type appCreator struct {

// newApp is an appCreator
func (a appCreator) newApp(logger cmtlog.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
skipUpgradeHeights := make(map[int64]bool)
for _, h := range cast.ToIntSlice(appOpts.Get(sdkserver.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
baseappOptions := sdkserver.DefaultBaseappOptions(appOpts)
ethermintApp := app.NewEthermintApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)),
logger, db, traceStore, true,
appOpts,
baseappOptions...,
)
Expand All @@ -296,12 +290,12 @@ func (a appCreator) appExport(
}

if height != -1 {
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, uint(1), appOpts, baseapp.SetChainID(app.ChainID))
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, appOpts, baseapp.SetChainID(app.ChainID))
if err := ethermintApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, uint(1), appOpts, baseapp.SetChainID(app.ChainID))
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, appOpts, baseapp.SetChainID(app.ChainID))
}

return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down
17 changes: 9 additions & 8 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/version"

tcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
tmlog "cosmossdk.io/log"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
)

// AddCommands adds server commands
Expand All @@ -45,18 +45,19 @@ func AddCommands(
appExport types.AppExporter,
addStartFlags types.ModuleInitFlags,
) {
tendermintCmd := &cobra.Command{
Use: "tendermint",
Short: "Tendermint subcommands",
cometCmd := &cobra.Command{
Use: "comet",
Aliases: []string{"cometbft", "tendermint"},
Short: "CometBFT subcommands",
}

tendermintCmd.AddCommand(
cometCmd.AddCommand(
sdkserver.ShowNodeIDCmd(),
sdkserver.ShowValidatorCmd(),
sdkserver.ShowAddressCmd(),
sdkserver.VersionCmd(),
tcmd.ResetAllCmd,
tcmd.ResetStateCmd,
cmtcmd.ResetAllCmd,
cmtcmd.ResetStateCmd,
sdkserver.BootstrapStateCmd(opts.AppCreator),
)

Expand All @@ -65,7 +66,7 @@ func AddCommands(

rootCmd.AddCommand(
startCmd,
tendermintCmd,
cometCmd,
sdkserver.ExportCmd(appExport, opts.DefaultNodeHome),
version.NewVersionCommand(),
sdkserver.NewRollbackCmd(opts.AppCreator, opts.DefaultNodeHome),
Expand Down
2 changes: 0 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func NewAppConstructor(encodingCfg ethermint.EncodingConfig, chainID string) App
dbm.NewMemDB(),
nil,
true,
make(map[int64]bool),
0,
simtestutil.NewAppOptionsWithFlagHome(val.Ctx.Config.RootDir),
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
Expand Down
9 changes: 6 additions & 3 deletions x/feemarket/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
. "github.com/onsi/gomega"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand Down Expand Up @@ -484,14 +486,15 @@ func setupChain(localMinGasPricesStr string) {
// Initialize the app, so we can use SetMinGasPrices to set the
// validator-specific min-gas-prices setting
db := dbm.NewMemDB()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = 5
appOptions[flags.FlagHome] = app.DefaultNodeHome
newapp := app.NewEthermintApp(
log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
5,
simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome),
appOptions,
baseapp.SetMinGasPrices(localMinGasPricesStr),
baseapp.SetChainID(app.ChainID),
)
Expand Down

0 comments on commit c9a2f9f

Please sign in to comment.