Skip to content

Commit

Permalink
improve readability by removing extra var (#1345)
Browse files Browse the repository at this point in the history
* add regression test

* apply fix

* improve readability by removing extra var

* reorder equal params
  • Loading branch information
ceyonur authored Sep 17, 2024
1 parent 0f8cd87 commit 787b16b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,24 @@ func CalcBaseFee(config *params.ChainConfig, feeConfig commontype.FeeConfig, par
return newRollupWindow, baseFee, nil
}

num := new(big.Int)

if totalGas > parentGasTarget {
// If the parent block used more gas than its target, the baseFee should increase.
gasUsedDelta := new(big.Int).SetUint64(totalGas - parentGasTarget)
x := new(big.Int).Mul(parent.BaseFee, gasUsedDelta)
y := x.Div(x, parentGasTargetBig)
baseFeeDelta := math.BigMax(
x.Div(y, baseFeeChangeDenominator),
common.Big1,
)
num.SetUint64(totalGas - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Div(num, parentGasTargetBig)
num.Div(num, baseFeeChangeDenominator)
baseFeeDelta := math.BigMax(num, common.Big1)

baseFee.Add(baseFee, baseFeeDelta)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
gasUsedDelta := new(big.Int).SetUint64(parentGasTarget - totalGas)
x := new(big.Int).Mul(parent.BaseFee, gasUsedDelta)
y := x.Div(x, parentGasTargetBig)
baseFeeDelta := math.BigMax(
x.Div(y, baseFeeChangeDenominator),
common.Big1,
)
num.SetUint64(parentGasTarget - totalGas)
num.Mul(num, parent.BaseFee)
num.Div(num, parentGasTargetBig)
num.Div(num, baseFeeChangeDenominator)
baseFeeDelta := math.BigMax(num, common.Big1)

// If [roll] is greater than [rollupWindow], apply the state transition to the base fee to account
// for the interval during which no blocks were produced.
Expand Down

0 comments on commit 787b16b

Please sign in to comment.