Skip to content

Commit

Permalink
misc: add formulas to comments in CalcBaseFee
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeiwan committed May 26, 2022
1 parent fa2c19a commit 046a1df
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions consensus/misc/eip1559.go
Expand Up @@ -69,6 +69,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)
r := new(big.Int).SetUint64(parent.GasUsed - parentGasTarget)
r.Mul(r, parent.BaseFee)
r.Div(r, parentGasTargetAdjusted)
Expand All @@ -77,6 +78,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
return r
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget * baseFeeChangeDenominator)
r := new(big.Int).SetUint64(parentGasTarget - parent.GasUsed)
r.Mul(r, parent.BaseFee)
r.Div(r, parentGasTargetAdjusted)
Expand Down

0 comments on commit 046a1df

Please sign in to comment.