Skip to content

Commit dac97cf

Browse files
rjl493456442shekhirin
authored andcommitted
params: define cancun and prague as timestamp based forks (ethereum#26481)
* params: define cancun and osaka as timestamp based forks * core, params: change osaka to prague * params: fix
1 parent 2e42b2b commit dac97cf

File tree

2 files changed

+148
-31
lines changed

2 files changed

+148
-31
lines changed

core/forkid/forkid_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,21 +387,21 @@ func TestValidation(t *testing.T) {
387387
// TODO(karalabe): Enable this when Cancun is specced, update local head and time, next timestamp
388388
//{&timestampedConfig, 21123456, 1678123456, ID{Hash: checksumToBytes(0x71147644), Next: 1678000000}, nil},
389389

390-
// Local is mainnet Osaka, remote announces Shanghai + knowledge about Cancun. Remote
391-
// is definitely out of sync. It may or may not need the Osaka update, we don't know yet.
390+
// Local is mainnet Prague, remote announces Shanghai + knowledge about Cancun. Remote
391+
// is definitely out of sync. It may or may not need the Prague update, we don't know yet.
392392
//
393-
// TODO(karalabe): Enable this when Cancun **and** Osaka is specced, update all the numbers
393+
// TODO(karalabe): Enable this when Cancun **and** Prague is specced, update all the numbers
394394
//{&timestampedConfig, 0, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}, nil},
395395

396396
// Local is mainnet Shanghai, remote announces Cancun. Local is out of sync, accept.
397397
//
398398
// TODO(karalabe): Enable this when Cancun is specced, update remote checksum
399399
//{&timestampedConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},
400400

401-
// Local is mainnet Shanghai, remote announces Cancun, but is not aware of Osaka. Local
401+
// Local is mainnet Shanghai, remote announces Cancun, but is not aware of Prague. Local
402402
// out of sync. Local also knows about a future fork, but that is uncertain yet.
403403
//
404-
// TODO(karalabe): Enable this when Cancun **and** Osaka is specced, update remote checksum
404+
// TODO(karalabe): Enable this when Cancun **and** Prague is specced, update remote checksum
405405
//{&timestampedConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},
406406

407407
// Local is mainnet Cancun. remote announces Shanghai but is not aware of further forks.

params/config.go

Lines changed: 143 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,124 @@ var (
266266

267267
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
268268
// and accepted by the Ethereum core developers into the Ethash consensus.
269-
//
270-
// This configuration is intentionally not using keyed fields to force anyone
271-
// adding flags to the config to also have to set these fields.
272-
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, false, new(EthashConfig), nil}
269+
AllEthashProtocolChanges = &ChainConfig{
270+
ChainID: big.NewInt(1337),
271+
HomesteadBlock: big.NewInt(0),
272+
DAOForkBlock: nil,
273+
DAOForkSupport: false,
274+
EIP150Block: big.NewInt(0),
275+
EIP150Hash: common.Hash{},
276+
EIP155Block: big.NewInt(0),
277+
EIP158Block: big.NewInt(0),
278+
ByzantiumBlock: big.NewInt(0),
279+
ConstantinopleBlock: big.NewInt(0),
280+
PetersburgBlock: big.NewInt(0),
281+
IstanbulBlock: big.NewInt(0),
282+
MuirGlacierBlock: big.NewInt(0),
283+
BerlinBlock: big.NewInt(0),
284+
LondonBlock: big.NewInt(0),
285+
ArrowGlacierBlock: big.NewInt(0),
286+
GrayGlacierBlock: big.NewInt(0),
287+
MergeNetsplitBlock: nil,
288+
ShanghaiTime: nil,
289+
CancunTime: nil,
290+
PragueTime: nil,
291+
TerminalTotalDifficulty: nil,
292+
TerminalTotalDifficultyPassed: false,
293+
Ethash: new(EthashConfig),
294+
Clique: nil,
295+
}
273296

274297
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
275298
// and accepted by the Ethereum core developers into the Clique consensus.
276-
//
277-
// This configuration is intentionally not using keyed fields to force anyone
278-
// adding flags to the config to also have to set these fields.
279-
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, false, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
280-
281-
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, false, new(EthashConfig), nil}
282-
NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, new(EthashConfig), nil}
283-
TestRules = TestChainConfig.Rules(new(big.Int), false, new(big.Int))
299+
AllCliqueProtocolChanges = &ChainConfig{
300+
ChainID: big.NewInt(1337),
301+
HomesteadBlock: big.NewInt(0),
302+
DAOForkBlock: nil,
303+
DAOForkSupport: false,
304+
EIP150Block: big.NewInt(0),
305+
EIP150Hash: common.Hash{},
306+
EIP155Block: big.NewInt(0),
307+
EIP158Block: big.NewInt(0),
308+
ByzantiumBlock: big.NewInt(0),
309+
ConstantinopleBlock: big.NewInt(0),
310+
PetersburgBlock: big.NewInt(0),
311+
IstanbulBlock: big.NewInt(0),
312+
MuirGlacierBlock: big.NewInt(0),
313+
BerlinBlock: big.NewInt(0),
314+
LondonBlock: big.NewInt(0),
315+
ArrowGlacierBlock: nil,
316+
GrayGlacierBlock: nil,
317+
MergeNetsplitBlock: nil,
318+
ShanghaiTime: nil,
319+
CancunTime: nil,
320+
PragueTime: nil,
321+
TerminalTotalDifficulty: nil,
322+
TerminalTotalDifficultyPassed: false,
323+
Ethash: nil,
324+
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
325+
}
326+
327+
// TestChainConfig contains every protocol change (EIPs) introduced
328+
// and accepted by the Ethereum core developers for testing proposes.
329+
TestChainConfig = &ChainConfig{
330+
ChainID: big.NewInt(1),
331+
HomesteadBlock: big.NewInt(0),
332+
DAOForkBlock: nil,
333+
DAOForkSupport: false,
334+
EIP150Block: big.NewInt(0),
335+
EIP150Hash: common.Hash{},
336+
EIP155Block: big.NewInt(0),
337+
EIP158Block: big.NewInt(0),
338+
ByzantiumBlock: big.NewInt(0),
339+
ConstantinopleBlock: big.NewInt(0),
340+
PetersburgBlock: big.NewInt(0),
341+
IstanbulBlock: big.NewInt(0),
342+
MuirGlacierBlock: big.NewInt(0),
343+
BerlinBlock: big.NewInt(0),
344+
LondonBlock: big.NewInt(0),
345+
ArrowGlacierBlock: big.NewInt(0),
346+
GrayGlacierBlock: big.NewInt(0),
347+
MergeNetsplitBlock: nil,
348+
ShanghaiTime: nil,
349+
CancunTime: nil,
350+
PragueTime: nil,
351+
TerminalTotalDifficulty: nil,
352+
TerminalTotalDifficultyPassed: false,
353+
Ethash: new(EthashConfig),
354+
Clique: nil,
355+
}
356+
357+
// NonActivatedConfig defines the chain configuration without activating
358+
// any protocol change (EIPs).
359+
NonActivatedConfig = &ChainConfig{
360+
ChainID: big.NewInt(1),
361+
HomesteadBlock: nil,
362+
DAOForkBlock: nil,
363+
DAOForkSupport: false,
364+
EIP150Block: nil,
365+
EIP150Hash: common.Hash{},
366+
EIP155Block: nil,
367+
EIP158Block: nil,
368+
ByzantiumBlock: nil,
369+
ConstantinopleBlock: nil,
370+
PetersburgBlock: nil,
371+
IstanbulBlock: nil,
372+
MuirGlacierBlock: nil,
373+
BerlinBlock: nil,
374+
LondonBlock: nil,
375+
ArrowGlacierBlock: nil,
376+
GrayGlacierBlock: nil,
377+
MergeNetsplitBlock: nil,
378+
ShanghaiTime: nil,
379+
CancunTime: nil,
380+
PragueTime: nil,
381+
TerminalTotalDifficulty: nil,
382+
TerminalTotalDifficultyPassed: false,
383+
Ethash: new(EthashConfig),
384+
Clique: nil,
385+
}
386+
TestRules = TestChainConfig.Rules(new(big.Int), false, new(big.Int))
284387
)
285388

