-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The minimum gas price configuration is a mechanism to prevent spam and ensure that only transactions with sufficient fees are processed. It achieves this by setting a minimum cost per unit of gas that a transaction must meet to be included in the mempool. The following condition is checked by the validator: the gas and fees provided by the user must meet this condition before the transaction can be included in the mempool and subsequently processed by the VM. Gas Fee => Gas Wanted x Min Gas Prices A node operator can set the min gas prices as following `gnoland config set application.min_gas_prices "1000ugnot/1gas" ` Co-authored-by: Nathan Toups <[email protected]>
- Loading branch information
Showing
8 changed files
with
97 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/gnolang/gno/tm2/pkg/errors" | ||
"github.com/gnolang/gno/tm2/pkg/std" | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Application Config | ||
|
||
// AppConfig defines the configuration options for the Application | ||
type AppConfig struct { | ||
// Lowest gas prices accepted by a validator in the form of "100tokenA/3gas;10tokenB/5gas" separated by semicolons | ||
MinGasPrices string `json:"min_gas_prices" toml:"min_gas_prices" comment:"Lowest gas prices accepted by a validator"` | ||
} | ||
|
||
// DefaultAppConfig returns a default configuration for the application | ||
func DefaultAppConfig() *AppConfig { | ||
return &AppConfig{ | ||
MinGasPrices: "", | ||
} | ||
} | ||
|
||
// ValidateBasic performs basic validation, checking format and param bounds, etc., and | ||
// returns an error if any check fails. | ||
func (cfg *AppConfig) ValidateBasic() error { | ||
if cfg.MinGasPrices == "" { | ||
return nil | ||
} | ||
if _, err := std.ParseGasPrices(cfg.MinGasPrices); err != nil { | ||
return errors.Wrap(err, "invalid min gas prices") | ||
} | ||
|
||
return nil | ||
} |
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,36 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidateAppConfig(t *testing.T) { | ||
c := DefaultAppConfig() | ||
c.MinGasPrices = "" // empty | ||
|
||
testCases := []struct { | ||
testName string | ||
minGasPrices string | ||
expectErr bool | ||
}{ | ||
{"invalid min gas prices invalid gas", "10token/1", true}, | ||
{"invalid min gas prices invalid gas denom", "9token/0gs", true}, | ||
{"invalid min gas prices zero gas", "10token/0gas", true}, | ||
{"invalid min gas prices no gas", "10token/gas", true}, | ||
{"invalid min gas prices negtive gas", "10token/-1gas", true}, | ||
{"invalid min gas prices invalid denom", "10$token/2gas", true}, | ||
{"invalid min gas prices invalid second denom", "10token/2gas;10/3gas", true}, | ||
{"valid min gas prices", "10foo/3gas;5bar/3gas", false}, | ||
} | ||
|
||
cfg := DefaultAppConfig() | ||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.testName, func(t *testing.T) { | ||
cfg.MinGasPrices = tc.minGasPrices | ||
assert.Equal(t, tc.expectErr, cfg.ValidateBasic() != nil) | ||
}) | ||
} | ||
} |
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