Skip to content

Commit

Permalink
consensus/misc: add formulas of CalcBaseFee
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeiwan committed May 26, 2022
1 parent 1fe322f commit 005fb1b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {

if parent.GasUsed > parentGasTarget {
// If the parent block used more gas than its target, the baseFee should increase.
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parent.GasUsed - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
Expand All @@ -80,6 +81,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
return num.Add(parent.BaseFee, baseFeeDelta)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasTarget - parent.GasUsed)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
Expand Down

0 comments on commit 005fb1b

Please sign in to comment.