286389
// NetworkNames are user friendly names to use in the chain spec banner.
@@ -370,11 +473,12 @@ type ChainConfig struct {
370473
ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
371474
GrayGlacierBlock *big.Int `json:"grayGlacierBlock,omitempty"` // Eip-5133 (bomb delay) switch block (nil = no fork, 0 = already activated)
372475
MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter
373-
CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch block (nil = no fork, 0 = already on cancun)
374476

375477
// Fork scheduling was switched from blocks to timestamps here
376478

377479
ShanghaiTime *big.Int `json:"shanghaiTime,omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai)
480+
CancunTime *big.Int `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun)
481+
PragueTime *big.Int `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
378482

379483
// TerminalTotalDifficulty is the amount of total difficulty reached by
380484
// the network that triggers the consensus upgrade.
@@ -489,8 +593,11 @@ func (c *ChainConfig) Description() string {
489593
if c.ShanghaiTime != nil {
490594
banner += fmt.Sprintf(" - Shanghai: @%-10v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md)\n", c.ShanghaiTime)
491595
}
492-
if c.CancunBlock != nil {
493-
banner += fmt.Sprintf(" - Cancun: @%-10v\n", c.CancunBlock)
596+
if c.CancunTime != nil {
597+
banner += fmt.Sprintf(" - Cancun: @%-10v\n", c.CancunTime)
598+
}
599+
if c.PragueTime != nil {
600+
banner += fmt.Sprintf(" - Prague: @%-10v\n", c.PragueTime)
494601
}
495602
return banner
496603
}
@@ -575,16 +682,21 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
575682
return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
576683
}
577684

578-
// IsCancun returns whether num is either equal to the Cancun fork block or greater.
579-
func (c *ChainConfig) IsCancun(num *big.Int) bool {
580-
return isBlockForked(c.CancunBlock, num)
581-
}
582-
583685
// IsShanghai returns whether time is either equal to the Shanghai fork time or greater.
584686
func (c *ChainConfig) IsShanghai(time *big.Int) bool {
585687
return isTimestampForked(c.ShanghaiTime, time)
586688
}
587689

690+
// IsCancun returns whether num is either equal to the Cancun fork time or greater.
691+
func (c *ChainConfig) IsCancun(time *big.Int) bool {
692+
return isTimestampForked(c.CancunTime, time)
693+
}
694+
695+
// IsPrague returns whether num is either equal to the Prague fork time or greater.
696+
func (c *ChainConfig) IsPrague(time *big.Int) bool {
697+
return isTimestampForked(c.PragueTime, time)
698+
}
699+
588700
// CheckCompatible checks whether scheduled fork transitions have been imported
589701
// with a mismatching chain configuration.
590702
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError {
@@ -636,8 +748,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
636748
{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
637749
{name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true},
638750
{name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true},
639-
{name: "cancunBlock", block: c.CancunBlock, optional: true},
640751
{name: "shanghaiTime", timestamp: c.ShanghaiTime},
752+
{name: "cancunTime", timestamp: c.CancunTime, optional: true},
753+
{name: "pragueTime", timestamp: c.PragueTime, optional: true},
641754
} {
642755
if lastFork.name != "" {
643756
switch {
@@ -732,12 +845,15 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
732845
if isForkBlockIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, headNumber) {
733846
return newBlockCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock)
734847
}
735-
if isForkBlockIncompatible(c.CancunBlock, newcfg.CancunBlock, headNumber) {
736-
return newBlockCompatError("Cancun fork block", c.CancunBlock, newcfg.CancunBlock)
737-
}
738848
if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) {
739849
return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime)
740850
}
851+
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) {
852+
return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime)
853+
}
854+
if isForkTimestampIncompatible(c.PragueTime, newcfg.PragueTime, headTimestamp) {
855+
return newTimestampCompatError("Prague fork timestamp", c.PragueTime, newcfg.PragueTime)
856+
}
741857
return nil
742858
}
743859

@@ -882,7 +998,7 @@ type Rules struct {
882998
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
883999
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
8841000
IsBerlin, IsLondon bool
885-
IsMerge, IsShanghai, isCancun bool
1001+
IsMerge, IsShanghai, isCancun, isPrague bool
8861002
}
8871003

8881004
// Rules ensures c's ChainID is not nil.
@@ -905,6 +1021,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp *big.Int) Rule
9051021
IsLondon: c.IsLondon(num),
9061022
IsMerge: isMerge,
9071023
IsShanghai: c.IsShanghai(timestamp),
908-
isCancun: c.IsCancun(num),
1024+
isCancun: c.IsCancun(timestamp),
1025+
isPrague: c.IsPrague(timestamp),
9091026
}
9101027
}

0 commit comments

Comments
 (0)