/
params.go
101 lines (83 loc) · 3.06 KB
/
params.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package types
import (
fmt "fmt"
"cosmossdk.io/math"
)
// MaxBlockUtilizationRatio is the maximum ratio of the max block size to the target block size. This
// can be trivially understood to be the maximum base fee increase that can occur in between
// blocks. This is a constant that is used to prevent the base fee from increasing too quickly.
const MaxBlockUtilizationRatio = 10
// NewParams instantiates a new EIP-1559 Params object. This params object is utilized
// to implement both the base EIP-1559 fee and AIMD EIP-1559 fee market implementations.
func NewParams(
window uint64,
alpha math.LegacyDec,
beta math.LegacyDec,
theta math.LegacyDec,
delta math.LegacyDec,
targetBlockSize uint64,
maxBlockSize uint64,
minBaseFee math.Int,
minLearingRate math.LegacyDec,
maxLearningRate math.LegacyDec,
feeDenom string,
enabled bool,
) Params {
return Params{
Alpha: alpha,
Beta: beta,
Theta: theta,
Delta: delta,
MinBaseFee: minBaseFee,
MinLearningRate: minLearingRate,
MaxLearningRate: maxLearningRate,
TargetBlockUtilization: targetBlockSize,
MaxBlockUtilization: maxBlockSize,
Window: window,
FeeDenom: feeDenom,
Enabled: enabled,
}
}
// ValidateBasic performs basic validation on the parameters.
func (p *Params) ValidateBasic() error {
if p.Window == 0 {
return fmt.Errorf("window cannot be zero")
}
if p.Alpha.IsNil() || p.Alpha.IsNegative() {
return fmt.Errorf("alpha cannot be nil must be between [0, inf)")
}
if p.Beta.IsNil() || p.Beta.IsNegative() || p.Beta.GT(math.LegacyOneDec()) {
return fmt.Errorf("beta cannot be nil and must be between [0, 1]")
}
if p.Theta.IsNil() || p.Theta.IsNegative() || p.Theta.GT(math.LegacyOneDec()) {
return fmt.Errorf("theta cannot be nil and must be between [0, 1]")
}
if p.Delta.IsNil() || p.Delta.IsNegative() {
return fmt.Errorf("delta cannot be nil and must be between [0, inf)")
}
if p.TargetBlockUtilization == 0 {
return fmt.Errorf("target block size cannot be zero")
}
if p.TargetBlockUtilization > p.MaxBlockUtilization {
return fmt.Errorf("target block size cannot be greater than max block size")
}
if p.MaxBlockUtilization/p.TargetBlockUtilization > MaxBlockUtilizationRatio {
return fmt.Errorf("max block size cannot be greater than target block size times %d", MaxBlockUtilizationRatio)
}
if p.MinBaseFee.IsNil() || !p.MinBaseFee.GTE(math.ZeroInt()) {
return fmt.Errorf("min base fee cannot be nil and must be greater than or equal to zero")
}
if p.MaxLearningRate.IsNil() || p.MinLearningRate.IsNegative() {
return fmt.Errorf("min learning rate cannot be negative or nil")
}
if p.MaxLearningRate.IsNil() || p.MaxLearningRate.IsNegative() {
return fmt.Errorf("max learning rate cannot be negative or nil")
}
if p.MinLearningRate.GT(p.MaxLearningRate) {
return fmt.Errorf("min learning rate cannot be greater than max learning rate")
}
if p.FeeDenom == "" {
return fmt.Errorf("fee denom must be set")
}
return nil
}