Skip to content

Commit 89b138c

Browse files
gballetholiman
andauthored
params: Add Shanghai and Cancun blocks (#25305)
* params: Add Shangai and Cancun blocks * fix copy/paste error Co-authored-by: Martin Holst Swende <[email protected]> * fix typo in Shanghai name Co-authored-by: Martin Holst Swende <[email protected]>
1 parent e73e8bc commit 89b138c

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

params/config.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,16 @@ var (
261261
//
262262
// This configuration is intentionally not using keyed fields to force anyone
263263
// adding flags to the config to also have to set these fields.
264-
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}
264+
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, new(EthashConfig), nil}
265265

266266
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
267267
// and accepted by the Ethereum core developers into the Clique consensus.
268268
//
269269
// This configuration is intentionally not using keyed fields to force anyone
270270
// adding flags to the config to also have to set these fields.
271-
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
271+
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
272272

273-
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}
273+
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, new(EthashConfig), nil}
274274
TestRules = TestChainConfig.Rules(new(big.Int), false)
275275
)
276276

@@ -361,6 +361,8 @@ type ChainConfig struct {
361361
ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
362362
GrayGlacierBlock *big.Int `json:"grayGlacierBlock,omitempty"` // Eip-5133 (bomb delay) switch block (nil = no fork, 0 = already activated)
363363
MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter
364+
ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch block (nil = no fork, 0 = already on shanghai)
365+
CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch block (nil = no fork, 0 = already on cancun)
364366

365367
// TerminalTotalDifficulty is the amount of total difficulty reached by
366368
// the network that triggers the consensus upgrade.
@@ -444,6 +446,12 @@ func (c *ChainConfig) String() string {
444446
if c.GrayGlacierBlock != nil {
445447
banner += fmt.Sprintf(" - Gray Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock)
446448
}
449+
if c.ShanghaiBlock != nil {
450+
banner += fmt.Sprintf(" - Shanghai: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md)\n", c.ShanghaiBlock)
451+
}
452+
if c.CancunBlock != nil {
453+
banner += fmt.Sprintf(" - Cancun: %-8v\n", c.CancunBlock)
454+
}
447455
banner += "\n"
448456

449457
// Add a special section for the merge as it's non-obvious
@@ -539,6 +547,16 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
539547
return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
540548
}
541549

550+
// IsShanghai returns whether num is either equal to the Shanghai fork block or greater.
551+
func (c *ChainConfig) IsShanghai(num *big.Int) bool {
552+
return isForked(c.ShanghaiBlock, num)
553+
}
554+
555+
// IsCancun returns whether num is either equal to the Cancun fork block or greater.
556+
func (c *ChainConfig) IsCancun(num *big.Int) bool {
557+
return isForked(c.CancunBlock, num)
558+
}
559+
542560
// CheckCompatible checks whether scheduled fork transitions have been imported
543561
// with a mismatching chain configuration.
544562
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
@@ -582,6 +600,8 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
582600
{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
583601
{name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true},
584602
{name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true},
603+
{name: "shanghaiBlock", block: c.ShanghaiBlock, optional: true},
604+
{name: "cancunBlock", block: c.CancunBlock, optional: true},
585605
} {
586606
if lastFork.name != "" {
587607
// Next one must be higher number
@@ -660,6 +680,12 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
660680
if isForkIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, head) {
661681
return newCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock)
662682
}
683+
if isForkIncompatible(c.ShanghaiBlock, newcfg.ShanghaiBlock, head) {
684+
return newCompatError("Shanghai fork block", c.ShanghaiBlock, newcfg.ShanghaiBlock)
685+
}
686+
if isForkIncompatible(c.CancunBlock, newcfg.CancunBlock, head) {
687+
return newCompatError("Cancun fork block", c.CancunBlock, newcfg.CancunBlock)
688+
}
663689
return nil
664690
}
665691

@@ -728,7 +754,7 @@ type Rules struct {
728754
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
729755
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
730756
IsBerlin, IsLondon bool
731-
IsMerge bool
757+
IsMerge, IsShanghai, isCancun bool
732758
}
733759

734760
// Rules ensures c's ChainID is not nil.
@@ -750,5 +776,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
750776
IsBerlin: c.IsBerlin(num),
751777
IsLondon: c.IsLondon(num),
752778
IsMerge: isMerge,
779+
IsShanghai: c.IsShanghai(num),
780+
isCancun: c.IsCancun(num),
753781
}
754782
}

0 commit comments

Comments
 (0)