mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
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 <rez@berachain.com>
This commit is contained in:
parent
c901125e84
commit
b09d57285e
3 changed files with 25 additions and 3 deletions
|
|
@ -16,5 +16,7 @@ and this project adheres to
|
||||||
|
|
||||||
### Changed
|
### 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.
|
- [WIP] Updated release GH workflow to publish tarballs and push built images to GHCR.
|
||||||
- Removed support for appveyor, gitea, travis, circleci.
|
- Removed support for appveyor, gitea, travis, circleci.
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,21 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
|
||||||
|
|
||||||
// CalcBaseFee calculates the basefee of the header.
|
// CalcBaseFee calculates the basefee of the header.
|
||||||
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
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 the current block is the first EIP-1559 block, return the InitialBaseFee.
|
||||||
if !config.IsLondon(parent.Number) {
|
if !config.IsLondon(parent.Number) {
|
||||||
return new(big.Int).SetUint64(params.InitialBaseFee)
|
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.SetUint64(parent.GasUsed - parentGasTarget)
|
||||||
num.Mul(num, parent.BaseFee)
|
num.Mul(num, parent.BaseFee)
|
||||||
num.Div(num, denom.SetUint64(parentGasTarget))
|
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 {
|
if num.Cmp(common.Big1) < 0 {
|
||||||
return num.Add(parent.BaseFee, common.Big1)
|
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.SetUint64(parentGasTarget - parent.GasUsed)
|
||||||
num.Mul(num, parent.BaseFee)
|
num.Mul(num, parent.BaseFee)
|
||||||
num.Div(num, denom.SetUint64(parentGasTarget))
|
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)
|
baseFee := num.Sub(parent.BaseFee, num)
|
||||||
if baseFee.Cmp(common.Big0) < 0 {
|
if baseFee.Cmp(common.Big0) < 0 {
|
||||||
|
|
|
||||||
|
|
@ -1020,7 +1020,12 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
|
// 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
|
return DefaultBaseFeeChangeDenominator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue