forked from cerc-io/laconicd-deprecated
all: bump SDK to v0.43.0-rc0 (#194)
* all: bump SDK to v0.43.0-rc0 * more updates * keys * accounting * update account * ante changes * readonly * readonly build * minor changes from self review * fixes * evm debug * custom config & rosetta * fix
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,6 +18,54 @@ const (
|
||||
DefaultEVMWSAddress = "0.0.0.0:8546"
|
||||
)
|
||||
|
||||
// AppConfig helps to override default appConfig template and configs.
|
||||
// return "", nil if no custom configuration is required for the application.
|
||||
func AppConfig() (string, interface{}) {
|
||||
// Optionally allow the chain developer to overwrite the SDK's default
|
||||
// server config.
|
||||
srvCfg := config.DefaultConfig()
|
||||
|
||||
// The SDK's default minimum gas price is set to "" (empty value) inside
|
||||
// app.toml. If left empty by validators, the node will halt on startup.
|
||||
// However, the chain developer can set a default app.toml value for their
|
||||
// validators here.
|
||||
//
|
||||
// In summary:
|
||||
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
|
||||
// own app.toml config,
|
||||
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
|
||||
// own app.toml to override, or use this default value.
|
||||
//
|
||||
// In ethermint, we set the min gas prices to 0.
|
||||
srvCfg.MinGasPrices = "0" + ethermint.AttoPhoton
|
||||
|
||||
customAppConfig := Config{
|
||||
Config: *srvCfg,
|
||||
EVMRPC: *DefaultEVMConfig(),
|
||||
}
|
||||
|
||||
customAppTemplate := config.DefaultConfigTemplate + DefaultConfigTemplate
|
||||
|
||||
return customAppTemplate, customAppConfig
|
||||
}
|
||||
|
||||
// DefaultConfig returns server's default configuration.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Config: *config.DefaultConfig(),
|
||||
EVMRPC: *DefaultEVMConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultEVMConfig returns an EVM config with the JSON-RPC API enabled by default
|
||||
func DefaultEVMConfig() *EVMRPCConfig {
|
||||
return &EVMRPCConfig{
|
||||
Enable: true,
|
||||
RPCAddress: DefaultEVMAddress,
|
||||
WsAddress: DefaultEVMWSAddress,
|
||||
}
|
||||
}
|
||||
|
||||
// EVMRPCConfig defines configuration for the EVM RPC server.
|
||||
type EVMRPCConfig struct {
|
||||
// Enable defines if the EVM RPC server should be enabled.
|
||||
@@ -33,70 +76,12 @@ type EVMRPCConfig struct {
|
||||
WsAddress string `mapstructure:"ws-address"`
|
||||
}
|
||||
|
||||
// Config defines the server's top level configuration
|
||||
// Config defines the server's top level configuration. It includes the default app config
|
||||
// from the SDK as well as the EVM configuration to enable the JSON-RPC APIs.
|
||||
type Config struct {
|
||||
config.BaseConfig `mapstructure:",squash"`
|
||||
config.Config
|
||||
|
||||
// Telemetry defines the application telemetry configuration
|
||||
Telemetry telemetry.Config `mapstructure:"telemetry"`
|
||||
API config.APIConfig `mapstructure:"api"`
|
||||
GRPC config.GRPCConfig `mapstructure:"grpc"`
|
||||
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
|
||||
StateSync config.StateSyncConfig `mapstructure:"state-sync"`
|
||||
}
|
||||
|
||||
func (c *Config) ToSDKConfig() *config.Config {
|
||||
return &config.Config{
|
||||
BaseConfig: c.BaseConfig,
|
||||
Telemetry: c.Telemetry,
|
||||
API: c.API,
|
||||
GRPC: c.GRPC,
|
||||
StateSync: c.StateSync,
|
||||
}
|
||||
}
|
||||
|
||||
// SetMinGasPrices sets the validator's minimum gas prices.
|
||||
func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) {
|
||||
c.MinGasPrices = gasPrices.String()
|
||||
}
|
||||
|
||||
// GetMinGasPrices returns the validator's minimum gas prices based on the set
|
||||
// configuration.
|
||||
func (c *Config) GetMinGasPrices() sdk.DecCoins {
|
||||
if c.MinGasPrices == "" {
|
||||
return sdk.DecCoins{}
|
||||
}
|
||||
|
||||
gasPricesStr := strings.Split(c.MinGasPrices, ";")
|
||||
gasPrices := make(sdk.DecCoins, len(gasPricesStr))
|
||||
|
||||
for i, s := range gasPricesStr {
|
||||
gasPrice, err := sdk.ParseDecCoin(s)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to parse minimum gas price coin (%s): %s", s, err))
|
||||
}
|
||||
|
||||
gasPrices[i] = gasPrice
|
||||
}
|
||||
|
||||
return gasPrices
|
||||
}
|
||||
|
||||
// DefaultConfig returns server's default configuration.
|
||||
func DefaultConfig() *Config {
|
||||
cfg := config.DefaultConfig()
|
||||
return &Config{
|
||||
BaseConfig: cfg.BaseConfig,
|
||||
Telemetry: cfg.Telemetry,
|
||||
API: cfg.API,
|
||||
GRPC: cfg.GRPC,
|
||||
EVMRPC: EVMRPCConfig{
|
||||
Enable: true,
|
||||
RPCAddress: DefaultEVMAddress,
|
||||
WsAddress: DefaultEVMWSAddress,
|
||||
},
|
||||
StateSync: cfg.StateSync,
|
||||
}
|
||||
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
|
||||
}
|
||||
|
||||
// GetConfig returns a fully parsed Config object.
|
||||
@@ -105,15 +90,11 @@ func GetConfig(v *viper.Viper) Config {
|
||||
cfg := config.GetConfig(v)
|
||||
|
||||
return Config{
|
||||
BaseConfig: cfg.BaseConfig,
|
||||
Telemetry: cfg.Telemetry,
|
||||
API: cfg.API,
|
||||
GRPC: cfg.GRPC,
|
||||
Config: cfg,
|
||||
EVMRPC: EVMRPCConfig{
|
||||
Enable: v.GetBool("evm-rpc.enable"),
|
||||
RPCAddress: v.GetString("evm-rpc.address"),
|
||||
WsAddress: v.GetString("evm-rpc.ws-address"),
|
||||
},
|
||||
StateSync: cfg.StateSync,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
require.True(t, cfg.GetMinGasPrices().IsZero())
|
||||
}
|
||||
|
||||
func TestSetMinimumFees(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.SetMinGasPrices(sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)})
|
||||
require.Equal(t, "5.000000000000000000foo", cfg.MinGasPrices)
|
||||
cfg := DefaultEVMConfig()
|
||||
require.True(t, cfg.Enable)
|
||||
require.Equal(t, cfg.RPCAddress, DefaultEVMAddress)
|
||||
require.Equal(t, cfg.WsAddress, DefaultEVMWSAddress)
|
||||
}
|
||||
|
||||
@@ -1,152 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
)
|
||||
|
||||
const defaultConfigTemplate = `# This is a TOML config file.
|
||||
# For more information, see https://github.com/toml-lang/toml
|
||||
|
||||
###############################################################################
|
||||
### Base Configuration ###
|
||||
###############################################################################
|
||||
|
||||
# The minimum gas prices a validator is willing to accept for processing a
|
||||
# transaction. A transaction's fees must meet the minimum of any denomination
|
||||
# specified in this config (e.g. 0.25token1;0.0001token2).
|
||||
minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}"
|
||||
|
||||
# default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals
|
||||
# nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node)
|
||||
# everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals
|
||||
# custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval'
|
||||
pruning = "{{ .BaseConfig.Pruning }}"
|
||||
|
||||
# These are applied if and only if the pruning strategy is custom.
|
||||
pruning-keep-recent = "{{ .BaseConfig.PruningKeepRecent }}"
|
||||
pruning-keep-every = "{{ .BaseConfig.PruningKeepEvery }}"
|
||||
pruning-interval = "{{ .BaseConfig.PruningInterval }}"
|
||||
|
||||
# HaltHeight contains a non-zero block height at which a node will gracefully
|
||||
# halt and shutdown that can be used to assist upgrades and testing.
|
||||
#
|
||||
# Note: Commitment of state will be attempted on the corresponding block.
|
||||
halt-height = {{ .BaseConfig.HaltHeight }}
|
||||
|
||||
# HaltTime contains a non-zero minimum block time (in Unix seconds) at which
|
||||
# a node will gracefully halt and shutdown that can be used to assist upgrades
|
||||
# and testing.
|
||||
#
|
||||
# Note: Commitment of state will be attempted on the corresponding block.
|
||||
halt-time = {{ .BaseConfig.HaltTime }}
|
||||
|
||||
# MinRetainBlocks defines the minimum block height offset from the current
|
||||
# block being committed, such that all blocks past this offset are pruned
|
||||
# from Tendermint. It is used as part of the process of determining the
|
||||
# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
|
||||
# that no blocks should be pruned.
|
||||
#
|
||||
# This configuration value is only responsible for pruning Tendermint blocks.
|
||||
# It has no bearing on application state pruning which is determined by the
|
||||
# "pruning-*" configurations.
|
||||
#
|
||||
# Note: Tendermint block pruning is dependant on this parameter in conunction
|
||||
# with the unbonding (safety threshold) period, state pruning and state sync
|
||||
# snapshot parameters to determine the correct minimum value of
|
||||
# ResponseCommit.RetainHeight.
|
||||
min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }}
|
||||
|
||||
# InterBlockCache enables inter-block caching.
|
||||
inter-block-cache = {{ .BaseConfig.InterBlockCache }}
|
||||
|
||||
# IndexEvents defines the set of events in the form {eventType}.{attributeKey},
|
||||
# which informs Tendermint what to index. If empty, all events will be indexed.
|
||||
#
|
||||
# Example:
|
||||
# ["message.sender", "message.recipient"]
|
||||
index-events = {{ .BaseConfig.IndexEvents }}
|
||||
|
||||
###############################################################################
|
||||
### Telemetry Configuration ###
|
||||
###############################################################################
|
||||
|
||||
[telemetry]
|
||||
|
||||
# Prefixed with keys to separate services.
|
||||
service-name = "{{ .Telemetry.ServiceName }}"
|
||||
|
||||
# Enabled enables the application telemetry functionality. When enabled,
|
||||
# an in-memory sink is also enabled by default. Operators may also enabled
|
||||
# other sinks such as Prometheus.
|
||||
enabled = {{ .Telemetry.Enabled }}
|
||||
|
||||
# Enable prefixing gauge values with hostname.
|
||||
enable-hostname = {{ .Telemetry.EnableHostname }}
|
||||
|
||||
# Enable adding hostname to labels.
|
||||
enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }}
|
||||
|
||||
# Enable adding service to labels.
|
||||
enable-service-label = {{ .Telemetry.EnableServiceLabel }}
|
||||
|
||||
# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink.
|
||||
prometheus-retention-time = {{ .Telemetry.PrometheusRetentionTime }}
|
||||
|
||||
# GlobalLabels defines a global set of name/value label tuples applied to all
|
||||
# metrics emitted using the wrapper functions defined in telemetry package.
|
||||
#
|
||||
# Example:
|
||||
# [["chain_id", "cosmoshub-1"]]
|
||||
global-labels = [{{ range $k, $v := .Telemetry.GlobalLabels }}
|
||||
["{{index $v 0 }}", "{{ index $v 1}}"],{{ end }}
|
||||
]
|
||||
|
||||
###############################################################################
|
||||
### API Configuration ###
|
||||
###############################################################################
|
||||
|
||||
[api]
|
||||
|
||||
# Enable defines if the API server should be enabled.
|
||||
enable = {{ .API.Enable }}
|
||||
|
||||
# Swagger defines if swagger documentation should automatically be registered.
|
||||
swagger = {{ .API.Swagger }}
|
||||
|
||||
# Address defines the API server to listen on.
|
||||
address = "{{ .API.Address }}"
|
||||
|
||||
# MaxOpenConnections defines the number of maximum open connections.
|
||||
max-open-connections = {{ .API.MaxOpenConnections }}
|
||||
|
||||
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds).
|
||||
rpc-read-timeout = {{ .API.RPCReadTimeout }}
|
||||
|
||||
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds).
|
||||
rpc-write-timeout = {{ .API.RPCWriteTimeout }}
|
||||
|
||||
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes).
|
||||
rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }}
|
||||
|
||||
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
|
||||
enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }}
|
||||
|
||||
###############################################################################
|
||||
### gRPC Configuration ###
|
||||
###############################################################################
|
||||
|
||||
[grpc]
|
||||
|
||||
# Enable defines if the gRPC server should be enabled.
|
||||
enable = {{ .GRPC.Enable }}
|
||||
|
||||
# Address defines the gRPC server address to bind to.
|
||||
address = "{{ .GRPC.Address }}"
|
||||
|
||||
// DefaultConfigTemplate defines the configuration template for the EVM RPC configuration
|
||||
const DefaultConfigTemplate = `
|
||||
###############################################################################
|
||||
### EVM RPC Configuration ###
|
||||
###############################################################################
|
||||
@@ -161,52 +16,4 @@ address = "{{ .EVMRPC.RPCAddress }}"
|
||||
|
||||
# Address defines the EVM WebSocket server address to bind to.
|
||||
ws-address = "{{ .EVMRPC.WsAddress }}"
|
||||
|
||||
###############################################################################
|
||||
### State Sync Configuration ###
|
||||
###############################################################################
|
||||
|
||||
# State sync snapshots allow other nodes to rapidly join the network without replaying historical
|
||||
# blocks, instead downloading and applying a snapshot of the application state at a given height.
|
||||
[state-sync]
|
||||
|
||||
# snapshot-interval specifies the block interval at which local state sync snapshots are
|
||||
# taken (0 to disable). Must be a multiple of pruning-keep-every.
|
||||
snapshot-interval = {{ .StateSync.SnapshotInterval }}
|
||||
|
||||
# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all).
|
||||
snapshot-keep-recent = {{ .StateSync.SnapshotKeepRecent }}
|
||||
`
|
||||
|
||||
var configTemplate *template.Template
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
tmpl := template.New("appConfigFileTemplate")
|
||||
|
||||
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseConfig retrieves the default environment configuration for the
|
||||
// application.
|
||||
func ParseConfig(v *viper.Viper) (*Config, error) {
|
||||
conf := DefaultConfig()
|
||||
err := v.Unmarshal(conf)
|
||||
|
||||
return conf, err
|
||||
}
|
||||
|
||||
// WriteConfigFile renders config using the template and writes it to
|
||||
// configFilePath.
|
||||
func WriteConfigFile(configFilePath string, config *Config) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err := configTemplate.Execute(&buffer, config); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -22,7 +22,8 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/tharsis/ethermint/crypto/hd"
|
||||
chain "github.com/tharsis/ethermint/types"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -44,8 +45,8 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
depCdc := clientCtx.JSONMarshaler
|
||||
cdc := depCdc.(codec.Marshaler)
|
||||
depCdc := clientCtx.JSONCodec
|
||||
cdc := depCdc.(codec.Codec)
|
||||
|
||||
serverCtx := server.GetServerContextFromCmd(cmd)
|
||||
config := serverCtx.Config
|
||||
@@ -127,9 +128,9 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||
return errors.New("invalid vesting parameters; must supply start and end time or end time")
|
||||
}
|
||||
} else {
|
||||
genAccount = &chain.EthAccount{
|
||||
genAccount = ðermint.EthAccount{
|
||||
BaseAccount: baseAccount,
|
||||
CodeHash: ethcrypto.Keccak256(nil),
|
||||
CodeHash: common.BytesToHash(evmtypes.EmptyCodeHash).Hex(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+55
-40
@@ -1,15 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/snapshots"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -20,6 +18,7 @@ import (
|
||||
|
||||
"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/rpc"
|
||||
@@ -27,15 +26,17 @@ import (
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
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"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
|
||||
"github.com/tharsis/ethermint/app"
|
||||
ethermintclient "github.com/tharsis/ethermint/client"
|
||||
ethermintconfig "github.com/tharsis/ethermint/cmd/ethermintd/config"
|
||||
"github.com/tharsis/ethermint/encoding"
|
||||
"github.com/tharsis/ethermint/server"
|
||||
)
|
||||
|
||||
// NewRootCmd creates a new root command for simd. It is called once in the
|
||||
@@ -43,29 +44,46 @@ import (
|
||||
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
||||
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
|
||||
initClientCtx := client.Context{}.
|
||||
WithJSONMarshaler(encodingConfig.Marshaler).
|
||||
WithCodec(encodingConfig.Marshaler).
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithLegacyAmino(encodingConfig.Amino).
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(types.AccountRetriever{}).
|
||||
WithBroadcastMode(flags.BroadcastBlock).
|
||||
WithHomeDir(app.DefaultNodeHome)
|
||||
WithHomeDir(app.DefaultNodeHome).
|
||||
WithViper("") // In simapp, we don't use any prefix for env variables.
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "ethermintd",
|
||||
Short: "Ethermint Daemon",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
// set the default command outputs
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.SetErr(cmd.ErrOrStderr())
|
||||
|
||||
initClientCtx = client.ReadHomeFlag(initClientCtx, cmd)
|
||||
|
||||
initClientCtx, err := config.ReadFromClientConfig(initClientCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return InterceptConfigsPreRunHandler(cmd)
|
||||
customAppTemplate, customAppConfig := ethermintconfig.AppConfig()
|
||||
|
||||
return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig)
|
||||
},
|
||||
}
|
||||
|
||||
authclient.Codec = encodingConfig.Marshaler
|
||||
sdk.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
// TODO: double-check
|
||||
// authclient.Codec = encodingConfig.Marshaler
|
||||
|
||||
cfg := sdk.GetConfig()
|
||||
cfg.Seal()
|
||||
|
||||
rootCmd.AddCommand(
|
||||
ethermintclient.ValidateChainID(
|
||||
@@ -79,29 +97,11 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
||||
tmcli.NewCompletionCmd(rootCmd, true),
|
||||
ethermintclient.TestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
|
||||
debug.Cmd(),
|
||||
config.Cmd(),
|
||||
)
|
||||
|
||||
tendermintCmd := &cobra.Command{
|
||||
Use: "tendermint",
|
||||
Short: "Tendermint subcommands",
|
||||
}
|
||||
|
||||
tendermintCmd.AddCommand(
|
||||
sdkserver.ShowNodeIDCmd(),
|
||||
sdkserver.ShowValidatorCmd(),
|
||||
sdkserver.ShowAddressCmd(),
|
||||
sdkserver.VersionCmd(),
|
||||
)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
StartCmd(newApp, app.DefaultNodeHome),
|
||||
sdkserver.UnsafeResetAllCmd(),
|
||||
flags.LineBreak,
|
||||
tendermintCmd,
|
||||
sdkserver.ExportCmd(createAppAndExport, app.DefaultNodeHome),
|
||||
flags.LineBreak,
|
||||
version.NewVersionCommand(),
|
||||
)
|
||||
a := appCreator{encodingConfig}
|
||||
server.AddCommands(rootCmd, app.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
|
||||
|
||||
// add keybase, auxiliary RPC, query, and tx child commands
|
||||
rootCmd.AddCommand(
|
||||
@@ -112,9 +112,16 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
||||
)
|
||||
rootCmd = addTxFlags(rootCmd)
|
||||
|
||||
// add rosetta
|
||||
rootCmd.AddCommand(sdkserver.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
|
||||
|
||||
return rootCmd, encodingConfig
|
||||
}
|
||||
|
||||
func addModuleInitFlags(startCmd *cobra.Command) {
|
||||
crisis.AddModuleInitFlags(startCmd)
|
||||
}
|
||||
|
||||
func queryCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query",
|
||||
@@ -152,12 +159,11 @@ func txCommand() *cobra.Command {
|
||||
authcmd.GetSignCommand(),
|
||||
authcmd.GetSignBatchCommand(),
|
||||
authcmd.GetMultiSignCommand(),
|
||||
authcmd.GetMultiSignBatchCmd(),
|
||||
authcmd.GetValidateSignaturesCommand(),
|
||||
flags.LineBreak,
|
||||
authcmd.GetBroadcastCommand(),
|
||||
authcmd.GetEncodeCommand(),
|
||||
authcmd.GetDecodeCommand(),
|
||||
flags.LineBreak,
|
||||
)
|
||||
|
||||
app.ModuleBasics.AddTxCommands(cmd)
|
||||
@@ -166,7 +172,12 @@ func txCommand() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
|
||||
type appCreator struct {
|
||||
encCfg params.EncodingConfig
|
||||
}
|
||||
|
||||
// newApp is an appCreator
|
||||
func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
|
||||
var cache sdk.MultiStorePersistentCache
|
||||
|
||||
if cast.ToBool(appOpts.Get(sdkserver.FlagInterBlockCache)) {
|
||||
@@ -197,7 +208,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
|
||||
logger, db, traceStore, true, skipUpgradeHeights,
|
||||
cast.ToString(appOpts.Get(flags.FlagHome)),
|
||||
cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)),
|
||||
encoding.MakeConfig(app.ModuleBasics), // Ideally, we would reuse the one created by NewRootCmd.
|
||||
a.encCfg,
|
||||
appOpts,
|
||||
baseapp.SetPruning(pruningOpts),
|
||||
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))),
|
||||
@@ -215,23 +226,27 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
|
||||
return ethermintApp
|
||||
}
|
||||
|
||||
// createAppAndExport creates a new Ethermint app (optionally at a given height)
|
||||
// appExport creates a new simapp (optionally at a given height)
|
||||
// and exports state.
|
||||
func createAppAndExport(
|
||||
func (a appCreator) appExport(
|
||||
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
|
||||
appOpts servertypes.AppOptions,
|
||||
) (servertypes.ExportedApp, error) {
|
||||
encCfg := encoding.MakeConfig(app.ModuleBasics) // Ideally, we would reuse the one created by NewRootCmd.
|
||||
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
|
||||
|
||||
var ethermintApp *app.EthermintApp
|
||||
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
||||
if !ok || homePath == "" {
|
||||
return servertypes.ExportedApp{}, errors.New("application home not set")
|
||||
}
|
||||
|
||||
if height != -1 {
|
||||
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg, appOpts)
|
||||
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, appOpts)
|
||||
|
||||
if err := ethermintApp.LoadHeight(height); err != nil {
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
} else {
|
||||
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg, appOpts)
|
||||
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), a.encCfg, appOpts)
|
||||
}
|
||||
|
||||
return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
|
||||
|
||||
@@ -1,410 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
||||
"github.com/rs/cors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/xlab/closer"
|
||||
log "github.com/xlab/suplog"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
"github.com/tendermint/tendermint/node"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
pvm "github.com/tendermint/tendermint/privval"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/rpc/client/local"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
sdkconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
ethlog "github.com/ethereum/go-ethereum/log"
|
||||
ethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/tharsis/ethermint/cmd/ethermintd/config"
|
||||
"github.com/tharsis/ethermint/ethereum/rpc"
|
||||
ethsrv "github.com/tharsis/ethermint/server"
|
||||
)
|
||||
|
||||
// Tendermint full-node start flags
|
||||
const (
|
||||
flagAddress = "address"
|
||||
flagTransport = "transport"
|
||||
flagTraceStore = "trace-store"
|
||||
flagCPUProfile = "cpu-profile"
|
||||
FlagMinGasPrices = "minimum-gas-prices"
|
||||
FlagHaltHeight = "halt-height"
|
||||
FlagHaltTime = "halt-time"
|
||||
FlagInterBlockCache = "inter-block-cache"
|
||||
FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades"
|
||||
FlagTrace = "trace"
|
||||
FlagInvCheckPeriod = "inv-check-period"
|
||||
|
||||
FlagPruning = "pruning"
|
||||
FlagPruningKeepRecent = "pruning-keep-recent"
|
||||
FlagPruningKeepEvery = "pruning-keep-every"
|
||||
FlagPruningInterval = "pruning-interval"
|
||||
FlagMinRetainBlocks = "min-retain-blocks"
|
||||
)
|
||||
|
||||
// GRPC-related flags.
|
||||
const (
|
||||
flagGRPCEnable = "grpc.enable"
|
||||
flagGRPCAddress = "grpc.address"
|
||||
flagEVMRPCEnable = "evm-rpc.enable"
|
||||
flagEVMRPCAddress = "evm-rpc.address"
|
||||
flagEVMWSAddress = "evm-rpc.ws-address"
|
||||
)
|
||||
|
||||
// State sync-related flags.
|
||||
const (
|
||||
FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval"
|
||||
FlagStateSyncSnapshotKeepRecent = "state-sync.snapshot-keep-recent"
|
||||
)
|
||||
|
||||
// StartCmd runs the service passed in, either stand-alone or in-process with
|
||||
// Tendermint.
|
||||
func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "Run the full node",
|
||||
Long: `Run the full node application with Tendermint in or out of process. By
|
||||
default, the application will run with Tendermint in process.
|
||||
|
||||
Pruning options can be provided via the '--pruning' flag or alternatively with '--pruning-keep-recent',
|
||||
'pruning-keep-every', and 'pruning-interval' together.
|
||||
|
||||
For '--pruning' the options are as follows:
|
||||
|
||||
default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals
|
||||
nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node)
|
||||
everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals
|
||||
custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval'
|
||||
|
||||
Node halting configurations exist in the form of two flags: '--halt-height' and '--halt-time'. During
|
||||
the ABCI Commit phase, the node will check if the current block height is greater than or equal to
|
||||
the halt-height or if the current block time is greater than or equal to the halt-time. If so, the
|
||||
node will attempt to gracefully shutdown and the block will not be committed. In addition, the node
|
||||
will not be able to commit subsequent blocks.
|
||||
|
||||
For profiling and benchmarking purposes, CPU profiling can be enabled via the '--cpu-profile' flag
|
||||
which accepts a path for the resulting pprof file.
|
||||
`,
|
||||
PreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
serverCtx := server.GetServerContextFromCmd(cmd)
|
||||
|
||||
// Bind flags to the Context's Viper so the app construction can set
|
||||
// options accordingly.
|
||||
err := serverCtx.Viper.BindPFlags(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = server.GetPruningOptionsFromFlags(serverCtx.Viper)
|
||||
return err
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
serverCtx := server.GetServerContextFromCmd(cmd)
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
|
||||
serverCtx.Logger.Info("starting ABCI with Tendermint")
|
||||
|
||||
// amino is needed here for backwards compatibility of REST routes
|
||||
err := startInProcess(serverCtx, clientCtx, appCreator)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
|
||||
cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address")
|
||||
cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc")
|
||||
cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")
|
||||
cmd.Flags().String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)")
|
||||
cmd.Flags().IntSlice(FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary")
|
||||
cmd.Flags().Uint64(FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node")
|
||||
cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node")
|
||||
cmd.Flags().Bool(FlagInterBlockCache, true, "Enable inter-block caching")
|
||||
cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file")
|
||||
cmd.Flags().Bool(FlagTrace, false, "Provide full stack traces for errors in ABCI Log")
|
||||
cmd.Flags().String(FlagPruning, storetypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)")
|
||||
cmd.Flags().Uint64(FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')")
|
||||
cmd.Flags().Uint64(FlagPruningKeepEvery, 0, "Offset heights to keep on disk after 'keep-every' (ignored if pruning is not 'custom')")
|
||||
cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")
|
||||
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")
|
||||
cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks")
|
||||
|
||||
cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled")
|
||||
cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on")
|
||||
|
||||
cmd.Flags().Bool(flagEVMRPCEnable, true, "Define if the gRPC server should be enabled")
|
||||
cmd.Flags().String(flagEVMRPCAddress, config.DefaultEVMAddress, "the EVM RPC server address to listen on")
|
||||
cmd.Flags().String(flagEVMWSAddress, config.DefaultEVMWSAddress, "the EVM WS server address to listen on")
|
||||
|
||||
cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval")
|
||||
cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep")
|
||||
|
||||
// add support for all Tendermint-specific command line options
|
||||
tcmd.AddNodeFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator types.AppCreator) error {
|
||||
cfg := ctx.Config
|
||||
home := cfg.RootDir
|
||||
|
||||
traceWriterFile := ctx.Viper.GetString(flagTraceStore)
|
||||
db, err := openDB(home)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed to open DB")
|
||||
return err
|
||||
}
|
||||
|
||||
traceWriter, err := openTraceWriter(traceWriterFile)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed to open trace writer")
|
||||
return err
|
||||
}
|
||||
|
||||
app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper)
|
||||
|
||||
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed load or gen node key")
|
||||
return err
|
||||
}
|
||||
|
||||
genDocProvider := node.DefaultGenesisDocProviderFunc(cfg)
|
||||
tmNode, err := node.NewNode(
|
||||
cfg,
|
||||
pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()),
|
||||
nodeKey,
|
||||
proxy.NewLocalClientCreator(app),
|
||||
genDocProvider,
|
||||
node.DefaultDBProvider,
|
||||
node.DefaultMetricsProvider(cfg.Instrumentation),
|
||||
ctx.Logger.With("module", "node"),
|
||||
)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed init node")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tmNode.Start(); err != nil {
|
||||
log.WithError(err).Errorln("failed start tendermint server")
|
||||
return err
|
||||
}
|
||||
|
||||
genDoc, err := genDocProvider()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.
|
||||
WithHomeDir(home).
|
||||
WithChainID(genDoc.ChainID).
|
||||
WithClient(local.New(tmNode))
|
||||
|
||||
var apiSrv *api.Server
|
||||
config := config.GetConfig(ctx.Viper)
|
||||
|
||||
var grpcSrv *grpc.Server
|
||||
if config.GRPC.Enable {
|
||||
grpcSrv, err = servergrpc.StartGRPCServer(clientCtx, app, config.GRPC.Address)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed to boot GRPC server")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var httpSrv *http.Server
|
||||
var httpSrvDone = make(chan struct{}, 1)
|
||||
var wsSrv rpc.WebsocketsServer
|
||||
|
||||
ethlog.Root().SetHandler(ethlog.StdoutHandler)
|
||||
if config.EVMRPC.Enable {
|
||||
tmEndpoint := "/websocket"
|
||||
tmRPCAddr := cfg.RPC.ListenAddress
|
||||
log.Infoln("EVM RPC Connecting to Tendermint WebSocket at", tmRPCAddr+tmEndpoint)
|
||||
tmWsClient := ethsrv.ConnectTmWS(tmRPCAddr, tmEndpoint)
|
||||
|
||||
rpcServer := ethrpc.NewServer()
|
||||
apis := rpc.GetRPCAPIs(clientCtx, tmWsClient)
|
||||
|
||||
for _, api := range apis {
|
||||
if err := rpcServer.RegisterName(api.Namespace, api.Service); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"namespace": api.Namespace,
|
||||
"service": api.Service,
|
||||
}).WithError(err).Fatalln("failed to register service in EVM RPC namespace")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/", rpcServer.ServeHTTP).Methods("POST")
|
||||
if grpcSrv != nil {
|
||||
grpcWeb := grpcweb.WrapServer(grpcSrv)
|
||||
ethsrv.MountGRPCWebServices(r, grpcWeb, grpcweb.ListGRPCResources(grpcSrv))
|
||||
}
|
||||
|
||||
handlerWithCors := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{
|
||||
http.MethodHead,
|
||||
http.MethodGet,
|
||||
http.MethodPost,
|
||||
http.MethodPut,
|
||||
http.MethodPatch,
|
||||
http.MethodDelete,
|
||||
},
|
||||
AllowedHeaders: []string{"*"},
|
||||
AllowCredentials: false,
|
||||
OptionsPassthrough: false,
|
||||
})
|
||||
|
||||
httpSrv = &http.Server{
|
||||
Addr: config.EVMRPC.RPCAddress,
|
||||
Handler: handlerWithCors.Handler(r),
|
||||
}
|
||||
|
||||
errCh := make(chan error)
|
||||
go func() {
|
||||
log.Infoln("Starting EVM RPC server on", config.EVMRPC.RPCAddress)
|
||||
if err := httpSrv.ListenAndServe(); err != nil {
|
||||
if err == http.ErrServerClosed {
|
||||
close(httpSrvDone)
|
||||
return
|
||||
}
|
||||
|
||||
log.WithError(err).Errorln("failed to start EVM RPC server")
|
||||
errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errCh:
|
||||
log.WithError(err).Errorln("failed to boot EVM RPC server")
|
||||
return err
|
||||
case <-time.After(1 * time.Second): // assume EVM RPC server started successfully
|
||||
}
|
||||
|
||||
log.Infoln("Starting EVM WebSocket server on", config.EVMRPC.WsAddress)
|
||||
_, port, _ := net.SplitHostPort(config.EVMRPC.RPCAddress)
|
||||
|
||||
// allocate separate WS connection to Tendermint
|
||||
tmWsClient = ethsrv.ConnectTmWS(tmRPCAddr, tmEndpoint)
|
||||
wsSrv = rpc.NewWebsocketsServer(tmWsClient, "localhost:"+port, config.EVMRPC.WsAddress)
|
||||
go wsSrv.Start()
|
||||
}
|
||||
|
||||
sdkcfg := sdkconfig.GetConfig(ctx.Viper)
|
||||
sdkcfg.API = config.API
|
||||
if sdkcfg.API.Enable {
|
||||
apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
|
||||
app.RegisterAPIRoutes(apiSrv, sdkcfg.API)
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
if err := apiSrv.Start(sdkcfg); err != nil {
|
||||
errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errCh:
|
||||
log.WithError(err).Errorln("failed to boot API server")
|
||||
return err
|
||||
case <-time.After(5 * time.Second): // assume server started successfully
|
||||
}
|
||||
}
|
||||
|
||||
var cpuProfileCleanup func()
|
||||
|
||||
if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" {
|
||||
f, err := os.Create(cpuProfile)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed to create CP profile")
|
||||
return err
|
||||
}
|
||||
|
||||
log.WithField("profile", cpuProfile).Infoln("starting CPU profiler")
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cpuProfileCleanup = func() {
|
||||
log.WithField("profile", cpuProfile).Infoln("stopping CPU profiler")
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
closer.Bind(func() {
|
||||
if tmNode.IsRunning() {
|
||||
_ = tmNode.Stop()
|
||||
}
|
||||
|
||||
if cpuProfileCleanup != nil {
|
||||
cpuProfileCleanup()
|
||||
}
|
||||
|
||||
if httpSrv != nil {
|
||||
shutdownCtx, cancelFn := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancelFn()
|
||||
|
||||
if err := httpSrv.Shutdown(shutdownCtx); err != nil {
|
||||
log.WithError(err).Warningln("HTTP server shutdown produced a warning")
|
||||
} else {
|
||||
log.Infoln("HTTP server shut down, waiting 5 sec")
|
||||
select {
|
||||
case <-time.Tick(5 * time.Second):
|
||||
case <-httpSrvDone:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if grpcSrv != nil {
|
||||
grpcSrv.Stop()
|
||||
}
|
||||
|
||||
log.Infoln("Bye!")
|
||||
})
|
||||
|
||||
closer.Hold()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func openDB(rootDir string) (dbm.DB, error) {
|
||||
dataDir := filepath.Join(rootDir, "data")
|
||||
return sdk.NewLevelDB("application", dataDir)
|
||||
}
|
||||
|
||||
func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
|
||||
if traceWriterFile == "" {
|
||||
return
|
||||
}
|
||||
return os.OpenFile(
|
||||
traceWriterFile,
|
||||
os.O_WRONLY|os.O_APPEND|os.O_CREATE,
|
||||
0666,
|
||||
)
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
tmcfg "github.com/tendermint/tendermint/config"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
tmflags "github.com/tendermint/tendermint/libs/cli/flags"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"github.com/tharsis/ethermint/cmd/ethermintd/config"
|
||||
)
|
||||
|
||||
// InterceptConfigsPreRunHandler performs a pre-run function for the root daemon
|
||||
// application command. It will create a Viper literal and a default server
|
||||
// Context. The server Tendermint configuration will either be read and parsed
|
||||
// or created and saved to disk, where the server Context is updated to reflect
|
||||
// the Tendermint configuration. The Viper literal is used to read and parse
|
||||
// the application configuration. Command handlers can fetch the server Context
|
||||
// to get the Tendermint configuration or to get access to Viper.
|
||||
func InterceptConfigsPreRunHandler(cmd *cobra.Command) error {
|
||||
rootViper := viper.New()
|
||||
err := rootViper.BindPFlags(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = rootViper.BindPFlags(cmd.PersistentFlags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serverCtx := server.NewDefaultContext()
|
||||
config, err := interceptConfigs(serverCtx, rootViper)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||
logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, tmcfg.DefaultLogLevel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if rootViper.GetBool(tmcli.TraceFlag) {
|
||||
logger = log.NewTracingLogger(logger)
|
||||
}
|
||||
|
||||
serverCtx.Config = config
|
||||
serverCtx.Logger = logger.With("module", "main")
|
||||
|
||||
// TODO: parse package-level log levels correctly (replace tmlib)
|
||||
//
|
||||
// if len(config.LogLevel) == 0 {
|
||||
// if ll := rootViper.GetString("log-level"); len(ll) > 0 {
|
||||
// config.LogLevel = ll
|
||||
// } else {
|
||||
// config.LogLevel = "info"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// logger := logging.NewWrappedSuplog("info", false)
|
||||
//
|
||||
// if rootViper.GetBool(tmcli.TraceFlag) {
|
||||
// logger = tmlog.NewTracingLogger(logger)
|
||||
// }
|
||||
//
|
||||
// serverCtx.Config = config
|
||||
// serverCtx.Logger = logger.With("module", "main")
|
||||
|
||||
return server.SetCmdServerContext(cmd, serverCtx)
|
||||
}
|
||||
|
||||
// interceptConfigs parses and updates a Tendermint configuration file or
|
||||
// creates a new one and saves it. It also parses and saves the application
|
||||
// configuration file. The Tendermint configuration file is parsed given a root
|
||||
// Viper object, whereas the application is parsed with the private package-aware
|
||||
// viperCfg object.
|
||||
func interceptConfigs(ctx *server.Context, rootViper *viper.Viper) (*tmcfg.Config, error) {
|
||||
rootDir := rootViper.GetString(flags.FlagHome)
|
||||
configPath := filepath.Join(rootDir, "config")
|
||||
configFile := filepath.Join(configPath, "config.toml")
|
||||
|
||||
conf := tmcfg.DefaultConfig()
|
||||
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
tmcfg.EnsureRoot(rootDir)
|
||||
|
||||
if err = conf.ValidateBasic(); err != nil {
|
||||
return nil, fmt.Errorf("error in config file: %v", err)
|
||||
}
|
||||
|
||||
conf.RPC.PprofListenAddress = "localhost:6060"
|
||||
conf.P2P.RecvRate = 5120000
|
||||
conf.P2P.SendRate = 5120000
|
||||
conf.Consensus.TimeoutCommit = 5 * time.Second
|
||||
tmcfg.WriteConfigFile(configFile, conf)
|
||||
} else {
|
||||
rootViper.SetConfigType("toml")
|
||||
rootViper.SetConfigName("config")
|
||||
rootViper.AddConfigPath(configPath)
|
||||
if err := rootViper.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("failed to read in app.toml: %w", err)
|
||||
}
|
||||
|
||||
if err := rootViper.Unmarshal(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
conf.SetRoot(rootDir)
|
||||
|
||||
appConfigFilePath := filepath.Join(configPath, "app.toml")
|
||||
if _, err := os.Stat(appConfigFilePath); os.IsNotExist(err) {
|
||||
appConf, err := config.ParseConfig(ctx.Viper)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse app.toml: %w", err)
|
||||
}
|
||||
|
||||
config.WriteConfigFile(appConfigFilePath, appConf)
|
||||
}
|
||||
|
||||
ctx.Viper.SetConfigType("toml")
|
||||
ctx.Viper.SetConfigName("app")
|
||||
ctx.Viper.AddConfigPath(configPath)
|
||||
if err := ctx.Viper.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("failed to read in app.toml: %w", err)
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
Reference in New Issue
Block a user