-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate min gas price option for txes with high gas wanted (#777)
- Loading branch information
1 parent
6e7d32b
commit f0842b9
Showing
7 changed files
with
142 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/spf13/cast" | ||
) | ||
|
||
// If Options are not set in a config somewhere, | ||
// use defaults to preserve functionality with old node software | ||
|
||
// TODO: Bump after next minor version. (in 6.2+) | ||
var DefaultMinGasPriceForArbitrageTx = sdk.ZeroDec() | ||
var DefaultMinGasPriceForHighGasTx = sdk.ZeroDec() | ||
var DefaultMaxGasWantedPerTx = uint64(25 * 1000 * 1000) | ||
var DefaultHighGasTxThreshold = uint64(1 * 1000 * 1000) | ||
|
||
type MempoolFeeOptions struct { | ||
MaxGasWantedPerTx uint64 | ||
MinGasPriceForArbitrageTx sdk.Dec | ||
HighGasTxThreshold uint64 | ||
MinGasPriceForHighGasTx sdk.Dec | ||
} | ||
|
||
func NewDefaultMempoolFeeOptions() MempoolFeeOptions { | ||
return MempoolFeeOptions{ | ||
MaxGasWantedPerTx: DefaultMaxGasWantedPerTx, | ||
MinGasPriceForArbitrageTx: DefaultMinGasPriceForArbitrageTx.Clone(), | ||
HighGasTxThreshold: DefaultHighGasTxThreshold, | ||
MinGasPriceForHighGasTx: DefaultMinGasPriceForHighGasTx.Clone(), | ||
} | ||
} | ||
|
||
func NewMempoolFeeOptions(opts servertypes.AppOptions) MempoolFeeOptions { | ||
return MempoolFeeOptions{ | ||
MaxGasWantedPerTx: parseMaxGasWantedPerTx(opts), | ||
MinGasPriceForArbitrageTx: parseMinGasPriceForArbitrageTx(opts), | ||
HighGasTxThreshold: DefaultHighGasTxThreshold, | ||
MinGasPriceForHighGasTx: parseMinGasPriceForHighGasTx(opts), | ||
} | ||
} | ||
|
||
func parseMaxGasWantedPerTx(opts servertypes.AppOptions) uint64 { | ||
valueInterface := opts.Get("osmosis-mempool.max-gas-wanted-per-tx") | ||
if valueInterface == nil { | ||
return DefaultMaxGasWantedPerTx | ||
} | ||
value, err := cast.ToUint64E(valueInterface) | ||
if err != nil { | ||
panic("invalidly configured osmosis-mempool.max-gas-wanted-per-tx") | ||
} | ||
return value | ||
} | ||
|
||
func parseMinGasPriceForArbitrageTx(opts servertypes.AppOptions) sdk.Dec { | ||
return parseDecFromConfig(opts, "arbitrage-min-gas-fee", DefaultMinGasPriceForArbitrageTx.Clone()) | ||
} | ||
|
||
func parseMinGasPriceForHighGasTx(opts servertypes.AppOptions) sdk.Dec { | ||
return parseDecFromConfig(opts, "min-gas-price-for-high-gas-tx", DefaultMinGasPriceForHighGasTx.Clone()) | ||
} | ||
|
||
func parseDecFromConfig(opts servertypes.AppOptions, optName string, defaultValue sdk.Dec) sdk.Dec { | ||
valueInterface := opts.Get("osmosis-mempool." + optName) | ||
value := defaultValue | ||
if valueInterface != nil { | ||
valueStr, ok := valueInterface.(string) | ||
if !ok { | ||
panic("invalidly configured osmosis-mempool." + optName) | ||
} | ||
var err error | ||
// pre-pend 0 to allow the config to start with a decimal, e.g. ".01" | ||
value, err = sdk.NewDecFromStr("0" + valueStr) | ||
if err != nil { | ||
panic(fmt.Errorf("invalidly configured osmosis-mempool.%v, err= %v", optName, err)) | ||
} | ||
} | ||
return value | ||
} |