forked from cerc-io/plugeth
params: make eip1559 params non-global (#25994)
This PR changes geth to read the eip1559 params from the chain config instead of the globals. This way the parameters may be changed by forking the chain config code, without creating a large diff throughout the past and future usages of the parameters. Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
08fb1aade6
commit
a51188a163
@ -33,7 +33,7 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
|
|||||||
// Verify that the gas limit remains within allowed bounds
|
// Verify that the gas limit remains within allowed bounds
|
||||||
parentGasLimit := parent.GasLimit
|
parentGasLimit := parent.GasLimit
|
||||||
if !config.IsLondon(parent.Number) {
|
if !config.IsLondon(parent.Number) {
|
||||||
parentGasLimit = parent.GasLimit * params.ElasticityMultiplier
|
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
|
||||||
}
|
}
|
||||||
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
if err := VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -58,7 +58,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
|||||||
return new(big.Int).SetUint64(params.InitialBaseFee)
|
return new(big.Int).SetUint64(params.InitialBaseFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
parentGasTarget := parent.GasLimit / params.ElasticityMultiplier
|
parentGasTarget := parent.GasLimit / config.ElasticityMultiplier()
|
||||||
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
||||||
if parent.GasUsed == parentGasTarget {
|
if parent.GasUsed == parentGasTarget {
|
||||||
return new(big.Int).Set(parent.BaseFee)
|
return new(big.Int).Set(parent.BaseFee)
|
||||||
@ -75,7 +75,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(params.BaseFeeChangeDenominator))
|
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
|
||||||
baseFeeDelta := math.BigMax(num, common.Big1)
|
baseFeeDelta := math.BigMax(num, common.Big1)
|
||||||
|
|
||||||
return num.Add(parent.BaseFee, baseFeeDelta)
|
return num.Add(parent.BaseFee, baseFeeDelta)
|
||||||
@ -85,7 +85,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(params.BaseFeeChangeDenominator))
|
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
|
||||||
baseFee := num.Sub(parent.BaseFee, num)
|
baseFee := num.Sub(parent.BaseFee, num)
|
||||||
|
|
||||||
return math.BigMax(baseFee, common.Big0)
|
return math.BigMax(baseFee, common.Big0)
|
||||||
|
@ -174,7 +174,7 @@ func (b *BlockGen) AddUncle(h *types.Header) {
|
|||||||
if b.config.IsLondon(h.Number) {
|
if b.config.IsLondon(h.Number) {
|
||||||
h.BaseFee = misc.CalcBaseFee(b.config, parent)
|
h.BaseFee = misc.CalcBaseFee(b.config, parent)
|
||||||
if !b.config.IsLondon(parent.Number) {
|
if !b.config.IsLondon(parent.Number) {
|
||||||
parentGasLimit := parent.GasLimit * params.ElasticityMultiplier
|
parentGasLimit := parent.GasLimit * b.config.ElasticityMultiplier()
|
||||||
h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
|
h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
|
|||||||
if chain.Config().IsLondon(header.Number) {
|
if chain.Config().IsLondon(header.Number) {
|
||||||
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
|
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
|
||||||
if !chain.Config().IsLondon(parent.Number()) {
|
if !chain.Config().IsLondon(parent.Number()) {
|
||||||
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
|
parentGasLimit := parent.GasLimit() * chain.Config().ElasticityMultiplier()
|
||||||
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
|
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1013,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
|
|||||||
if w.chainConfig.IsLondon(header.Number) {
|
if w.chainConfig.IsLondon(header.Number) {
|
||||||
header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header())
|
header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header())
|
||||||
if !w.chainConfig.IsLondon(parent.Number()) {
|
if !w.chainConfig.IsLondon(parent.Number()) {
|
||||||
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
|
parentGasLimit := parent.GasLimit() * w.chainConfig.ElasticityMultiplier()
|
||||||
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
|
header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,6 +709,16 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
|
||||||
|
func (c *ChainConfig) BaseFeeChangeDenominator() uint64 {
|
||||||
|
return DefaultBaseFeeChangeDenominator
|
||||||
|
}
|
||||||
|
|
||||||
|
// ElasticityMultiplier bounds the maximum gas limit an EIP-1559 block may have.
|
||||||
|
func (c *ChainConfig) ElasticityMultiplier() uint64 {
|
||||||
|
return DefaultElasticityMultiplier
|
||||||
|
}
|
||||||
|
|
||||||
// isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
|
// isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
|
||||||
// block s2 because head is already past the fork.
|
// block s2 because head is already past the fork.
|
||||||
func isForkIncompatible(s1, s2, head *big.Int) bool {
|
func isForkIncompatible(s1, s2, head *big.Int) bool {
|
||||||
|
@ -119,9 +119,9 @@ const (
|
|||||||
// Introduced in Tangerine Whistle (Eip 150)
|
// Introduced in Tangerine Whistle (Eip 150)
|
||||||
CreateBySelfdestructGas uint64 = 25000
|
CreateBySelfdestructGas uint64 = 25000
|
||||||
|
|
||||||
BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
|
DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
|
||||||
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
|
DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
|
||||||
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
|
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
|
||||||
|
|
||||||
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
|
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user