Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eip1559): remove CalcBaseFeeOntake() method #293

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading