Skip to content

Commit a327ffe

Browse files
fjlMariusVanDerWijdenrjl493456442
authored
params: EIP-7892 - Blob Parameter Only Hardforks (ethereum#32193)
This is a resubmit of ethereum#31820 against the `master` branch. --------- Co-authored-by: Marius van der Wijden <[email protected]> Co-authored-by: Gary Rong <[email protected]>
1 parent 90a0989 commit a327ffe

File tree

2 files changed

+115
-32
lines changed

2 files changed

+115
-32
lines changed

consensus/misc/eip4844/eip4844.go

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/core/types"
2525
"github.com/ethereum/go-ethereum/params"
26-
"github.com/ethereum/go-ethereum/params/forks"
2726
)
2827

2928
var (
@@ -100,42 +99,53 @@ func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header, headTim
10099

101100
// CalcBlobFee calculates the blobfee from the header's excess blob gas field.
102101
func CalcBlobFee(config *params.ChainConfig, header *types.Header) *big.Int {
103-
var frac uint64
104-
switch config.LatestFork(header.Time) {
105-
case forks.Osaka:
106-
frac = config.BlobScheduleConfig.Osaka.UpdateFraction
107-
case forks.Prague:
108-
frac = config.BlobScheduleConfig.Prague.UpdateFraction
109-
case forks.Cancun:
110-
frac = config.BlobScheduleConfig.Cancun.UpdateFraction
111-
default:
102+
blobConfig := latestBlobConfig(config, header.Time)
103+
if blobConfig == nil {
112104
panic("calculating blob fee on unsupported fork")
113105
}
114-
return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(*header.ExcessBlobGas), new(big.Int).SetUint64(frac))
106+
return fakeExponential(minBlobGasPrice, new(big.Int).SetUint64(*header.ExcessBlobGas), new(big.Int).SetUint64(blobConfig.UpdateFraction))
115107
}
116108

117109
// MaxBlobsPerBlock returns the max blobs per block for a block at the given timestamp.
118110
func MaxBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
119-
if cfg.BlobScheduleConfig == nil {
111+
blobConfig := latestBlobConfig(cfg, time)
112+
if blobConfig == nil {
120113
return 0
121114
}
115+
return blobConfig.Max
116+
}
117+
118+
func latestBlobConfig(cfg *params.ChainConfig, time uint64) *params.BlobConfig {
119+
if cfg.BlobScheduleConfig == nil {
120+
return nil
121+
}
122122
var (
123123
london = cfg.LondonBlock
124124
s = cfg.BlobScheduleConfig
125125
)
126126
switch {
127+
case cfg.IsBPO5(london, time) && s.BPO5 != nil:
128+
return s.BPO5
129+
case cfg.IsBPO4(london, time) && s.BPO4 != nil:
130+
return s.BPO4
131+
case cfg.IsBPO3(london, time) && s.BPO3 != nil:
132+
return s.BPO3
133+
case cfg.IsBPO2(london, time) && s.BPO2 != nil:
134+
return s.BPO2
135+
case cfg.IsBPO1(london, time) && s.BPO1 != nil:
136+
return s.BPO1
127137
case cfg.IsOsaka(london, time) && s.Osaka != nil:
128-
return s.Osaka.Max
138+
return s.Osaka
129139
case cfg.IsPrague(london, time) && s.Prague != nil:
130-
return s.Prague.Max
140+
return s.Prague
131141
case cfg.IsCancun(london, time) && s.Cancun != nil:
132-
return s.Cancun.Max
142+
return s.Cancun
133143
default:
134-
return 0
144+
return nil
135145
}
136146
}
137147

138-
// MaxBlobsPerBlock returns the maximum blob gas that can be spent in a block at the given timestamp.
148+
// MaxBlobGasPerBlock returns the maximum blob gas that can be spent in a block at the given timestamp.
139149
func MaxBlobGasPerBlock(cfg *params.ChainConfig, time uint64) uint64 {
140150
return uint64(MaxBlobsPerBlock(cfg, time)) * params.BlobTxBlobGasPerBlob
141151
}
@@ -148,6 +158,16 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
148158
return 0
149159
}
150160
switch {
161+
case s.BPO5 != nil:
162+
return s.BPO5.Max
163+
case s.BPO4 != nil:
164+
return s.BPO4.Max
165+
case s.BPO3 != nil:
166+
return s.BPO3.Max
167+
case s.BPO2 != nil:
168+
return s.BPO2.Max
169+
case s.BPO1 != nil:
170+
return s.BPO1.Max
151171
case s.Osaka != nil:
152172
return s.Osaka.Max
153173
case s.Prague != nil:
@@ -161,23 +181,11 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
161181

162182
// targetBlobsPerBlock returns the target number of blobs in a block at the given timestamp.
163183
func targetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
164-
if cfg.BlobScheduleConfig == nil {
165-
return 0
166-
}
167-
var (
168-
london = cfg.LondonBlock
169-
s = cfg.BlobScheduleConfig
170-
)
171-
switch {
172-
case cfg.IsOsaka(london, time) && s.Osaka != nil:
173-
return s.Osaka.Target
174-
case cfg.IsPrague(london, time) && s.Prague != nil:
175-
return s.Prague.Target
176-
case cfg.IsCancun(london, time) && s.Cancun != nil:
177-
return s.Cancun.Target
178-
default:
184+
blobConfig := latestBlobConfig(cfg, time)
185+
if blobConfig == nil {
179186
return 0
180187
}
188+
return blobConfig.Target
181189
}
182190

183191
// fakeExponential approximates factor * e ** (numerator / denominator) using

params/config.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ type ChainConfig struct {
411411
PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
412412
OsakaTime *uint64 `json:"osakaTime,omitempty"` // Osaka switch time (nil = no fork, 0 = already on osaka)
413413
VerkleTime *uint64 `json:"verkleTime,omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle)
414+
BPO1Time *uint64 `json:"bpo1Time,omitempty"` // BPO1 switch time (nil = no fork, 0 = already on bpo1)
415+
BPO2Time *uint64 `json:"bpo2Time,omitempty"` // BPO2 switch time (nil = no fork, 0 = already on bpo2)
416+
BPO3Time *uint64 `json:"bpo3Time,omitempty"` // BPO3 switch time (nil = no fork, 0 = already on bpo3)
417+
BPO4Time *uint64 `json:"bpo4Time,omitempty"` // BPO4 switch time (nil = no fork, 0 = already on bpo4)
418+
BPO5Time *uint64 `json:"bpo5Time,omitempty"` // BPO5 switch time (nil = no fork, 0 = already on bpo5)
414419

415420
// TerminalTotalDifficulty is the amount of total difficulty reached by
416421
// the network that triggers the consensus upgrade.
@@ -531,6 +536,21 @@ func (c *ChainConfig) Description() string {
531536
if c.VerkleTime != nil {
532537
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
533538
}
539+
if c.BPO1Time != nil {
540+
banner += fmt.Sprintf(" - BPO1: @%-10v\n", *c.BPO1Time)
541+
}
542+
if c.BPO2Time != nil {
543+
banner += fmt.Sprintf(" - BPO2: @%-10v\n", *c.BPO2Time)
544+
}
545+
if c.BPO3Time != nil {
546+
banner += fmt.Sprintf(" - BPO3: @%-10v\n", *c.BPO3Time)
547+
}
548+
if c.BPO4Time != nil {
549+
banner += fmt.Sprintf(" - BPO4: @%-10v\n", *c.BPO4Time)
550+
}
551+
if c.BPO5Time != nil {
552+
banner += fmt.Sprintf(" - BPO5: @%-10v\n", *c.BPO5Time)
553+
}
534554
return banner
535555
}
536556

@@ -547,6 +567,11 @@ type BlobScheduleConfig struct {
547567
Prague *BlobConfig `json:"prague,omitempty"`
548568
Osaka *BlobConfig `json:"osaka,omitempty"`
549569
Verkle *BlobConfig `json:"verkle,omitempty"`
570+
BPO1 *BlobConfig `json:"bpo1,omitempty"`
571+
BPO2 *BlobConfig `json:"bpo2,omitempty"`
572+
BPO3 *BlobConfig `json:"bpo3,omitempty"`
573+
BPO4 *BlobConfig `json:"bpo4,omitempty"`
574+
BPO5 *BlobConfig `json:"bpo5,omitempty"`
550575
}
551576

552577
// IsHomestead returns whether num is either equal to the homestead block or greater.
@@ -654,6 +679,31 @@ func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool {
654679
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
655680
}
656681

682+
// IsBPO1 returns whether time is either equal to the BPO1 fork time or greater.
683+
func (c *ChainConfig) IsBPO1(num *big.Int, time uint64) bool {
684+
return c.IsLondon(num) && isTimestampForked(c.BPO1Time, time)
685+
}
686+
687+
// IsBPO2 returns whether time is either equal to the BPO2 fork time or greater.
688+
func (c *ChainConfig) IsBPO2(num *big.Int, time uint64) bool {
689+
return c.IsLondon(num) && isTimestampForked(c.BPO2Time, time)
690+
}
691+
692+
// IsBPO3 returns whether time is either equal to the BPO3 fork time or greater.
693+
func (c *ChainConfig) IsBPO3(num *big.Int, time uint64) bool {
694+
return c.IsLondon(num) && isTimestampForked(c.BPO3Time, time)
695+
}
696+
697+
// IsBPO4 returns whether time is either equal to the BPO4 fork time or greater.
698+
func (c *ChainConfig) IsBPO4(num *big.Int, time uint64) bool {
699+
return c.IsLondon(num) && isTimestampForked(c.BPO4Time, time)
700+
}
701+
702+
// IsBPO5 returns whether time is either equal to the BPO5 fork time or greater.
703+
func (c *ChainConfig) IsBPO5(num *big.Int, time uint64) bool {
704+
return c.IsLondon(num) && isTimestampForked(c.BPO5Time, time)
705+
}
706+
657707
// IsVerkleGenesis checks whether the verkle fork is activated at the genesis block.
658708
//
659709
// Verkle mode is considered enabled if the verkle fork time is configured,
@@ -729,6 +779,11 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
729779
{name: "pragueTime", timestamp: c.PragueTime, optional: true},
730780
{name: "osakaTime", timestamp: c.OsakaTime, optional: true},
731781
{name: "verkleTime", timestamp: c.VerkleTime, optional: true},
782+
{name: "bpo1", timestamp: c.BPO1Time, optional: true},
783+
{name: "bpo2", timestamp: c.BPO2Time, optional: true},
784+
{name: "bpo3", timestamp: c.BPO3Time, optional: true},
785+
{name: "bpo4", timestamp: c.BPO4Time, optional: true},
786+
{name: "bpo5", timestamp: c.BPO5Time, optional: true},
732787
} {
733788
if lastFork.name != "" {
734789
switch {
@@ -778,6 +833,11 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
778833
{name: "cancun", timestamp: c.CancunTime, config: bsc.Cancun},
779834
{name: "prague", timestamp: c.PragueTime, config: bsc.Prague},
780835
{name: "osaka", timestamp: c.OsakaTime, config: bsc.Osaka},
836+
{name: "bpo1", timestamp: c.BPO1Time, config: bsc.BPO1},
837+
{name: "bpo2", timestamp: c.BPO2Time, config: bsc.BPO2},
838+
{name: "bpo3", timestamp: c.BPO3Time, config: bsc.BPO3},
839+
{name: "bpo4", timestamp: c.BPO4Time, config: bsc.BPO4},
840+
{name: "bpo5", timestamp: c.BPO5Time, config: bsc.BPO5},
781841
} {
782842
if cur.config != nil {
783843
if err := cur.config.validate(); err != nil {
@@ -878,6 +938,21 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
878938
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
879939
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
880940
}
941+
if isForkTimestampIncompatible(c.BPO1Time, newcfg.BPO1Time, headTimestamp) {
942+
return newTimestampCompatError("BPO1 fork timestamp", c.BPO1Time, newcfg.BPO1Time)
943+
}
944+
if isForkTimestampIncompatible(c.BPO2Time, newcfg.BPO2Time, headTimestamp) {
945+
return newTimestampCompatError("BPO2 fork timestamp", c.BPO2Time, newcfg.BPO2Time)
946+
}
947+
if isForkTimestampIncompatible(c.BPO3Time, newcfg.BPO3Time, headTimestamp) {
948+
return newTimestampCompatError("BPO3 fork timestamp", c.BPO3Time, newcfg.BPO3Time)
949+
}
950+
if isForkTimestampIncompatible(c.BPO4Time, newcfg.BPO4Time, headTimestamp) {
951+
return newTimestampCompatError("BPO4 fork timestamp", c.BPO4Time, newcfg.BPO4Time)
952+
}
953+
if isForkTimestampIncompatible(c.BPO5Time, newcfg.BPO5Time, headTimestamp) {
954+
return newTimestampCompatError("BPO5 fork timestamp", c.BPO5Time, newcfg.BPO5Time)
955+
}
881956
return nil
882957
}
883958

0 commit comments

Comments
 (0)