Skip to content

Commit

Permalink
adjust use of baseapp by adding Tx decoder and adjust root cmd to use…
Browse files Browse the repository at this point in the history
… correct mempool and baseapp options
  • Loading branch information
MalteHerrmann committed Aug 12, 2024
1 parent 3cad940 commit ea877ce
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
27 changes: 27 additions & 0 deletions cmd/config/chain_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package config

import (
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/spf13/viper"
"path/filepath"
)

// GetChainIDFromHome returns the chain ID from the client configuration
// in the given home directory.
func GetChainIDFromHome(home string) (string, error) {
v := viper.New()
v.AddConfigPath(filepath.Join(home, "config"))
v.SetConfigName("client")
v.SetConfigType("toml")

if err := v.ReadInConfig(); err != nil {
return "", err
}
conf := new(config.ClientConfig)

if err := v.Unmarshal(conf); err != nil {
return "", err
}

return conf.ChainID, nil
}
9 changes: 8 additions & 1 deletion example_chain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,14 @@ func NewExampleApp(
// }
// baseAppOptions = append(baseAppOptions, prepareOpt)

bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp := baseapp.NewBaseApp(
appName,
logger,
db,
// use transaction decoder to support the sdk.Tx interface instead of sdk.StdTx
encodingConfig.TxConfig.TxDecoder(),
baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down
4 changes: 3 additions & 1 deletion example_chain/local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,6 @@ fi
osd start \
--log_level $LOGLEVEL \
--minimum-gas-prices=0.0001aevmos \
--home "$HOMEDIR"
--home "$HOMEDIR" \
--json-rpc.api eth,txpool,personal,net,debug,web3 \
--chain-id "$CHAINID"
75 changes: 71 additions & 4 deletions example_chain/osd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@ import (
dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/pruning"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/server"
sdkserver "github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
evmoscmd "github.com/evmos/os/client"
evmoscmdconfig "github.com/evmos/os/cmd/config"
evmoskeyring "github.com/evmos/os/crypto/keyring"
evmosencoding "github.com/evmos/os/encoding"
evmoseip712 "github.com/evmos/os/ethereum/eip712"
"github.com/evmos/os/example_chain"
chainconfig "github.com/evmos/os/example_chain/osd/config"
evmosserver "github.com/evmos/os/server"
evmosserverconfig "github.com/evmos/os/server/config"
srvflags "github.com/evmos/os/server/flags"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -86,7 +93,7 @@ func NewRootCmd() *cobra.Command {
customAppTemplate, customAppConfig := initAppConfig()
customTMConfig := initTendermintConfig()

return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
},
}

Expand Down Expand Up @@ -180,6 +187,13 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
txCommand(),
)

// add general tx flags to the root command
var err error
rootCmd, err = srvflags.AddTxFlags(rootCmd)
if err != nil {
panic(err)
}

// add rosetta
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
}
Expand Down Expand Up @@ -253,8 +267,61 @@ func newApp(
traceStore io.Writer,
appOpts servertypes.AppOptions,
) servertypes.Application {
var cache sdk.MultiStorePersistentCache

if cast.ToBool(appOpts.Get(sdkserver.FlagInterBlockCache)) {
cache = store.NewCommitKVStoreCacheManager()
}

pruningOpts, err := sdkserver.GetPruningOptionsFromFlags(appOpts)
if err != nil {
panic(err)
}

homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
if chainID == "" {
chainID, err = evmoscmdconfig.GetChainIDFromHome(homeDir)
if err != nil {
panic(err)
}
}

snapshotStore, err := sdkserver.GetSnapshotStore(appOpts)
if err != nil {
panic(err)
}

snapshotOptions := snapshottypes.NewSnapshotOptions(
cast.ToUint64(appOpts.Get(sdkserver.FlagStateSyncSnapshotInterval)),
cast.ToUint32(appOpts.Get(sdkserver.FlagStateSyncSnapshotKeepRecent)),
)

baseappOptions := []func(*baseapp.BaseApp){
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltHeight))),
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltTime))),
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(sdkserver.FlagMinRetainBlocks))),
baseapp.SetInterBlockCache(cache),
baseapp.SetTrace(cast.ToBool(appOpts.Get(sdkserver.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(sdkserver.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(sdkserver.FlagIAVLCacheSize))),
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(sdkserver.FlagDisableIAVLFastNode))),
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(sdkserver.FlagIAVLLazyLoading))),
baseapp.SetChainID(chainID),
}

// Set up the required mempool and ABCI proposal handlers for evmOS
baseappOptions = append(baseappOptions, func(app *baseapp.BaseApp) {
mempool := sdkmempool.NoOpMempool{}
app.SetMempool(mempool)

baseappOptions := server.DefaultBaseappOptions(appOpts)
handler := baseapp.NewDefaultProposalHandler(mempool, app)
app.SetPrepareProposal(handler.PrepareProposalHandler())
app.SetProcessProposal(handler.ProcessProposalHandler())
})

return example_chain.NewExampleApp(
logger, db, traceStore, true,
Expand Down Expand Up @@ -289,7 +356,7 @@ func appExport(
}

// overwrite the FlagInvCheckPeriod
viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
viperAppOpts.Set(sdkserver.FlagInvCheckPeriod, 1)
appOpts = viperAppOpts

if height != -1 {
Expand Down

0 comments on commit ea877ce

Please sign in to comment.