-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 mechanism
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 19, 2018
1 parent
c6a3928
commit 62387d9
Showing
16 changed files
with
323 additions
and
46 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
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,46 @@ | ||
package config | ||
|
||
import ( | ||
"bytes" | ||
"text/template" | ||
|
||
"github.com/spf13/viper" | ||
cmn "github.com/tendermint/tendermint/libs/common" | ||
) | ||
|
||
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 }}" | ||
` | ||
|
||
var configTemplate *template.Template | ||
|
||
func init() { | ||
var err error | ||
tmpl := template.New("cosmosConfigFileTemplate") | ||
if configTemplate, err = tmpl.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) | ||
} |
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
Oops, something went wrong.