diff --git a/consensus/dummy/dynamic_fees.go b/consensus/dummy/dynamic_fees.go index 8e85f85067..566d72b301 100644 --- a/consensus/dummy/dynamic_fees.go +++ b/consensus/dummy/dynamic_fees.go @@ -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.