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

feat: Non-zero Default Fees #9371

Merged
merged 31 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ef14cc8
draft
cyberbono3 May 20, 2021
c85f811
add MinGasPrices check in interceptConfigs
cyberbono3 May 21, 2021
34e7484
Update server/start.go
cyberbono3 May 27, 2021
57ed05c
revert changes in interceptConfigs in server/util.go
cyberbono3 May 27, 2021
2d0e734
implement config.ValidateBasic method and call it within startInProcess
cyberbono3 May 27, 2021
4ec4af0
fix ValidateBasic
cyberbono3 May 27, 2021
e52ee4f
run gofmt
cyberbono3 May 28, 2021
04bf221
minor fixes
cyberbono3 May 28, 2021
59c615f
gofmt
cyberbono3 May 28, 2021
345e531
uncapitalize error string
cyberbono3 May 28, 2021
1c6ea9c
draft TestStartCmdwithEmptyandNonEmptyMinGasPrices
cyberbono3 Jun 9, 2021
99ef5da
WIP fix panic in appCreator in startInProcess
cyberbono3 Jun 14, 2021
174fb8d
WIP appCreator argument in server.startInProcess
cyberbono3 Jun 14, 2021
3fe4b98
use a.NewApp as argument in server.StartCmd
cyberbono3 Jun 14, 2021
4c126fc
could not read GenesisDoc file error
cyberbono3 Jun 15, 2021
b0c80b4
Fix test
amaury1093 Jun 16, 2021
06e9d47
fix lint issues
cyberbono3 Jun 16, 2021
8da8817
revert unneeded changes
cyberbono3 Jun 16, 2021
5e2ce12
add changelog entry
cyberbono3 Jun 16, 2021
2f71a76
revert unnecessary change
cyberbono3 Jun 17, 2021
3bd6fda
declare ErrSetMinGasPrice
cyberbono3 Jun 17, 2021
122a752
Update server/rosetta/lib/errors/errors_test.go
cyberbono3 Jun 17, 2021
64c0c30
add docs to exported stuff
cyberbono3 Jun 22, 2021
7496080
create CLI Breaking Changes section in CHANGELOG.md
cyberbono3 Jun 23, 2021
af31bbf
merge master to my branch
cyberbono3 Jun 23, 2021
40eb4eb
fix failed test
cyberbono3 Jun 24, 2021
58d180c
apply robert suggestion
cyberbono3 Jun 24, 2021
7694dbd
Allow chain devs to set min gas prices
amaury1093 Jun 25, 2021
aa9b055
Merge branch 'master' into cyberbono3/non-zero-default-fees
amaury1093 Jun 25, 2021
81d7718
Add docs
amaury1093 Jun 25, 2021
d77b083
make rosetta-data
amaury1093 Jun 25, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9235](https://github.com/cosmos/cosmos-sdk/pull/9235) CreateMembershipProof/CreateNonMembershipProof now returns an error
if input key is empty, or input data contains empty key.
* [\#9314](https://github.com/cosmos/cosmos-sdk/pull/9314) Update Rosetta SDK to upstream's latest release.
* [\#9371](https://github.com/cosmos/cosmos-sdk/pull/9371) Non-zero default fees/Server will error if there's an empty value for min-gas-price
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

### Features

Expand Down
11 changes: 11 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"errors"
"fmt"
"strings"

Expand All @@ -21,6 +22,8 @@ const (
DefaultGRPCWebAddress = "0.0.0.0:9091"
)

var ErrSetMinGasPrice = errors.New("please set min gas price in app.toml or flag or env var")
cyberbono3 marked this conversation as resolved.
Show resolved Hide resolved
cyberbono3 marked this conversation as resolved.
Show resolved Hide resolved

// BaseConfig defines the server's basic configuration
type BaseConfig struct {
// The minimum gas prices a validator is willing to accept for processing a
Expand Down Expand Up @@ -306,3 +309,11 @@ func GetConfig(v *viper.Viper) Config {
},
}
}

func (c Config) ValidateBasic() error {
cyberbono3 marked this conversation as resolved.
Show resolved Hide resolved
if c.BaseConfig.MinGasPrices == "" {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return ErrSetMinGasPrice
}

return nil
}
2 changes: 1 addition & 1 deletion server/rosetta/lib/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ func (e *MyError) Error() string {
}
func (e *MyError) Is(err error) bool {
return true
}
}
cyberbono3 marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return err
}

config := config.GetConfig(ctx.Viper)
if err := config.ValidateBasic(); err != nil {
cyberbono3 marked this conversation as resolved.
Show resolved Hide resolved
return err
}

app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper)

nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
Expand Down Expand Up @@ -273,8 +278,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
ctx.Logger.Debug("initialization: tmNode started")

config := config.GetConfig(ctx.Viper)

// Add the tx service to the gRPC router. We only need to register this
// service if API or gRPC is enabled, and avoid doing so in the general
// case, because it spawns a new local tendermint RPC client.
Expand Down
117 changes: 77 additions & 40 deletions server/util_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package server_test

import (
"context"
Expand All @@ -11,35 +11,41 @@ import (
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

"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/config"
"github.com/cosmos/cosmos-sdk/simapp"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)

var CancelledInPreRun = errors.New("Canelled in prerun")
var cancelledInPreRun = errors.New("Cancelled in prerun")

// Used in each test to run the function under test via Cobra
// but to always halt the command
func preRunETestImpl(cmd *cobra.Command, args []string) error {
err := InterceptConfigsPreRunHandler(cmd)
err := server.InterceptConfigsPreRunHandler(cmd)
if err != nil {
return err
}

return CancelledInPreRun
return cancelledInPreRun
}

func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T) {
tempDir := t.TempDir()
cmd := StartCmd(nil, "/foobar")
cmd := server.StartCmd(nil, "/foobar")
if err := cmd.Flags().Set(flags.FlagHome, tempDir); err != nil {
t.Fatalf("Could not set home flag [%T] %v", err, err)
}

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)
if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand Down Expand Up @@ -106,17 +112,17 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) {
t.Fatalf("Failed closing config.toml: %v", err)
}

