mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
params: EIP-7892 - Blob Parameter Only Hardforks (#31820)
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
parent
3d6b399385
commit
60ac08786e
2 changed files with 115 additions and 32 deletions
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/params/forks"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -81,42 +80,53 @@ func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header, headTim
|
||||||
|
|
||||||
// CalcBlobFee calculates the blobfee from the header's excess blob gas field.
|
// CalcBlobFee calculates the blobfee from the header's excess blob gas field.
|
||||||
func CalcBlobFee(config *params.ChainConfig, header *types.Header) *big.Int {
|
func CalcBlobFee(config *params.ChainConfig, header *types.Header) *big.Int {
|
||||||
var frac uint64
|
blobConfig := latestBlobConfig(config, header.Time)
|
||||||
switch config.LatestFork(header.Time) {
|
if blobConfig == nil {
|
||||||
case forks.Osaka:
|
|
||||||
frac = config.BlobScheduleConfig.Osaka.UpdateFraction
|
|
||||||
case forks.Prague:
|
|
||||||
frac = config.BlobScheduleConfig.Prague.UpdateFraction
|
|
||||||
case forks.Cancun:
|
|
||||||
frac = config.BlobScheduleConfig.Cancun.UpdateFraction
|
|
||||||
default:
|
|
||||||
panic("calculating blob fee on unsupported fork")
|
panic("calculating blob fee on unsupported fork")
|
||||||
}
|
}
|
||||||
return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(*header.ExcessBlobGas), new(big.Int).SetUint64(frac))
|
return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(*header.ExcessBlobGas), new(big.Int).SetUint64(blobConfig.UpdateFraction))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxBlobsPerBlock returns the max blobs per block for a block at the given timestamp.
|
// MaxBlobsPerBlock returns the max blobs per block for a block at the given timestamp.
|
||||||
func MaxBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
|
func MaxBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
|
||||||
if cfg.BlobScheduleConfig == nil {
|
blobConfig := latestBlobConfig(cfg, time)
|
||||||
|
if blobConfig == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
return blobConfig.Max
|
||||||
|
}
|
||||||
|
|
||||||
|
func latestBlobConfig(cfg *params.ChainConfig, time uint64) *params.BlobConfig {
|
||||||
|
if cfg.BlobScheduleConfig == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
london = cfg.LondonBlock
|
london = cfg.LondonBlock
|
||||||
s = cfg.BlobScheduleConfig
|
s = cfg.BlobScheduleConfig
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
|
case cfg.IsBPO5(london, time) && s.BPO5 != nil:
|
||||||
|
return s.BPO5
|
||||||
|
case cfg.IsBPO4(london, time) && s.BPO4 != nil:
|
||||||
|
return s.BPO4
|
||||||
|
case cfg.IsBPO3(london, time) && s.BPO3 != nil:
|
||||||
|
return s.BPO3
|
||||||
|
case cfg.IsBPO2(london, time) && s.BPO2 != nil:
|
||||||
|
return s.BPO2
|
||||||
|
case cfg.IsBPO1(london, time) && s.BPO1 != nil:
|
||||||
|
return s.BPO1
|
||||||
case cfg.IsOsaka(london, time) && s.Osaka != nil:
|
case cfg.IsOsaka(london, time) && s.Osaka != nil:
|
||||||
return s.Osaka.Max
|
return s.Osaka
|
||||||
case cfg.IsPrague(london, time) && s.Prague != nil:
|
case cfg.IsPrague(london, time) && s.Prague != nil:
|
||||||
return s.Prague.Max
|
return s.Prague
|
||||||
case cfg.IsCancun(london, time) && s.Cancun != nil:
|
case cfg.IsCancun(london, time) && s.Cancun != nil:
|
||||||
return s.Cancun.Max
|
return s.Cancun
|
||||||
default:
|
default:
|
||||||
return 0
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxBlobsPerBlock returns the maximum blob gas that can be spent in a block at the given timestamp.
|
// MaxBlobGasPerBlock returns the maximum blob gas that can be spent in a block at the given timestamp.
|
||||||
func MaxBlobGasPerBlock(cfg *params.ChainConfig, time uint64) uint64 {
|
func MaxBlobGasPerBlock(cfg *params.ChainConfig, time uint64) uint64 {
|
||||||
return uint64(MaxBlobsPerBlock(cfg, time)) * params.BlobTxBlobGasPerBlob
|
return uint64(MaxBlobsPerBlock(cfg, time)) * params.BlobTxBlobGasPerBlob
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +139,16 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
case s.BPO5 != nil:
|
||||||
|
return s.BPO5.Max
|
||||||
|
case s.BPO4 != nil:
|
||||||
|
return s.BPO4.Max
|
||||||
|
case s.BPO3 != nil:
|
||||||
|
return s.BPO3.Max
|
||||||
|
case s.BPO2 != nil:
|
||||||
|
return s.BPO2.Max
|
||||||
|
case s.BPO1 != nil:
|
||||||
|
return s.BPO1.Max
|
||||||
case s.Osaka != nil:
|
case s.Osaka != nil:
|
||||||
return s.Osaka.Max
|
return s.Osaka.Max
|
||||||
case s.Prague != nil:
|
case s.Prague != nil:
|
||||||
|
|
@ -142,23 +162,11 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
|
||||||
|
|
||||||
// targetBlobsPerBlock returns the target number of blobs in a block at the given timestamp.
|
// targetBlobsPerBlock returns the target number of blobs in a block at the given timestamp.
|
||||||
func targetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
|
func targetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
|
||||||
if cfg.BlobScheduleConfig == nil {
|
blobConfig := latestBlobConfig(cfg, time)
|
||||||
return 0
|
if blobConfig == nil {
|
||||||
}
|
|
||||||
var (
|
|
||||||
london = cfg.LondonBlock
|
|
||||||
s = cfg.BlobScheduleConfig
|
|
||||||
)
|
|
||||||
switch {
|
|
||||||
case cfg.IsOsaka(london, time) && s.Osaka != nil:
|
|
||||||
return s.Osaka.Target
|
|
||||||
case cfg.IsPrague(london, time) && s.Prague != nil:
|
|
||||||
return s.Prague.Target
|
|
||||||
case cfg.IsCancun(london, time) && s.Cancun != nil:
|
|
||||||
return s.Cancun.Target
|
|
||||||
default:
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
return blobConfig.Target
|
||||||
}
|
}
|
||||||
|
|
||||||
// fakeExponential approximates factor * e ** (numerator / denominator) using
|
// fakeExponential approximates factor * e ** (numerator / denominator) using
|
||||||
|
|
|
||||||
|
|
@ -410,6 +410,11 @@ type ChainConfig struct {
|
||||||
PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
|
PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
|
||||||
OsakaTime *uint64 `json:"osakaTime,omitempty"` // Osaka switch time (nil = no fork, 0 = already on osaka)
|
OsakaTime *uint64 `json:"osakaTime,omitempty"` // Osaka switch time (nil = no fork, 0 = already on osaka)
|
||||||
VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle)
|
VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle)
|
||||||
|
BPO1Time *uint64 `json:"bpo1Time,omitempty"` // BPO1 switch time (nil = no fork, 0 = already on bpo1)
|
||||||
|
BPO2Time *uint64 `json:"bpo2Time,omitempty"` // BPO2 switch time (nil = no fork, 0 = already on bpo2)
|
||||||
|
BPO3Time *uint64 `json:"bpo3Time,omitempty"` // BPO3 switch time (nil = no fork, 0 = already on bpo3)
|
||||||
|
BPO4Time *uint64 `json:"bpo4Time,omitempty"` // BPO4 switch time (nil = no fork, 0 = already on bpo4)
|
||||||
|
BPO5Time *uint64 `json:"bpo5Time,omitempty"` // BPO5 switch time (nil = no fork, 0 = already on bpo5)
|
||||||
|
|
||||||
// TerminalTotalDifficulty is the amount of total difficulty reached by
|
// TerminalTotalDifficulty is the amount of total difficulty reached by
|
||||||
// the network that triggers the consensus upgrade.
|
// the network that triggers the consensus upgrade.
|
||||||
|
|
@ -530,6 +535,21 @@ func (c *ChainConfig) Description() string {
|
||||||
if c.VerkleTime != nil {
|
if c.VerkleTime != nil {
|
||||||
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
|
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
|
||||||
}
|
}
|
||||||
|
if c.BPO1Time != nil {
|
||||||
|
banner += fmt.Sprintf(" - BPO1: @%-10v\n", *c.BPO1Time)
|
||||||
|
}
|
||||||
|
if c.BPO2Time != nil {
|
||||||
|
banner += fmt.Sprintf(" - BPO2: @%-10v\n", *c.BPO2Time)
|
||||||
|
}
|
||||||
|
if c.BPO3Time != nil {
|
||||||
|
banner += fmt.Sprintf(" - BPO3: @%-10v\n", *c.BPO3Time)
|
||||||
|
}
|
||||||
|
if c.BPO4Time != nil {
|
||||||
|
banner += fmt.Sprintf(" - BPO4: @%-10v\n", *c.BPO4Time)
|
||||||
|
}
|
||||||
|
if c.BPO5Time != nil {
|
||||||
|
banner += fmt.Sprintf(" - BPO5: @%-10v\n", *c.BPO5Time)
|
||||||
|
}
|
||||||
return banner
|
return banner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -546,6 +566,11 @@ type BlobScheduleConfig struct {
|
||||||
Prague *BlobConfig `json:"prague,omitempty"`
|
Prague *BlobConfig `json:"prague,omitempty"`
|
||||||
Osaka *BlobConfig `json:"osaka,omitempty"`
|
Osaka *BlobConfig `json:"osaka,omitempty"`
|
||||||
Verkle *BlobConfig `json:"verkle,omitempty"`
|
Verkle *BlobConfig `json:"verkle,omitempty"`
|
||||||
|
BPO1 *BlobConfig `json:"bpo1,omitempty"`
|
||||||
|
BPO2 *BlobConfig `json:"bpo2,omitempty"`
|
||||||
|
BPO3 *BlobConfig `json:"bpo3,omitempty"`
|
||||||
|
BPO4 *BlobConfig `json:"bpo4,omitempty"`
|
||||||
|
BPO5 *BlobConfig `json:"bpo5,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
// IsHomestead returns whether num is either equal to the homestead block or greater.
|
||||||
|
|
@ -653,6 +678,31 @@ func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool {
|
||||||
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
|
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBPO1 returns whether time is either equal to the BPO1 fork time or greater.
|
||||||
|
func (c *ChainConfig) IsBPO1(num *big.Int, time uint64) bool {
|
||||||
|
return c.IsLondon(num) && isTimestampForked(c.BPO1Time, time)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBPO2 returns whether time is either equal to the BPO2 fork time or greater.
|
||||||
|
func (c *ChainConfig) IsBPO2(num *big.Int, time uint64) bool {
|
||||||
|
return c.IsLondon(num) && isTimestampForked(c.BPO2Time, time)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBPO3 returns whether time is either equal to the BPO3 fork time or greater.
|
||||||
|
func (c *ChainConfig) IsBPO3(num *big.Int, time uint64) bool {
|
||||||
|
return c.IsLondon(num) && isTimestampForked(c.BPO3Time, time)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBPO4 returns whether time is either equal to the BPO4 fork time or greater.
|
||||||
|
func (c *ChainConfig) IsBPO4(num *big.Int, time uint64) bool {
|
||||||
|
return c.IsLondon(num) && isTimestampForked(c.BPO4Time, time)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBPO5 returns whether time is either equal to the BPO5 fork time or greater.
|
||||||
|
func (c *ChainConfig) IsBPO5(num *big.Int, time uint64) bool {
|
||||||
|
return c.IsLondon(num) && isTimestampForked(c.BPO5Time, time)
|
||||||
|
}
|
||||||
|
|
||||||
// IsVerkleGenesis checks whether the verkle fork is activated at the genesis block.
|
// IsVerkleGenesis checks whether the verkle fork is activated at the genesis block.
|
||||||
//
|
//
|
||||||
// Verkle mode is considered enabled if the verkle fork time is configured,
|
// Verkle mode is considered enabled if the verkle fork time is configured,
|
||||||
|
|
@ -728,6 +778,11 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
|
||||||
{name: "pragueTime", timestamp: c.PragueTime, optional: true},
|
{name: "pragueTime", timestamp: c.PragueTime, optional: true},
|
||||||
{name: "osakaTime", timestamp: c.OsakaTime, optional: true},
|
{name: "osakaTime", timestamp: c.OsakaTime, optional: true},
|
||||||
{name: "verkleTime", timestamp: c.VerkleTime, optional: true},
|
{name: "verkleTime", timestamp: c.VerkleTime, optional: true},
|
||||||
|
{name: "bpo1", timestamp: c.BPO1Time, optional: true},
|
||||||
|
{name: "bpo2", timestamp: c.BPO2Time, optional: true},
|
||||||
|
{name: "bpo3", timestamp: c.BPO3Time, optional: true},
|
||||||
|
{name: "bpo4", timestamp: c.BPO4Time, optional: true},
|
||||||
|
{name: "bpo5", timestamp: c.BPO5Time, optional: true},
|
||||||
} {
|
} {
|
||||||
if lastFork.name != "" {
|
if lastFork.name != "" {
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -777,6 +832,11 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
|
||||||
{name: "cancun", timestamp: c.CancunTime, config: bsc.Cancun},
|
{name: "cancun", timestamp: c.CancunTime, config: bsc.Cancun},
|
||||||
{name: "prague", timestamp: c.PragueTime, config: bsc.Prague},
|
{name: "prague", timestamp: c.PragueTime, config: bsc.Prague},
|
||||||
{name: "osaka", timestamp: c.OsakaTime, config: bsc.Osaka},
|
{name: "osaka", timestamp: c.OsakaTime, config: bsc.Osaka},
|
||||||
|
{name: "bpo1", timestamp: c.BPO1Time, config: bsc.BPO1},
|
||||||
|
{name: "bpo2", timestamp: c.BPO2Time, config: bsc.BPO2},
|
||||||
|
{name: "bpo3", timestamp: c.BPO3Time, config: bsc.BPO3},
|
||||||
|
{name: "bpo4", timestamp: c.BPO4Time, config: bsc.BPO4},
|
||||||
|
{name: "bpo5", timestamp: c.BPO5Time, config: bsc.BPO5},
|
||||||
} {
|
} {
|
||||||
if cur.config != nil {
|
if cur.config != nil {
|
||||||
if err := cur.config.validate(); err != nil {
|
if err := cur.config.validate(); err != nil {
|
||||||
|
|
@ -877,6 +937,21 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
|
||||||
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
|
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
|
||||||
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
|
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
|
||||||
}
|
}
|
||||||
|
if isForkTimestampIncompatible(c.BPO1Time, newcfg.BPO1Time, headTimestamp) {
|
||||||
|
return newTimestampCompatError("BPO1 fork timestamp", c.BPO1Time, newcfg.BPO1Time)
|
||||||
|
}
|
||||||
|
if isForkTimestampIncompatible(c.BPO2Time, newcfg.BPO2Time, headTimestamp) {
|
||||||
|
return newTimestampCompatError("BPO2 fork timestamp", c.BPO2Time, newcfg.BPO2Time)
|
||||||
|
}
|
||||||
|
if isForkTimestampIncompatible(c.BPO3Time, newcfg.BPO3Time, headTimestamp) {
|
||||||
|
return newTimestampCompatError("BPO3 fork timestamp", c.BPO3Time, newcfg.BPO3Time)
|
||||||
|
}
|
||||||
|
if isForkTimestampIncompatible(c.BPO4Time, newcfg.BPO4Time, headTimestamp) {
|
||||||
|
return newTimestampCompatError("BPO4 fork timestamp", c.BPO4Time, newcfg.BPO4Time)
|
||||||
|
}
|
||||||
|
if isForkTimestampIncompatible(c.BPO5Time, newcfg.BPO5Time, headTimestamp) {
|
||||||
|
return newTimestampCompatError("BPO5 fork timestamp", c.BPO5Time, newcfg.BPO5Time)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue