From 124fde7e025d6ba88c5cf796d6a0a5fd19c21a19 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 3 Aug 2024 16:56:11 +0800 Subject: [PATCH] feat(eip1559): remove `CalcBaseFeeOntake()` method (#293) --- consensus/misc/eip1559/eip1559.go | 35 ------------------------------- miner/worker.go | 11 ++-------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/consensus/misc/eip1559/eip1559.go b/consensus/misc/eip1559/eip1559.go index 79ad57403662..84b82c4c492e 100644 --- a/consensus/misc/eip1559/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -93,38 +93,3 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { return math.BigMax(baseFee, common.Big0) } } - -// CHANGE(taiko): CalcBaseFeeOntake calculates the basefee of the an ontake block header. -func CalcBaseFeeOntake(config *params.ChainConfig, parent *types.Header, parentGasTarget uint64) *big.Int { - // If the parent gasUsed is the same as the target, the baseFee remains unchanged. - if parent.GasUsed == parentGasTarget { - return new(big.Int).Set(parent.BaseFee) - } - - var ( - num = new(big.Int) - denom = new(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)) - num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator())) - baseFeeDelta := math.BigMax(num, common.Big1) - - 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)) - num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator())) - baseFee := num.Sub(parent.BaseFee, num) - - return math.BigMax(baseFee, common.Big0) - } -} diff --git a/miner/worker.go b/miner/worker.go index 1973a2e27771..1ddbe23955c6 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -987,15 +987,8 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { } // Set baseFee and GasLimit if we are on an EIP-1559 chain if w.chainConfig.IsLondon(header.Number) { - if w.chainConfig.Taiko { - if w.chainConfig.IsOntake(header.Number) { - _, blockGasTargetMillion := core.DecodeOntakeExtraData(header.Extra) - header.BaseFee = eip1559.CalcBaseFeeOntake(w.chainConfig, parent, uint64(blockGasTargetMillion)*1_000_000) - } else if genParams.baseFeePerGas != nil { - header.BaseFee = genParams.baseFeePerGas - } else { - header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent) - } + if w.chainConfig.Taiko && genParams.baseFeePerGas != nil { + header.BaseFee = genParams.baseFeePerGas } else { header.BaseFee = eip1559.CalcBaseFee(w.chainConfig, parent) if !w.chainConfig.IsLondon(parent.Number) {