cmd := StartCmd(nil, "/foobar")
cmd := server.StartCmd(nil, "/foobar")
if err := cmd.Flags().Set(flags.FlagHome, tempDir); err != nil {
t.Fatalf("Could not set home flag [%T] %v", err, err)
}

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand Down Expand Up @@ -146,14 +152,14 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) {
if err := writer.Close(); err != nil {
t.Fatalf("Failed closing app.toml: %v", err)
}
cmd := StartCmd(nil, tempDir)
cmd := server.StartCmd(nil, tempDir)

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -165,7 +171,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) {
func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) {
const testAddr = "tcp://127.1.2.3:12345"
tempDir := t.TempDir()
cmd := StartCmd(nil, "/foobar")
cmd := server.StartCmd(nil, "/foobar")

if err := cmd.Flags().Set(flags.FlagHome, tempDir); err != nil {
t.Fatalf("Could not set home flag [%T] %v", err, err)
Expand All @@ -178,10 +184,10 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) {

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -193,7 +199,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) {
func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) {
const testAddr = "tcp://127.1.2.3:12345"
tempDir := t.TempDir()
cmd := StartCmd(nil, "/foobar")
cmd := server.StartCmd(nil, "/foobar")
if err := cmd.Flags().Set(flags.FlagHome, tempDir); err != nil {
t.Fatalf("Could not set home flag [%T] %v", err, err)
}
Expand All @@ -213,10 +219,10 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) {

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand Down Expand Up @@ -279,7 +285,7 @@ func newPrecedenceCommon(t *testing.T) precedenceCommon {
})

// Set up the command object that is used in this test
retval.cmd = StartCmd(nil, tempDir)
retval.cmd = server.StartCmd(nil, tempDir)
retval.cmd.PreRunE = preRunETestImpl

return retval
Expand Down Expand Up @@ -317,10 +323,10 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) {
testCommon := newPrecedenceCommon(t)
testCommon.setAll(t, &TestAddrExpected, &TestAddrNotExpected, &TestAddrNotExpected)

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := testCommon.cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -333,10 +339,10 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) {
testCommon := newPrecedenceCommon(t)
testCommon.setAll(t, nil, &TestAddrExpected, &TestAddrNotExpected)

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := testCommon.cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -349,10 +355,10 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) {
testCommon := newPrecedenceCommon(t)
testCommon.setAll(t, nil, nil, &TestAddrExpected)

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := testCommon.cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -365,10 +371,10 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) {
testCommon := newPrecedenceCommon(t)
// Do not set anything

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)

if err := testCommon.cmd.ExecuteContext(ctx); err != CancelledInPreRun {
if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun {
t.Fatalf("function failed with [%T] %v", err, err)
}

Expand All @@ -386,16 +392,47 @@ func TestInterceptConfigsWithBadPermissions(t *testing.T) {
if err := os.Mkdir(subDir, 0600); err != nil {
t.Fatalf("Failed to create sub directory: %v", err)
}
cmd := StartCmd(nil, "/foobar")
cmd := server.StartCmd(nil, "/foobar")
if err := cmd.Flags().Set(flags.FlagHome, subDir); err != nil {
t.Fatalf("Could not set home flag [%T] %v", err, err)
}

cmd.PreRunE = preRunETestImpl

serverCtx := &Context{}
ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx)
serverCtx := &server.Context{}
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)
if err := cmd.ExecuteContext(ctx); !os.IsPermission(err) {
t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err)
}
}

func TestEmptyMinGasPrices(t *testing.T) {
tempDir := t.TempDir()
err := os.Mkdir(filepath.Join(tempDir, "config"), os.ModePerm)
require.NoError(t, err)
encCfg := simapp.MakeTestEncodingConfig()

// Run InitCmd to create necessary config files.
clientCtx := client.Context{}.WithHomeDir(tempDir).WithJSONCodec(encCfg.Marshaler)
serverCtx := server.NewDefaultContext()
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
cmd := genutilcli.InitCmd(simapp.ModuleBasics, tempDir)
cmd.SetArgs([]string{"appnode-test"})
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)

// Modify app.toml.
appCfgTempFilePath := filepath.Join(tempDir, "config", "app.toml")
appConf := config.DefaultConfig()
appConf.BaseConfig.MinGasPrices = ""
config.WriteConfigFile(appCfgTempFilePath, appConf)

// Run StartCmd.
cmd = server.StartCmd(nil, tempDir)
cmd.PreRunE = func(cmd *cobra.Command, _ []string) error {
return server.InterceptConfigsPreRunHandler(cmd)
}
err = cmd.ExecuteContext(ctx)
require.Errorf(t, err, config.ErrSetMinGasPrice.Error())
}
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ type appCreator struct {
encCfg params.EncodingConfig
}

// newApp is an AppCreator
// 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

Expand Down
4 changes: 4 additions & 0 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func startInProcess(cfg Config, val *Validator) error {
tmCfg := val.Ctx.Config
tmCfg.Instrumentation.Prometheus = false

if err := val.AppConfig.ValidateBasic(); err != nil {
return err
}

nodeKey, err := p2p.LoadOrGenNodeKey(tmCfg.NodeKeyFile())
if err != nil {
return err
Expand Down