From b09d57285ebcc9097e96470279cd02c6939dd1f4 Mon Sep 17 00:00:00 2001 From: Cal Bera Date: Wed, 18 Jun 2025 20:12:18 -0700 Subject: [PATCH] feat(BRIP-2): Gas Fee Modifications (#2) * impl with fork-awareness * Update protocol_params.go * remove the change comments * hak * Update eip1559.go * Update config.go * Update protocol_params.go * renove forkstuff * Update genesis.go * Update eip1559.go * Update eip1559.go * Update config.go * Check for isBerachain * feat(BRIP-2): Gas Fee Modifications * make fork aware * more fork aware * more prague1 stuff * Move all changes except EIP-1559 to prepare-fork branch * Reset all files except EIP-1559 to match master * fix build * resolve conflict * nit * empty bera configs * defaults * undo unneeded changes * undo * Changelog --------- Co-authored-by: Rez --- CHANGELOG.md | 2 ++ consensus/misc/eip1559/eip1559.go | 19 +++++++++++++++++-- params/config.go | 7 ++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6b4f1aa8..dba19c2d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,5 +16,7 @@ and this project adheres to ### Changed +- BRIP-2: Allowed configuration of the `MinimumBaseFeeWei`. For Berachain, this will be set as 1 gwei. (https://github.com/berachain/bera-geth/pull/2) +- BRIP-2: Allowed configuration of the `BaseFeeChangeDenominator`. For Berachain, this will be set as 48 (a 6x increase corresponding to 6x faster block times). (https://github.com/berachain/bera-geth/pull/2) - [WIP] Updated release GH workflow to publish tarballs and push built images to GHCR. - Removed support for appveyor, gitea, travis, circleci. diff --git a/consensus/misc/eip1559/eip1559.go b/consensus/misc/eip1559/eip1559.go index a90bd744b2..f6b5af915f 100644 --- a/consensus/misc/eip1559/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -54,6 +54,21 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade // CalcBaseFee calculates the basefee of the header. func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { + calculatedBaseFee := calcBaseFee(config, parent) + + // Starting at the Prague1 fork, the base fee must be at least the minimum base fee. + if config.IsPrague1(parent.Number, parent.Time) { + minBaseFee := new(big.Int).SetUint64(config.Berachain.Prague1.MinimumBaseFeeWei) + if calculatedBaseFee.Cmp(minBaseFee) < 0 { + calculatedBaseFee = minBaseFee + } + } + + return calculatedBaseFee +} + +// calcBaseFee calculates the basefee of the header in wei. +func calcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { // If the current block is the first EIP-1559 block, return the InitialBaseFee. if !config.IsLondon(parent.Number) { return new(big.Int).SetUint64(params.InitialBaseFee) @@ -76,7 +91,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { num.SetUint64(parent.GasUsed - parentGasTarget) num.Mul(num, parent.BaseFee) num.Div(num, denom.SetUint64(parentGasTarget)) - num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator())) + num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator(parent.Number, parent.Time))) if num.Cmp(common.Big1) < 0 { return num.Add(parent.BaseFee, common.Big1) } @@ -87,7 +102,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { num.SetUint64(parentGasTarget - parent.GasUsed) num.Mul(num, parent.BaseFee) num.Div(num, denom.SetUint64(parentGasTarget)) - num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator())) + num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator(parent.Number, parent.Time))) baseFee := num.Sub(parent.BaseFee, num) if baseFee.Cmp(common.Big0) < 0 { diff --git a/params/config.go b/params/config.go index 4abf45f3de..9f80fabae3 100644 --- a/params/config.go +++ b/params/config.go @@ -1020,7 +1020,12 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, } // BaseFeeChangeDenominator bounds the amount the base fee can change between blocks. -func (c *ChainConfig) BaseFeeChangeDenominator() uint64 { +func (c *ChainConfig) BaseFeeChangeDenominator(num *big.Int, time uint64) uint64 { + // Starting at the Prague1 fork, we use the Berachain base fee change denominator. + if c.IsPrague1(num, time) { + return c.Berachain.Prague1.BaseFeeChangeDenominator + } + return DefaultBaseFeeChangeDenominator }