Skip to content

Commit

Permalink
Merge pull request #104 from testinprod-io/pcw109550/canyon/chainspec
Browse files Browse the repository at this point in the history
[Canyon Hard Fork] Update chainspecs
  • Loading branch information
ImTei authored Nov 8, 2023
2 parents 4f7093d + f48892f commit 22c57fb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
9 changes: 9 additions & 0 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime,
config.CanyonTime = overrideOptimismCanyonTime
// Shanghai hardfork is included in canyon hardfork
config.ShanghaiTime = overrideOptimismCanyonTime
if config.Optimism.EIP1559DenominatorCanyon == 0 {
logger.Warn("EIP1559DenominatorCanyon set to 0. Overriding to 250 to avoid divide by zero.")
config.Optimism.EIP1559DenominatorCanyon = 250
}
}
if overrideShanghaiTime != nil && config.IsOptimism() && overrideOptimismCanyonTime != nil {
if overrideShanghaiTime.Cmp(overrideOptimismCanyonTime) != 0 {
Expand All @@ -114,6 +118,11 @@ func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime,
if config.IsOptimism() && config.ChainID != nil {
if config.ChainID.Cmp(params.OptimismGoerliChainConfig.ChainID) == 0 {
config.RegolithTime = params.OptimismGoerliChainConfig.RegolithTime
if overrideOptimismCanyonTime == nil {
// fall back to default hardfork time
config.ShanghaiTime = params.OptimismGoerliChainConfig.ShanghaiTime
config.CanyonTime = params.OptimismGoerliChainConfig.CanyonTime
}
} else if config.ChainID.Cmp(params.OptimismMainnetChainConfig.ChainID) == 0 {
config.RegolithTime = params.OptimismMainnetChainConfig.RegolithTime
}
Expand Down
9 changes: 7 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,13 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
backend.genesisHash = genesis.Hash()

logger.Info("Initialised chain configuration", "config", chainConfig, "genesis", genesis.Hash())
if chainConfig.IsOptimism() && chainConfig.RegolithTime == nil {
log.Warn("Optimism RegolithTime has not been set")
if chainConfig.IsOptimism() {
if chainConfig.RegolithTime == nil {
log.Warn("Optimism RegolithTime has not been set")
}
if chainConfig.CanyonTime == nil {
log.Warn("Optimism CanyonTime has not been set")
}
}

if err := backend.setUpSnapDownloader(ctx, config.Downloader); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions params/chainspecs/optimism-devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"terminalTotalDifficultyPassed": true,
"optimism": {
"eip1559Elasticity": 2,
"eip1559Denominator": 8
"eip1559Denominator": 8,
"eip1559DenominatorCanyon": 250
},
"regolithTime": 0
"regolithTime": 0,
"shanghaiTime": 2,
"canyonTime": 2
}
7 changes: 5 additions & 2 deletions params/chainspecs/optimism-goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"terminalTotalDifficultyPassed": true,
"optimism": {
"eip1559Elasticity": 10,
"eip1559Denominator": 50
"eip1559Denominator": 50,
"eip1559DenominatorCanyon": 250
},
"regolithTime": 1679079600
"regolithTime": 1679079600,
"shanghaiTime": 1698436800,
"canyonTime": 1698436800
}
27 changes: 27 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,30 @@ func TestCheckCompatible(t *testing.T) {
}
}
}

// TODO: remove when superchain-registry is integrated
// TestCanyonTimestampOnBlockBoundary asserts that Canyon will activate on a block's timestamp.
// This is critical because the create2Deployer only activates on a block's timestamp.
func TestCanyonTimestampOnBlockBoundary(t *testing.T) {
superchainConfigs := []*chain.Config{OptimismMainnetChainConfig, OptimismGoerliChainConfig, OptimismDevnetChainConfig}
l2BlockTime := 2
for _, config := range superchainConfigs {
if config.CanyonTime == nil {
continue
}
regolithTime := 0
if config.RegolithTime != nil {
regolithTime = int(config.RegolithTime.Int64())
}
canyonTime := int(config.CanyonTime.Int64())
if regolithTime > canyonTime {
t.Fatalf("Canyon time on superchain %v is less then Regolith time. canyon time: %v, regolith time: %v",
config.ChainName, canyonTime, regolithTime)
}
canyonOffset := canyonTime - regolithTime
if canyonOffset%l2BlockTime != 0 {
t.Fatalf("Canyon time on superchain %v is not on the block time. canyon time: %v, regolith time: %v, block time: %v",
config.ChainName, canyonTime, regolithTime, l2BlockTime)
}
}
}

0 comments on commit 22c57fb

Please sign in to comment.