Skip to content

Commit 39ec874

Browse files
Reduce magic numbers in dynamic fees (#773)
1 parent 584302d commit 39ec874

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

consensus/dummy/dynamic_fees.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ var (
3232
ApricotPhase4BlockGasCostStep = big.NewInt(50_000)
3333
ApricotPhase4TargetBlockRate uint64 = 2 // in seconds
3434
ApricotPhase5BlockGasCostStep = big.NewInt(200_000)
35-
rollupWindow uint64 = 10
3635
)
3736

3837
// CalcBaseFee takes the previous header and the timestamp of its child block
@@ -87,7 +86,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, timestamp uin
8786
// Add in the gas used by the parent block in the correct place
8887
// If the parent consumed gas within the rollup window, add the consumed
8988
// gas in.
90-
if roll < rollupWindow {
89+
if roll < params.RollupWindow {
9190
var blockGasCost, parentExtraStateGasUsed uint64
9291
switch {
9392
case isApricotPhase5:
@@ -133,13 +132,13 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, timestamp uin
133132
}
134133
}
135134

136-
slot := rollupWindow - 1 - roll
135+
slot := params.RollupWindow - 1 - roll
137136
start := slot * wrappers.LongLen
138137
updateLongWindow(newRollupWindow, start, addedGas)
139138
}
140139

141140
// Calculate the amount of gas consumed within the rollup window.
142-
totalGas := sumLongWindow(newRollupWindow, int(rollupWindow))
141+
totalGas := sumLongWindow(newRollupWindow, params.RollupWindow)
143142

144143
if totalGas == parentGasTarget {
145144
return newRollupWindow, baseFee, nil
@@ -167,9 +166,9 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, timestamp uin
167166
// for the interval during which no blocks were produced.
168167
// We use roll/rollupWindow, so that the transition is applied for every [rollupWindow] seconds
169168
// that has elapsed between the parent and this block.
170-
if roll > rollupWindow {
169+
if roll > params.RollupWindow {
171170
// Note: roll/rollupWindow must be greater than 1 since we've checked that roll > rollupWindow
172-
baseFeeDelta = new(big.Int).Mul(baseFeeDelta, new(big.Int).SetUint64(roll/rollupWindow))
171+
baseFeeDelta = new(big.Int).Mul(baseFeeDelta, new(big.Int).SetUint64(roll/params.RollupWindow))
173172
}
174173
baseFee.Sub(baseFee, baseFeeDelta)
175174
}

params/avalanche_params.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"math/big"
88

99
"github.com/ava-labs/avalanchego/utils/units"
10+
"github.com/ava-labs/avalanchego/utils/wrappers"
1011
)
1112

1213
// Minimum Gas Price
@@ -32,8 +33,8 @@ const (
3233
ApricotPhase5BaseFeeChangeDenominator uint64 = 36
3334
EtnaMinBaseFee int64 = GWei
3435

35-
DynamicFeeExtraDataSize = 80
36-
RollupWindow uint64 = 10
36+
RollupWindow = 10 // in seconds
37+
DynamicFeeExtraDataSize = wrappers.LongLen * RollupWindow
3738

3839
// The base cost to charge per atomic transaction. Added in Apricot Phase 5.
3940
AtomicTxBaseCost uint64 = 10_000

0 commit comments

Comments
 (0)