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

chore: remove simapp imports #83

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
with:
PATTERNS: |
**/**.py
go.mod
go.sum
gomod2nix.toml
- name: run gomod2nix
run: |
nix run -f ./nix gomod2nix
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
go.mod
go.sum
tests/integration_tests/**
*.nix
- name: Run integration tests
run: make run-integration-tests
if: env.GIT_DIFF
Expand Down
3 changes: 1 addition & 2 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (suite *AnteTestSuite) SetupTest() {
suite.Require().NoError(err)
suite.priv = priv

suite.app = app.Setup(checkTx, func(app *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState {
suite.app = app.Setup(checkTx, func(app *app.EthermintApp, genesis app.GenesisState) app.GenesisState {
if suite.enableFeemarket {
// setup feemarketGenesis params
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand Down
46 changes: 36 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -123,8 +123,10 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

"github.com/cosmos/cosmos-sdk/server"
// unnamed import of statik for swagger UI support
_ "github.com/evmos/ethermint/client/docs/statik"
"github.com/evmos/ethermint/encoding"

"github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/ethereum/eip712"
Expand All @@ -140,7 +142,6 @@ import (
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"

simappparams "cosmossdk.io/simapp/params"
// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Expand Down Expand Up @@ -225,6 +226,7 @@ type EthermintApp struct {
// encoding
cdc *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
Expand Down Expand Up @@ -282,15 +284,13 @@ func NewEthermintApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *EthermintApp {
encodingConfig := encoding.MakeConfig(ModuleBasics)
appCodec := encodingConfig.Codec
cdc := encodingConfig.Amino
txConfig := encodingConfig.TxConfig
interfaceRegistry := encodingConfig.InterfaceRegistry

eip712.SetEncodingConfig(encodingConfig)
Expand All @@ -308,12 +308,13 @@ func NewEthermintApp(
appName,
logger,
db,
encodingConfig.TxConfig.TxDecoder(),
txConfig.TxDecoder(),
baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(txConfig.TxEncoder())

keys := sdk.NewKVStoreKeys(
// SDK keys
Expand All @@ -338,9 +339,11 @@ func NewEthermintApp(
os.Exit(1)
}

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change related to simapp import? should we change something in configuration to read this instead of hardcoding to 5 as it was before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specifically, but it was part of the same change from crypto-org-chain/ethermint

app := &EthermintApp{
BaseApp: bApp,
cdc: cdc,
txConfig: txConfig,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
Expand Down Expand Up @@ -428,6 +431,16 @@ func NewEthermintApp(
keys[feegrant.StoreKey],
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
}
homePath := cast.ToString(appOpts.Get(flags.FlagHome))
if homePath == "" {
homePath = DefaultNodeHome
}

// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = *upgradekeeper.NewKeeper(
skipUpgradeHeights,
Expand Down Expand Up @@ -543,7 +556,7 @@ func NewEthermintApp(
// SDK app modules
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
txConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -711,7 +724,7 @@ func NewEthermintApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(encodingConfig.TxConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))
app.setAnteHandler(txConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))
// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down Expand Up @@ -791,7 +804,7 @@ func (app *EthermintApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) a

// InitChainer updates at chain initialization
func (app *EthermintApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState simapp.GenesisState
var genesisState GenesisState
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
Expand Down Expand Up @@ -846,6 +859,19 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

func (app *EthermintApp) TxConfig() client.TxConfig {
return app.txConfig
}

func (app *EthermintApp) EncodingConfig() ethermint.EncodingConfig {
return ethermint.EncodingConfig{
InterfaceRegistry: app.InterfaceRegistry(),
Codec: app.AppCodec(),
TxConfig: app.TxConfig(),
Amino: app.LegacyAmino(),
}
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
5 changes: 0 additions & 5 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/evmos/ethermint/encoding"
)

func TestEthermintAppExport(t *testing.T) {
Expand All @@ -25,10 +24,6 @@ func TestEthermintAppExport(t *testing.T) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
9 changes: 0 additions & 9 deletions app/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/evmos/ethermint/encoding"
)

func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
Expand All @@ -20,10 +19,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down Expand Up @@ -53,10 +48,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
3 changes: 1 addition & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"cosmossdk.io/simapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -33,7 +32,7 @@ import (
)

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() simapp.GenesisState {
func NewDefaultGenesisState() GenesisState {
encCfg := encoding.MakeConfig(ModuleBasics)
return ModuleBasics.DefaultGenesis(encCfg.Codec)
}
Expand Down
19 changes: 7 additions & 12 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"time"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -30,8 +29,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/evmos/ethermint/encoding"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand All @@ -41,6 +38,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

type GenesisState map[string]json.RawMessage

// DefaultConsensusParams defines the default Tendermint consensus params used in
// EthermintApp testing.
var DefaultConsensusParams = &tmproto.ConsensusParams{
Expand All @@ -61,22 +60,18 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
}

// Setup initializes a new EthermintApp. A Nop logger is set in EthermintApp.
func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState) simapp.GenesisState) *EthermintApp {
func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, GenesisState) GenesisState) *EthermintApp {
return SetupWithDB(isCheckTx, patchGenesis, dbm.NewMemDB())
}

const ChainID = "ethermint_9000-1"

// SetupWithDB initializes a new EthermintApp. A Nop logger is set in EthermintApp.
func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState) simapp.GenesisState, db dbm.DB) *EthermintApp {
func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, GenesisState) GenesisState, db dbm.DB) *EthermintApp {
app := NewEthermintApp(log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
5,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down Expand Up @@ -108,7 +103,7 @@ func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.Genesis
}

// NewTestGenesisState generate genesis state with single validator
func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
func NewTestGenesisState(codec codec.Codec) GenesisState {
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
if err != nil {
Expand All @@ -130,10 +125,10 @@ func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
return genesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
}

func genesisStateWithValSet(codec codec.Codec, genesisState simapp.GenesisState,
func genesisStateWithValSet(codec codec.Codec, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) simapp.GenesisState {
) GenesisState {
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = codec.MustMarshalJSON(authGenesis)
Expand Down
14 changes: 5 additions & 9 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
tmcli "github.com/cometbft/cometbft/libs/cli"
tmlog "github.com/cometbft/cometbft/libs/log"

"cosmossdk.io/simapp/params"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down Expand Up @@ -66,7 +65,7 @@ const EnvPrefix = "ETHERMINT"

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand Down Expand Up @@ -210,7 +209,7 @@ func txCommand() *cobra.Command {
}

type appCreator struct {
encCfg params.EncodingConfig
encCfg ethermint.EncodingConfig
}

// newApp is an appCreator
Expand Down Expand Up @@ -267,10 +266,7 @@ func (a appCreator) newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer,
chainID = conf.ChainID
}
ethermintApp := app.NewEthermintApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)),
a.encCfg,
logger, db, traceStore, true,
appOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))),
Expand Down Expand Up @@ -308,13 +304,13 @@ func (a appCreator) appExport(
}

if height != -1 {
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, 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), a.encCfg, appOpts, baseapp.SetChainID(app.ChainID))
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, appOpts, baseapp.SetChainID(app.ChainID))
}

return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in
buildGoApplication rec {
inherit pname version tags ldflags;
src = lib.sourceByRegex ./. [
"^(x|app|cmd|client|server|crypto|rpc|types|encoding|ethereum|indexer|testutil|version|go.mod|go.sum|gomod2nix.toml)($|/.*)"
"^(x|app|cmd|client|server|crypto|rpc|types|encoding|ethereum|indexer|testutil|version|go.mod|go.sum|gomod2nix.toml|store)($|/.*)"
"^tests(/.*[.]go)?$"
];
modules = ./gomod2nix.toml;
Expand Down
Loading
Loading