/
eip1559_aimd.go
98 lines (82 loc) · 3.77 KB
/
eip1559_aimd.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
package types
import "cosmossdk.io/math"
// Note: The following constants are the default values for the AIMD EIP-1559
// fee market implementation. This implements an adjustable learning rate
// algorithm that is not present in the base EIP-1559 implementation.
var (
// DefaultAIMDWindow is the default window size for the sliding window
// used to calculate the base fee.
DefaultAIMDWindow uint64 = 8
// DefaultAIMDAlpha is the default alpha value for the learning
// rate calculation. This value determines how much we want to additively
// increase the learning rate when the target block size is exceeded.
DefaultAIMDAlpha = math.LegacyMustNewDecFromStr("0.025")
// DefaultAIMDBeta is the default beta value for the learning rate
// calculation. This value determines how much we want to multiplicatively
// decrease the learning rate when the target utilization is not met.
DefaultAIMDBeta = math.LegacyMustNewDecFromStr("0.95")
// DefaultAIMDTheta is the default threshold for determining whether
// to increase or decrease the learning rate. In this case, we increase
// the learning rate if the block utilization within the window is greater
// than 0.75 or less than 0.25. Otherwise, we multiplicatively decrease
// the learning rate.
DefaultAIMDTheta = math.LegacyMustNewDecFromStr("0.25")
// DefaultAIMDDelta is the default delta value for how much we additively
// increase or decrease the base fee when the net block utilization within
// the window is not equal to the target utilization.
DefaultAIMDDelta = math.LegacyMustNewDecFromStr("0.0")
// DefaultAIMDTargetBlockSize is the default target block utilization. This
// is the default on Ethereum. This denominated in units of gas consumed in
// a block.
DefaultAIMDTargetBlockSize uint64 = 15_000_000
// DefaultAIMDMaxBlockSize is the default maximum block utilization.
// This is the default on Ethereum. This denominated in units of gas
// consumed in a block.
DefaultAIMDMaxBlockSize uint64 = 30_000_000
// DefaultAIMDMinBaseFee is the default minimum base fee. This is the
// default on Ethereum. Note that ethereum is denominated in 1e18 wei.
// Cosmos chains will likely want to change this to 1e6.
DefaultAIMDMinBaseFee = math.NewInt(1_000_000_000)
// DefaultAIMDMinLearningRate is the default minimum learning rate.
DefaultAIMDMinLearningRate = math.LegacyMustNewDecFromStr("0.01")
// DefaultAIMDMaxLearningRate is the default maximum learning rate.
DefaultAIMDMaxLearningRate = math.LegacyMustNewDecFromStr("0.50")
// DefaultAIMDFeeDenom is the Cosmos SDK default bond denom.
DefaultAIMDFeeDenom = DefaultFeeDenom
)
// DefaultAIMDParams returns a default set of parameters that implements
// the AIMD EIP-1559 fee market implementation. These parameters allow for
// the learning rate to be dynamically adjusted based on the block utilization
// within the window.
func DefaultAIMDParams() Params {
return NewParams(
DefaultAIMDWindow,
DefaultAIMDAlpha,
DefaultAIMDBeta,
DefaultAIMDTheta,
DefaultAIMDDelta,
DefaultAIMDTargetBlockSize,
DefaultAIMDMaxBlockSize,
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDMaxLearningRate,
DefaultAIMDFeeDenom,
true,
)
}
// DefaultAIMDState returns the default state for the AIMD EIP-1559 fee market
// implementation. This implementation uses a sliding window to track the
// block utilization and dynamically adjusts the learning rate based on the
// utilization within the window.
func DefaultAIMDState() State {
return NewState(
DefaultAIMDWindow,
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
)
}
// DefaultAIMDGenesisState returns a default genesis state that implements
// the AIMD EIP-1559 fee market implementation.
func DefaultAIMDGenesisState() *GenesisState {
return NewGenesisState(DefaultAIMDParams(), DefaultAIMDState())
}