/
options.go
86 lines (73 loc) · 2.71 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package types
import (
"fmt"
"github.com/spf13/cast"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// If Options are not set in a config somewhere,
// use defaults to preserve functionality with old node software
// DefaultMinGasPriceForArbitrageTx represents minimum gas price
// for arbitrage transactions.
var DefaultMinGasPriceForArbitrageTx = sdk.ZeroDec()
var (
DefaultMinGasPriceForHighGasTx = sdk.ZeroDec()
DefaultMaxGasWantedPerTx = uint64(25 * 1000 * 1000)
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
}