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 29 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9205](https://github.com/cosmos/cosmos-sdk/pull/9205) Improve readability in `abci` handleQueryP2P
* [\#9314](https://github.com/cosmos/cosmos-sdk/pull/9314) Update Rosetta SDK to upstream's latest release.


### Features

* [\#8077](https://github.com/cosmos/cosmos-sdk/pull/8077) Added support for grpc-web, enabling browsers to communicate with a chain's gRPC server
Expand Down Expand Up @@ -127,6 +128,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (store) [\#8790](https://github.com/cosmos/cosmos-sdk/pull/8790) Reduce gas costs by 10x for transient store operations.
* (x/bank) [\#9051](https://github.com/cosmos/cosmos-sdk/pull/9051) Supply value is stored as `sdk.Int` rather than `string`.


### CLI Breaking Changes

* [\#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 in app.toml


### Improvements

* (baseapp) [\#9578](https://github.com/cosmos/cosmos-sdk/pull/9578) Return `Baseapp`'s `trace` value for logging error stack traces.
Expand Down
10 changes: 10 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
Expand Down Expand Up @@ -310,3 +311,12 @@ func GetConfig(v *viper.Viper) Config {
},
}
}

// ValidateBasic returns an error if min-gas-prices field is empty in BaseConfig. Otherwise, it returns nil.
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 sdkerrors.ErrAppConfig.Wrap("set min gas price in app.toml or flag or env variable")
}

return nil
}
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
118 changes: 78 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,42 @@ 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"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

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, "", nil)
err := server.InterceptConfigsPreRunHandler(cmd, "", nil)
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 +113,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 +153,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 +172,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 +185,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 +200,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 +220,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 +286,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 +324,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 +340,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 +356,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 +372,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 +393,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, "", nil)
}
err = cmd.ExecuteContext(ctx)
require.Errorf(t, err, sdkerrors.ErrAppConfig.Error())
}
21 changes: 19 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,25 @@ func initAppConfig() (string, interface{}) {
WASM WASMConfig `mapstructure:"wasm"`
}

// Optionally allow the chain developer to overwrite the SDK's default
// server config.
srvCfg := serverconfig.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 simapp, we set the min gas prices to 0.
srvCfg.MinGasPrices = "0stake"
Comment on lines +101 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a chat with @aaronc last evening about this, we were looking around Viper.SetDefault, but this morning I noticed this new initAppConfig function introduced by @anilcse in #9550. And it seems to me like the perfect place for chain developers to set a default min gas price.

cc. @marbar3778

Copy link
Member

@tac0turtle tac0turtle Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome!! We should add a note in the docs, that @anilcse added, that this is possible.


customAppConfig := CustomAppConfig{
Config: *serverconfig.DefaultConfig(),
Config: *srvCfg,
WASM: WASMConfig{
LruSize: 1,
QueryGasLimit: 300000,
Expand Down Expand Up @@ -207,7 +224,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
3 changes: 3 additions & 0 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ var (
// ErrPanic is only set when we recover from a panic, so we know to
// redact potentially sensitive system info
ErrPanic = Register(UndefinedCodespace, 111222, "panic")

// ErrAppConfig defines an error occurred if min-gas-prices field in BaseConfig is empty.
ErrAppConfig = Register(RootCodespace, 40, "error in app.toml")
)

// Register returns an error instance that should be used as the base for
Expand Down