Skip to content

Commit

Permalink
feat: enforce min base fee in 1559 calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Nov 6, 2024
1 parent 70f3205 commit d9783f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
num = new(big.Int)
denom = new(big.Int)
baseFeeChangeDenominatorUint64 = params.BaseFeeChangeDenominator(config.Bor, parent.Number)
minBaseFee = params.GetMinBaseFee(config.Bor, parent.Number)
)

if parent.GasUsed > parentGasTarget {
Expand All @@ -94,7 +95,13 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
num.Div(num, denom.SetUint64(baseFeeChangeDenominatorUint64))
baseFee := num.Sub(parent.BaseFee, num)

return math.BigMax(baseFee, common.Big0)
// Because the min base fee is enforced on polygon pos, use that as the minimum
if config.Bor != nil {
return math.BigMax(baseFee, minBaseFee)
} else {
return math.BigMax(baseFee, common.Big0)
}

}

Check failure on line 105 in consensus/misc/eip1559/eip1559.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

unnecessary trailing newline (whitespace)
}

Expand Down
10 changes: 8 additions & 2 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ const (
BaseFeeChangeDenominatorPreDelhi = 8 // Bounds the amount the base fee can change between blocks before Delhi Hard Fork.
BaseFeeChangeDenominatorPostDelhi = 16 // Bounds the amount the base fee can change between blocks after Delhi Hard Fork.

ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 25000000000 // Initial base fee for EIP-1559 blocks.
MinBaseFee = 25000000000 // Mininum enforced base fee for EIP-1559 blocks (for polygon)

DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
Expand Down Expand Up @@ -219,3 +220,8 @@ func BaseFeeChangeDenominator(borConfig *BorConfig, number *big.Int) uint64 {
return BaseFeeChangeDenominatorPreDelhi
}
}

func GetMinBaseFee(borConfig *BorConfig, number *big.Int) *big.Int {
// TODO: Check for HF here
return big.NewInt(MinBaseFee)
}

0 comments on commit d9783f7

Please sign in to comment.