2021-04-17 10:00:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-06-29 17:02:21 +00:00
|
|
|
"errors"
|
2021-04-17 10:00:07 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
"github.com/spf13/cast"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
tmcfg "github.com/tendermint/tendermint/config"
|
|
|
|
tmcli "github.com/tendermint/tendermint/libs/cli"
|
|
|
|
tmlog "github.com/tendermint/tendermint/libs/log"
|
|
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/config"
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/rpc"
|
|
|
|
sdkserver "github.com/cosmos/cosmos-sdk/server"
|
|
|
|
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
2021-08-19 16:55:13 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp/params"
|
|
|
|
"github.com/cosmos/cosmos-sdk/snapshots"
|
2022-06-06 12:37:13 +00:00
|
|
|
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
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"
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/crisis"
|
2021-04-17 10:00:07 +00:00
|
|
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/app"
|
|
|
|
ethermintclient "github.com/cerc-io/laconicd/client"
|
|
|
|
"github.com/cerc-io/laconicd/client/debug"
|
|
|
|
"github.com/cerc-io/laconicd/crypto/hd"
|
|
|
|
"github.com/cerc-io/laconicd/encoding"
|
|
|
|
"github.com/cerc-io/laconicd/server"
|
|
|
|
servercfg "github.com/cerc-io/laconicd/server/config"
|
|
|
|
srvflags "github.com/cerc-io/laconicd/server/flags"
|
|
|
|
ethermint "github.com/cerc-io/laconicd/types"
|
2021-04-17 10:00:07 +00:00
|
|
|
)
|
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
const EnvPrefix = "ETHERMINT"
|
2021-07-23 12:31:59 +00:00
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
// NewRootCmd creates a new root command for simd. It is called once in the
|
|
|
|
// main function.
|
|
|
|
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
2021-06-04 13:45:37 +00:00
|
|
|
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
|
2021-04-17 10:00:07 +00:00
|
|
|
initClientCtx := client.Context{}.
|
2022-04-11 08:09:39 +00:00
|
|
|
WithCodec(encodingConfig.Codec).
|
2021-04-17 10:00:07 +00:00
|
|
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
|
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
|
|
WithLegacyAmino(encodingConfig.Amino).
|
|
|
|
WithInput(os.Stdin).
|
|
|
|
WithAccountRetriever(types.AccountRetriever{}).
|
2021-04-18 17:23:26 +00:00
|
|
|
WithBroadcastMode(flags.BroadcastBlock).
|
2021-06-29 17:02:21 +00:00
|
|
|
WithHomeDir(app.DefaultNodeHome).
|
2021-07-23 12:31:59 +00:00
|
|
|
WithKeyringOptions(hd.EthSecp256k1Option()).
|
|
|
|
WithViper(EnvPrefix)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
2022-09-07 07:26:51 +00:00
|
|
|
Use: "laconicd",
|
2022-10-10 10:38:33 +00:00
|
|
|
Short: "Ethermint Daemon",
|
2021-04-17 10:00:07 +00:00
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
2021-06-29 17:02:21 +00:00
|
|
|
// set the default command outputs
|
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
|
|
|
cmd.SetErr(cmd.ErrOrStderr())
|
|
|
|
|
2021-10-22 10:49:38 +00:00
|
|
|
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-29 17:02:21 +00:00
|
|
|
|
2021-10-22 10:49:38 +00:00
|
|
|
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
|
2021-06-29 17:02:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-22 10:49:38 +00:00
|
|
|
// FIXME: replace AttoPhoton with bond denom
|
2021-07-28 09:47:29 +00:00
|
|
|
customAppTemplate, customAppConfig := servercfg.AppConfig(ethermint.AttoPhoton)
|
2021-06-29 17:02:21 +00:00
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, tmcfg.DefaultConfig())
|
2021-04-17 10:00:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// TODO: double-check
|
2022-10-10 10:38:33 +00:00
|
|
|
// authclient.Codec = encodingConfig.Codec
|
2021-06-29 17:02:21 +00:00
|
|
|
|
|
|
|
cfg := sdk.GetConfig()
|
|
|
|
cfg.Seal()
|
2021-04-17 10:00:07 +00:00
|
|
|
|
|
|
|
rootCmd.AddCommand(
|
2021-04-18 17:23:26 +00:00
|
|
|
ethermintclient.ValidateChainID(
|
|
|
|
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
|
2021-04-17 10:00:07 +00:00
|
|
|
),
|
|
|
|
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
|
2021-11-29 15:46:20 +00:00
|
|
|
genutilcli.MigrateGenesisCmd(), // TODO: shouldn't this include the local app version instead of the SDK?
|
2021-05-20 07:44:07 +00:00
|
|
|
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
|
2021-04-17 10:00:07 +00:00
|
|
|
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
|
|
|
|
AddGenesisAccountCmd(app.DefaultNodeHome),
|
|
|
|
tmcli.NewCompletionCmd(rootCmd, true),
|
2021-11-14 13:34:10 +00:00
|
|
|
ethermintclient.NewTestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
2021-04-17 10:00:07 +00:00
|
|
|
debug.Cmd(),
|
2021-06-29 17:02:21 +00:00
|
|
|
config.Cmd(),
|
2021-04-17 10:00:07 +00:00
|
|
|
)
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
a := appCreator{encodingConfig}
|
|
|
|
server.AddCommands(rootCmd, app.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
|
|
|
// add keybase, auxiliary RPC, query, and tx child commands
|
|
|
|
rootCmd.AddCommand(
|
|
|
|
rpc.StatusCommand(),
|
|
|
|
queryCommand(),
|
|
|
|
txCommand(),
|
2021-04-18 17:23:26 +00:00
|
|
|
ethermintclient.KeyCommands(app.DefaultNodeHome),
|
2021-04-17 10:00:07 +00:00
|
|
|
)
|
2021-11-25 15:12:57 +00:00
|
|
|
|
|
|
|
rootCmd, err := srvflags.AddTxFlags(rootCmd)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-04-18 17:23:26 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// add rosetta
|
2022-04-11 08:09:39 +00:00
|
|
|
rootCmd.AddCommand(sdkserver.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
|
2021-06-29 17:02:21 +00:00
|
|
|
|
2022-10-12 07:34:44 +00:00
|
|
|
// Add flags for GQL server.
|
|
|
|
rootCmd = srvflags.AddGQLFlags(rootCmd)
|
|
|
|
|
2021-06-08 07:07:11 +00:00
|
|
|
return rootCmd, encodingConfig
|
2021-04-17 10:00:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
func addModuleInitFlags(startCmd *cobra.Command) {
|
|
|
|
crisis.AddModuleInitFlags(startCmd)
|
|
|
|
}
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
func queryCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "query",
|
|
|
|
Aliases: []string{"q"},
|
|
|
|
Short: "Querying subcommands",
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.AddCommand(
|
|
|
|
authcmd.GetAccountCmd(),
|
|
|
|
rpc.ValidatorCommand(),
|
|
|
|
rpc.BlockCommand(),
|
|
|
|
authcmd.QueryTxsByEventsCmd(),
|
|
|
|
authcmd.QueryTxCmd(),
|
|
|
|
)
|
|
|
|
|
|
|
|
app.ModuleBasics.AddQueryCommands(cmd)
|
|
|
|
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func txCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "tx",
|
|
|
|
Short: "Transactions subcommands",
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.AddCommand(
|
|
|
|
authcmd.GetSignCommand(),
|
|
|
|
authcmd.GetSignBatchCommand(),
|
|
|
|
authcmd.GetMultiSignCommand(),
|
2021-06-29 17:02:21 +00:00
|
|
|
authcmd.GetMultiSignBatchCmd(),
|
2021-04-17 10:00:07 +00:00
|
|
|
authcmd.GetValidateSignaturesCommand(),
|
|
|
|
authcmd.GetBroadcastCommand(),
|
|
|
|
authcmd.GetEncodeCommand(),
|
|
|
|
authcmd.GetDecodeCommand(),
|
|
|
|
)
|
|
|
|
|
|
|
|
app.ModuleBasics.AddTxCommands(cmd)
|
|
|
|
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
type appCreator struct {
|
|
|
|
encCfg params.EncodingConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// newApp is an appCreator
|
2022-09-30 06:41:39 +00:00
|
|
|
func (a appCreator) newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
|
2021-04-17 10:00:07 +00:00
|
|
|
var cache sdk.MultiStorePersistentCache
|
|
|
|
|
|
|
|
if cast.ToBool(appOpts.Get(sdkserver.FlagInterBlockCache)) {
|
|
|
|
cache = store.NewCommitKVStoreCacheManager()
|
|
|
|
}
|
|
|
|
|
|
|
|
skipUpgradeHeights := make(map[int64]bool)
|
|
|
|
for _, h := range cast.ToIntSlice(appOpts.Get(sdkserver.FlagUnsafeSkipUpgrades)) {
|
|
|
|
skipUpgradeHeights[int64(h)] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
pruningOpts, err := sdkserver.GetPruningOptionsFromFlags(appOpts)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
|
2022-10-10 10:38:33 +00:00
|
|
|
if err = os.MkdirAll(snapshotDir, os.ModePerm); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-09-30 06:41:39 +00:00
|
|
|
snapshotDB, err := dbm.NewDB("metadata", sdkserver.GetAppDBBackend(appOpts), snapshotDir)
|
2021-04-17 10:00:07 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-10-10 10:38:33 +00:00
|
|
|
|
2022-06-06 12:37:13 +00:00
|
|
|
snapshotOptions := snapshottypes.NewSnapshotOptions(
|
2022-06-07 10:13:58 +00:00
|
|
|
cast.ToUint64(appOpts.Get(sdkserver.FlagStateSyncSnapshotInterval)),
|
|
|
|
cast.ToUint32(appOpts.Get(sdkserver.FlagStateSyncSnapshotKeepRecent)),
|
2022-06-06 12:37:13 +00:00
|
|
|
)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
2021-04-18 17:23:26 +00:00
|
|
|
ethermintApp := app.NewEthermintApp(
|
2021-04-17 10:00:07 +00:00
|
|
|
logger, db, traceStore, true, skipUpgradeHeights,
|
|
|
|
cast.ToString(appOpts.Get(flags.FlagHome)),
|
|
|
|
cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)),
|
2021-06-29 17:02:21 +00:00
|
|
|
a.encCfg,
|
2021-04-17 10:00:07 +00:00
|
|
|
appOpts,
|
|
|
|
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))),
|
2022-06-06 12:37:13 +00:00
|
|
|
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
|
2021-04-17 10:00:07 +00:00
|
|
|
)
|
2021-04-18 17:23:26 +00:00
|
|
|
|
|
|
|
return ethermintApp
|
2021-04-17 10:00:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// appExport creates a new simapp (optionally at a given height)
|
2021-04-17 10:00:07 +00:00
|
|
|
// and exports state.
|
2021-06-29 17:02:21 +00:00
|
|
|
func (a appCreator) appExport(
|
2022-09-30 06:41:39 +00:00
|
|
|
logger tmlog.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
|
2021-04-18 17:23:26 +00:00
|
|
|
appOpts servertypes.AppOptions,
|
|
|
|
) (servertypes.ExportedApp, error) {
|
2021-04-17 10:00:07 +00:00
|
|
|
var ethermintApp *app.EthermintApp
|
2021-06-29 17:02:21 +00:00
|
|
|
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
|
|
|
if !ok || homePath == "" {
|
|
|
|
return servertypes.ExportedApp{}, errors.New("application home not set")
|
|
|
|
}
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
if height != -1 {
|
2021-06-29 17:02:21 +00:00
|
|
|
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, appOpts)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
|
|
|
if err := ethermintApp.LoadHeight(height); err != nil {
|
|
|
|
return servertypes.ExportedApp{}, err
|
|
|
|
}
|
|
|
|
} else {
|
2021-06-29 17:02:21 +00:00
|
|
|
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), a.encCfg, appOpts)
|
2021-04-17 10:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
|
|
|
|
}
|