Skip to content

Commit

Permalink
Reduce magic numbers in dynamic fees (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 29, 2025
1 parent 77661b1 commit dc60ff7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ func CalcBaseFee(config *params.ChainConfig, feeConfig commontype.FeeConfig, par
// Add in the gas used by the parent block in the correct place
// If the parent consumed gas within the rollup window, add the consumed
// gas in.
expectedRollUp := params.RollupWindow
if roll < expectedRollUp {
slot := expectedRollUp - 1 - roll
if roll < params.RollupWindow {
slot := params.RollupWindow - 1 - roll
start := slot * wrappers.LongLen
updateLongWindow(newRollupWindow, start, parent.GasUsed)
}

// Calculate the amount of gas consumed within the rollup window.
totalGas := sumLongWindow(newRollupWindow, int(expectedRollUp))
totalGas := sumLongWindow(newRollupWindow, params.RollupWindow)

if totalGas == parentGasTarget {
return newRollupWindow, baseFee, nil
Expand Down Expand Up @@ -93,9 +92,9 @@ func CalcBaseFee(config *params.ChainConfig, feeConfig commontype.FeeConfig, par
// for the interval during which no blocks were produced.
// We use roll/rollupWindow, so that the transition is applied for every [rollupWindow] seconds
// that has elapsed between the parent and this block.
if roll > expectedRollUp {
if roll > params.RollupWindow {
// Note: roll/params.RollupWindow must be greater than 1 since we've checked that roll > params.RollupWindow
baseFeeDelta = new(big.Int).Mul(baseFeeDelta, new(big.Int).SetUint64(roll/expectedRollUp))
baseFeeDelta = new(big.Int).Mul(baseFeeDelta, new(big.Int).SetUint64(roll/params.RollupWindow))
}
baseFee.Sub(baseFee, baseFeeDelta)
}
Expand Down
5 changes: 3 additions & 2 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/big"

"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -19,8 +20,8 @@ const (
maxJSONLen = 64 * 1024 * 1024 // 64MB

// Consensus Params
RollupWindow uint64 = 10
DynamicFeeExtraDataSize = 80
RollupWindow = 10 // in seconds
DynamicFeeExtraDataSize = wrappers.LongLen * RollupWindow

// For legacy tests
MinGasPrice int64 = 225_000_000_000
Expand Down

0 comments on commit dc60ff7

Please sign in to comment.