Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

params,core: add max and target value to chain config #31002

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ func (o *ChainOverrides) apply(cfg *params.ChainConfig) (*params.ChainConfig, er
if err := cpy.CheckConfigForkOrder(); err != nil {
return nil, err
}
if err := cpy.CheckConfigBlobSchedule(); err != nil {
return nil, err
}
return &cpy, nil
}

Expand Down Expand Up @@ -513,6 +516,9 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *triedb.Database) (*types.Blo
if err := config.CheckConfigForkOrder(); err != nil {
return nil, err
}
if err := config.CheckConfigBlobSchedule(); err != nil {
return nil, err
}
if config.Clique != nil && len(g.ExtraData) < 32+crypto.SignatureLength {
return nil, errors.New("can't start clique chain without signers")
}
Expand Down
31 changes: 28 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,14 @@ type BlobConfig struct {
type BlobScheduleConfig struct {
Cancun *BlobConfig `json:"cancun,omitempty"`
Prague *BlobConfig `json:"prague,omitempty"`
Verkle *BlobConfig `json:"verkle,omitempty"`
}

// TargetBlobsPerBlock returns the target blobs per block associated with
// requested time.
func (c *ChainConfig) TargetBlobsPerBlock(time uint64) uint64 {
if c.BlobScheduleConfig == nil {
panic("blob schedule not defined")
return 0
}
var (
london = c.LondonBlock
Expand All @@ -514,7 +515,7 @@ func (c *ChainConfig) TargetBlobsPerBlock(time uint64) uint64 {
// requested time.
func (c *ChainConfig) MaxBlobsPerBlock(time uint64) uint64 {
if c.BlobScheduleConfig == nil {
panic("blob schedule not defined")
return 0
}
var (
london = c.LondonBlock
Expand Down Expand Up @@ -543,7 +544,7 @@ func (c *ChainConfig) LatestMaxBlobsPerBlock() uint64 {
case s.Cancun != nil:
return s.Cancun.Max
default:
panic("blob schedule empty")
return 0
}
}

Expand Down Expand Up @@ -756,6 +757,30 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
lastFork = cur
}
}

return nil
}

// CheckConfigBlobSchedule checks that all forks with blobs enabled explicitly
// define the blob schedule configuration.
func (c *ChainConfig) CheckConfigBlobSchedule() error {
lightclient marked this conversation as resolved.
Show resolved Hide resolved
bsc := c.BlobScheduleConfig
if bsc == nil {
bsc = &BlobScheduleConfig{}
}
for _, cur := range []struct {
name string
timestamp *uint64
config *BlobConfig
}{
{name: "cancun", timestamp: c.CancunTime, config: bsc.Cancun},
{name: "prague", timestamp: c.PragueTime, config: bsc.Prague},
{name: "verkle", timestamp: c.VerkleTime, config: bsc.Verkle},
} {
if cur.timestamp != nil && cur.config == nil {
return fmt.Errorf("unsupported fork configuration: missing blob configuration entry for %v in schedule", cur.name)
}
}
return nil
}

Expand Down