Skip to content

Commit

Permalink
feat(eip1559): remove CalcBaseFeeOntake() method (ethereum#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Aug 3, 2024
1 parent 06b2903 commit 124fde7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
35 changes: 0 additions & 35 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
11 changes: 2 additions & 9 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 124fde7

Please sign in to comment.