-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support min fees-based anti spam strategy
Create cosmos.toml configuration file and handle minimum_fees setting/flag to provide validators with a simple and flexible anti-spam mechanism. Closes: #1921
- Loading branch information
Alessio Treglia
committed
Sep 13, 2018
1 parent
5bf9401
commit e5edb2a
Showing
11 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
cfg := DefaultConfig() | ||
require.True(t, cfg.MinimumFees().IsZero()) | ||
} | ||
|
||
func TestSetMinimumFees(t *testing.T) { | ||
cfg := DefaultConfig() | ||
cfg.SetMinimumFees(sdk.Coins{sdk.NewCoin("foo", sdk.NewInt(100))}) | ||
require.Equal(t, "100foo", cfg.MinFees) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
import ( | ||
"bytes" | ||
"text/template" | ||
|
||
"github.com/spf13/viper" | ||
cmn "github.com/tendermint/tendermint/libs/common" | ||
) | ||
|
||
var configTemplate *template.Template | ||
|
||
func init() { | ||
var err error | ||
if configTemplate, err = template.New("cosmosConfigFileTemplate").Parse(defaultConfigTemplate); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// ParseConfig retrieves the default environment configuration for Cosmos | ||
func ParseConfig() (*Config, error) { | ||
conf := DefaultConfig() | ||
err := viper.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) | ||
} | ||
|
||
cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0644) | ||
} | ||
|
||
const defaultConfigTemplate = `# This is a TOML config file. | ||
# For more information, see https://github.com/toml-lang/toml | ||
##### main base config options ##### | ||
# Validators reject any tx from the mempool with less than the minimum fee per gas. | ||
minimum_fees = "{{ .BaseConfig.MinFees }}" | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters