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

Server/simd: Viper Removal #6599

Merged
merged 23 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from 19 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
8 changes: 4 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {

tx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, 0, 0)
return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
}

var mode runTxMode
Expand All @@ -190,7 +190,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {

gInfo, result, err := app.runTx(mode, req.Tx, tx)
if err != nil {
return sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed)
return sdkerrors.ResponseCheckTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
}

return abci.ResponseCheckTx{
Expand All @@ -212,7 +212,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx

tx, err := app.txDecoder(req.Tx)
if err != nil {
return sdkerrors.ResponseDeliverTx(err, 0, 0)
return sdkerrors.ResponseDeliverTx(err, 0, 0, app.trace)
}

gInfo := sdk.GasInfo{}
Expand All @@ -228,7 +228,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx
gInfo, result, err := app.runTx(runTxModeDeliver, req.Tx, tx)
if err != nil {
resultStr = "failed"
return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed)
return sdkerrors.ResponseDeliverTx(err, gInfo.GasWanted, gInfo.GasUsed, app.trace)
}

return abci.ResponseDeliverTx{
Expand Down
7 changes: 7 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ type BaseApp struct { // nolint: maligned

// recovery handler for app.runTx method
runTxRecoveryMiddleware recoveryMiddleware

// trace set will return full stack traces for errors in ABCI Log field
trace bool
}

// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
Expand Down Expand Up @@ -276,6 +279,10 @@ func (app *BaseApp) setInterBlockCache(cache sdk.MultiStorePersistentCache) {
app.interBlockCache = cache
}

func (app *BaseApp) setTrace(trace bool) {
app.trace = trace
}

// Router returns the router of the BaseApp.
func (app *BaseApp) Router() sdk.Router {
if app.sealed {
Expand Down
5 changes: 5 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func SetHaltTime(haltTime uint64) func(*BaseApp) {
return func(bap *BaseApp) { bap.setHaltTime(haltTime) }
}

// SetTrace will turn on or off trace flag
func SetTrace(trace bool) func(*BaseApp) {
return func(app *BaseApp) { app.setTrace(trace) }
}

// SetInterBlockCache provides a BaseApp option function that sets the
// inter-block cache.
func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) {
Expand Down
46 changes: 23 additions & 23 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func DefaultConfig() *Config {
}

// GetConfig returns a fully parsed Config object.
func GetConfig() Config {
globalLabelsRaw := viper.Get("telemetry.global-labels").([]interface{})
func GetConfig(v *viper.Viper) Config {
globalLabelsRaw := v.Get("telemetry.global-labels").([]interface{})
globalLabels := make([][]string, 0, len(globalLabelsRaw))
for _, glr := range globalLabelsRaw {
labelsRaw := glr.([]interface{})
Expand All @@ -150,32 +150,32 @@ func GetConfig() Config {

return Config{
BaseConfig: BaseConfig{
MinGasPrices: viper.GetString("minimum-gas-prices"),
InterBlockCache: viper.GetBool("inter-block-cache"),
Pruning: viper.GetString("pruning"),
PruningKeepRecent: viper.GetString("pruning-keep-recent"),
PruningKeepEvery: viper.GetString("pruning-keep-every"),
PruningInterval: viper.GetString("pruning-interval"),
HaltHeight: viper.GetUint64("halt-height"),
HaltTime: viper.GetUint64("halt-time"),
MinGasPrices: v.GetString("minimum-gas-prices"),
InterBlockCache: v.GetBool("inter-block-cache"),
Pruning: v.GetString("pruning"),
PruningKeepRecent: v.GetString("pruning-keep-recent"),
PruningKeepEvery: v.GetString("pruning-keep-every"),
PruningInterval: v.GetString("pruning-interval"),
HaltHeight: v.GetUint64("halt-height"),
HaltTime: v.GetUint64("halt-time"),
},
Telemetry: telemetry.Config{
ServiceName: viper.GetString("telemetry.service-name"),
Enabled: viper.GetBool("telemetry.enabled"),
EnableHostname: viper.GetBool("telemetry.enable-hostname"),
EnableHostnameLabel: viper.GetBool("telemetry.enable-hostname-label"),
EnableServiceLabel: viper.GetBool("telemetry.enable-service-label"),
PrometheusRetentionTime: viper.GetInt64("telemetry.prometheus-retention-time"),
ServiceName: v.GetString("telemetry.service-name"),
Enabled: v.GetBool("telemetry.enabled"),
EnableHostname: v.GetBool("telemetry.enable-hostname"),
EnableHostnameLabel: v.GetBool("telemetry.enable-hostname-label"),
EnableServiceLabel: v.GetBool("telemetry.enable-service-label"),
PrometheusRetentionTime: v.GetInt64("telemetry.prometheus-retention-time"),
GlobalLabels: globalLabels,
},
API: APIConfig{
Enable: viper.GetBool("api.enable"),
Address: viper.GetString("api.address"),
MaxOpenConnections: viper.GetUint("api.max-open-connections"),
RPCReadTimeout: viper.GetUint("api.rpc-read-timeout"),
RPCWriteTimeout: viper.GetUint("api.rpc-write-timeout"),
RPCMaxBodyBytes: viper.GetUint("api.rpc-max-body-bytes"),
EnableUnsafeCORS: viper.GetBool("api.enabled-unsafe-cors"),
Enable: v.GetBool("api.enable"),
Address: v.GetString("api.address"),
MaxOpenConnections: v.GetUint("api.max-open-connections"),
RPCReadTimeout: v.GetUint("api.rpc-read-timeout"),
RPCWriteTimeout: v.GetUint("api.rpc-write-timeout"),
RPCMaxBodyBytes: v.GetUint("api.rpc-max-body-bytes"),
EnableUnsafeCORS: v.GetBool("api.enabled-unsafe-cors"),
},
}
}
4 changes: 2 additions & 2 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func init() {

// ParseConfig retrieves the default environment configuration for the
// application.
func ParseConfig() (*Config, error) {
func ParseConfig(v *viper.Viper) (*Config, error) {
conf := DefaultConfig()
err := viper.Unmarshal(conf)
err := v.Unmarshal(conf)

return conf, err
}
Expand Down
3 changes: 2 additions & 1 deletion server/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
Expand All @@ -27,7 +28,7 @@ type (

// AppCreator is a function that allows us to lazily initialize an
// application using various configurations.
AppCreator func(log.Logger, dbm.DB, io.Writer) Application
AppCreator func(log.Logger, dbm.DB, io.Writer, *viper.Viper) Application
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

// AppExporter is a function that dumps all app state to
// JSON-serializable structure and returns the current validator set.
Expand Down
15 changes: 7 additions & 8 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -29,9 +28,9 @@ func ExportCmd(ctx *Context, cdc codec.JSONMarshaler, appExporter AppExporter) *
Short: "Export state to JSON",
RunE: func(cmd *cobra.Command, args []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(flags.FlagHome))

traceWriterFile := viper.GetString(flagTraceStore)
homeDir, _ := cmd.Flags().GetString(flags.FlagHome)
config.SetRoot(homeDir)

db, err := openDB(config.RootDir)
if err != nil {
Expand All @@ -52,14 +51,15 @@ func ExportCmd(ctx *Context, cdc codec.JSONMarshaler, appExporter AppExporter) *
return nil
}

traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore)
traceWriter, err := openTraceWriter(traceWriterFile)
if err != nil {
return err
}

height := viper.GetInt64(flagHeight)
forZeroHeight := viper.GetBool(flagForZeroHeight)
jailWhiteList := viper.GetStringSlice(flagJailWhitelist)
height, _ := cmd.Flags().GetInt64(flagHeight)
forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight)
jailWhiteList, _ := cmd.Flags().GetStringSlice(flagJailWhitelist)

appState, validators, cp, err := appExporter(ctx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
if err != nil {
Expand Down Expand Up @@ -98,11 +98,10 @@ func ExportCmd(ctx *Context, cdc codec.JSONMarshaler, appExporter AppExporter) *
},
}

cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)")
cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
cmd.Flags().StringSlice(flagJailWhitelist, []string{}, "List of validators to not jail state export")
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.OutOrStderr())

return cmd
}
11 changes: 3 additions & 8 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package server
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"path"
"testing"

"github.com/stretchr/testify/require"

"github.com/spf13/viper"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -62,12 +61,8 @@ func TestExportCmd_ConsensusParams(t *testing.T) {

output := &bytes.Buffer{}
cmd.SetOut(output)

viper.Set(flags.FlagHome, tempDir)
err = cmd.RunE(cmd, []string{})
if err != nil {
t.Errorf("error: %s", err)
}
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.Execute())

var exportedGenDoc tmtypes.GenesisDoc
err = app.Codec().UnmarshalJSON(output.Bytes(), &exportedGenDoc)
Expand Down
8 changes: 4 additions & 4 deletions server/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
// GetPruningOptionsFromFlags parses command flags and returns the correct
// PruningOptions. If a pruning strategy is provided, that will be parsed and
// returned, otherwise, it is assumed custom pruning options are provided.
func GetPruningOptionsFromFlags() (types.PruningOptions, error) {
strategy := strings.ToLower(viper.GetString(FlagPruning))
func GetPruningOptionsFromFlags(v *viper.Viper) (types.PruningOptions, error) {
strategy := strings.ToLower(v.GetString(FlagPruning))

switch strategy {
case types.PruningOptionDefault, types.PruningOptionNothing, types.PruningOptionEverything:
return types.NewPruningOptionsFromString(strategy), nil

case types.PruningOptionCustom:
opts := types.NewPruningOptions(
viper.GetUint64(FlagPruningKeepRecent),
viper.GetUint64(FlagPruningKeepEvery), viper.GetUint64(FlagPruningInterval),
v.GetUint64(FlagPruningKeepRecent),
v.GetUint64(FlagPruningKeepEvery), v.GetUint64(FlagPruningInterval),
)

if err := opts.Validate(); err != nil {
Expand Down
33 changes: 21 additions & 12 deletions server/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ import (
func TestGetPruningOptionsFromFlags(t *testing.T) {
tests := []struct {
name string
initParams func()
initParams func() *viper.Viper
expectedOptions types.PruningOptions
wantErr bool
}{
{
name: FlagPruning,
initParams: func() {
viper.Set(FlagPruning, types.PruningOptionNothing)
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionNothing)
return v
},
expectedOptions: types.PruneNothing,
},
{
name: "custom pruning options",
initParams: func() {
viper.Set(FlagPruning, types.PruningOptionCustom)
viper.Set(FlagPruningKeepRecent, 1234)
viper.Set(FlagPruningKeepEvery, 4321)
viper.Set(FlagPruningInterval, 10)
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionCustom)
v.Set(FlagPruningKeepRecent, 1234)
v.Set(FlagPruningKeepEvery, 4321)
v.Set(FlagPruningInterval, 10)

return v
},
expectedOptions: types.PruningOptions{
KeepRecent: 1234,
Expand All @@ -38,8 +43,12 @@ func TestGetPruningOptionsFromFlags(t *testing.T) {
},
},
{
name: types.PruningOptionDefault,
initParams: func() {},
name: types.PruningOptionDefault,
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionDefault)
return v
},
expectedOptions: types.PruneDefault,
},
}
Expand All @@ -50,9 +59,9 @@ func TestGetPruningOptionsFromFlags(t *testing.T) {
t.Run(tt.name, func(j *testing.T) {
viper.Reset()
viper.SetDefault(FlagPruning, types.PruningOptionDefault)
tt.initParams()
v := tt.initParams()

opts, err := GetPruningOptionsFromFlags()
opts, err := GetPruningOptionsFromFlags(v)
if tt.wantErr {
require.Error(t, err)
return
Expand Down
Loading