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

R4R: Support min fees in a localnet and fix gaiad config #3172

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ IMPROVEMENTS

* Gaia
* [\#3158](https://github.com/cosmos/cosmos-sdk/pull/3158) Validate slashing genesis
* [\#3172](https://github.com/cosmos/cosmos-sdk/pull/3172) Support minimum fees
in a local testnet.

* SDK
* [\#3093](https://github.com/cosmos/cosmos-sdk/issues/3093) Ante handler does no longer read all accounts in one go when processing signatures as signature
Expand All @@ -62,8 +64,9 @@ BUG FIXES
* Gaia CLI (`gaiacli`)

* Gaia

* \#3148 Fix `gaiad export` by adding a boolean to `NewGaiaApp` determining whether or not to load the latest version
* [\#3172](https://github.com/cosmos/cosmos-sdk/pull/3172) Fix parsing `gaiad.toml`
when it already exists.

* SDK

Expand Down
3 changes: 1 addition & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ func (app *BaseApp) initFromMainStore(mainKey *sdk.KVStoreKey) error {
return nil
}

// SetMinimumFees sets the minimum fees.
func (app *BaseApp) SetMinimumFees(fees sdk.Coins) { app.minimumFees = fees }
func (app *BaseApp) setMinimumFees(fees sdk.Coins) { app.minimumFees = fees }
alessio marked this conversation as resolved.
Show resolved Hide resolved

// NewContext returns a new Context with the correct store, the given header, and nil txBytes.
func (app *BaseApp) NewContext(isCheckTx bool, header abci.Header) sdk.Context {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func SetMinimumFees(minFees string) func(*BaseApp) {
if err != nil {
panic(fmt.Sprintf("invalid minimum fees: %v", err))
}
return func(bap *BaseApp) { bap.SetMinimumFees(fees) }
return func(bap *BaseApp) { bap.setMinimumFees(fees) }
}

func (app *BaseApp) SetName(name string) {
Expand Down
28 changes: 21 additions & 7 deletions cmd/gaia/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authtx "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/cosmos/cosmos-sdk/x/stake"
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
staketypes "github.com/cosmos/cosmos-sdk/x/stake/types"

"github.com/spf13/cobra"
"github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config"
tmconfig "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/types"
Expand All @@ -34,6 +35,7 @@ var (
flagNodeDaemonHome = "node-daemon-home"
flagNodeCliHome = "node-cli-home"
flagStartingIPAddress = "starting-ip-address"
flagMinimumFees = "minimum-fees"
)

const nodeDirPerm = 0755
Expand Down Expand Up @@ -76,13 +78,19 @@ Example:
cmd.Flags().String(flagStartingIPAddress, "192.168.0.1",
"Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)")

cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(
client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created",
)
cmd.Flags().String(
flagMinimumFees, fmt.Sprintf("1%s", staketypes.DefaultBondDenom), "Validator minimum fees",
)

return cmd
}

func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
func initTestnet(config *tmconfig.Config, cdc *codec.Codec) error {
var chainID string

outDir := viper.GetString(flagOutputDir)
numValidators := viper.GetInt(flagNumValidators)

Expand All @@ -95,6 +103,9 @@ func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
nodeIDs := make([]string, numValidators)
valPubKeys := make([]crypto.PubKey, numValidators)

gaiaConfig := srvconfig.DefaultConfig()
gaiaConfig.MinFees = viper.GetString(flagMinimumFees)

var (
accs []app.GenesisAccount
genFiles []string
Expand Down Expand Up @@ -181,14 +192,14 @@ func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
Address: addr,
Coins: sdk.Coins{
sdk.NewInt64Coin(fmt.Sprintf("%stoken", nodeDirName), 1000),
sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 150),
sdk.NewInt64Coin(staketypes.DefaultBondDenom, 500),
},
})

msg := stake.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 100),
sdk.NewInt64Coin(staketypes.DefaultBondDenom, 100),
stake.NewDescription(nodeDirName, "", "", ""),
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
)
Expand All @@ -213,6 +224,9 @@ func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
_ = os.RemoveAll(outDir)
return err
}

gaiaConfigFilePath := filepath.Join(nodeDir, "config/gaiad.toml")
srvconfig.WriteConfigFile(gaiaConfigFilePath, gaiaConfig)
}

if err := initGenFiles(cdc, chainID, accs, genFiles, numValidators); err != nil {
Expand Down Expand Up @@ -261,7 +275,7 @@ func initGenFiles(
}

func collectGenFiles(
cdc *codec.Codec, config *cfg.Config, chainID string,
cdc *codec.Codec, config *tmconfig.Config, chainID string,
monikers, nodeIDs []string, valPubKeys []crypto.PubKey,
numValidators int, outDir, nodeDirPrefix, nodeDaemonHomeName string,
) error {
Expand Down
4 changes: 2 additions & 2 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ var configTemplate *template.Template

func init() {
var err error
tmpl := template.New("cosmosConfigFileTemplate")
tmpl := template.New("gaiaConfigFileTemplate")
if configTemplate, err = tmpl.Parse(defaultConfigTemplate); err != nil {
panic(err)
}
}

// ParseConfig retrieves the default environment configuration for Cosmos.
// ParseConfig retrieves the default environment configuration for Gaia.
func ParseConfig() (*Config, error) {
conf := DefaultConfig()
err := viper.Unmarshal(conf)
Expand Down
17 changes: 7 additions & 10 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,15 @@ func interceptLoadConfig() (conf *cfg.Config, err error) {
conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary.
}

cosmosConfigFilePath := filepath.Join(rootDir, "config/gaiad.toml")
viper.SetConfigName("cosmos")
_ = viper.MergeInConfig()
var cosmosConf *config.Config
if _, err := os.Stat(cosmosConfigFilePath); os.IsNotExist(err) {
cosmosConf, _ := config.ParseConfig()
config.WriteConfigFile(cosmosConfigFilePath, cosmosConf)
// create a default gaia config file if it does not exist
gaiaConfigFilePath := filepath.Join(rootDir, "config/gaiad.toml")
if _, err := os.Stat(gaiaConfigFilePath); os.IsNotExist(err) {
gaiaConf, _ := config.ParseConfig()
config.WriteConfigFile(gaiaConfigFilePath, gaiaConf)
}

if cosmosConf == nil {
_, err = config.ParseConfig()
}
viper.SetConfigName("gaiad")
err = viper.MergeInConfig()

return
}
Expand Down