Skip to content

Commit

Permalink
Merge pull request #371 from ethereum-optimism/gk/elastic
Browse files Browse the repository at this point in the history
Read Optimism Config from superchain-registry
  • Loading branch information
geoknee authored Aug 28, 2024
2 parents 110c433 + 673a11f commit 6003812
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 66 deletions.
9 changes: 0 additions & 9 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,6 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
}
}
}

if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.OPGoerliChainID)) == 0 {
// Apply Optimism Goerli regolith time
config.RegolithTime = &params.OptimismGoerliRegolithTime
}
if config.IsOptimism() && config.ChainID != nil && config.ChainID.Cmp(big.NewInt(params.BaseGoerliChainID)) == 0 {
// Apply Base Goerli regolith time
config.RegolithTime = &params.BaseGoerliRegolithTime
}
if overrides != nil && overrides.OverrideCancun != nil {
config.CancunTime = overrides.OverrideCancun
}
Expand Down
2 changes: 0 additions & 2 deletions core/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func LoadOPStackGenesis(chainID uint64) (*Genesis, error) {
switch chainID {
case params.OPMainnetChainID:
expectedHash = common.HexToHash("0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b")
case params.OPGoerliChainID:
expectedHash = common.HexToHash("0xc1fc15cd51159b1f1e5cbc4b82e85c1447ddfa33c52cf1d98d14fba0d6354be1")
default:
return nil, fmt.Errorf("unknown stateless genesis definition for chain %d", chainID)
}
Expand Down
3 changes: 3 additions & 0 deletions core/superchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func TestRegistryChainConfigOverride(t *testing.T) {
rawdb.WriteCanonicalHash(db, bl.Hash(), 0)
rawdb.WriteBlock(db, bl)

if genesis.Config.Optimism == nil {
t.Fatal("expected non nil Optimism config")
}
genesis.Config.Optimism.EIP1559DenominatorCanyon = tt.setDenominator
// create chain config, even with incomplete genesis input: the chain config should be corrected
chainConfig, _, err := SetupGenesisBlockWithOverride(db, tdb, genesis, tt.overrides)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/deckarep/golang-set/v2 v2.6.0
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240821192748-42bd03ba8313
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240828144951-4e6edcb7d36c
github.com/ethereum/c-kzg-4844 v1.0.0
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0
github.com/fatih/color v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240821192748-42bd03ba8313 h1:SVSFg8ccdRBJxOdRS1pK8oIHvMufiPAQz1gkQsEPnZc=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240821192748-42bd03ba8313/go.mod h1:XaVXL9jg8BcyOeugECgIUGa9Y3DjYJj71RHmb5qon6M=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240828144951-4e6edcb7d36c h1:wI6W6CimquWKoD6eZ0GhULXmiZynynzLBCPnsFKt+Y0=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240828144951-4e6edcb7d36c/go.mod h1:XaVXL9jg8BcyOeugECgIUGa9Y3DjYJj71RHmb5qon6M=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4=
Expand Down
26 changes: 3 additions & 23 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,9 @@ var (
)

const (
OPMainnetChainID = 10
OPGoerliChainID = 420
BaseMainnetChainID = 8453
BaseGoerliChainID = 84531
baseSepoliaChainID = 84532
baseGoerliDevnetChainID = 11763071
pgnSepoliaChainID = 58008
devnetChainID = 997
chaosnetChainID = 888
)

// OP Stack chain config
var (
// March 17, 2023 @ 7:00:00 pm UTC
OptimismGoerliRegolithTime = uint64(1679079600)
// May 4, 2023 @ 5:00:00 pm UTC
BaseGoerliRegolithTime = uint64(1683219600)
// Apr 21, 2023 @ 6:30:00 pm UTC
baseGoerliDevnetRegolithTime = uint64(1682101800)
// March 5, 2023 @ 2:48:00 am UTC
devnetRegolithTime = uint64(1677984480)
// August 16, 2023 @ 3:34:22 am UTC
chaosnetRegolithTime = uint64(1692156862)
OPMainnetChainID = 10
BaseMainnetChainID = 8453
baseSepoliaChainID = 84532
)

func newUint64(val uint64) *uint64 { return &val }
Expand Down
44 changes: 15 additions & 29 deletions params/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func OPStackChainNames() (out []string) {
return
}

// uint64ptr is a weird helper to allow 1-line constant pointer creation.
func uint64ptr(n uint64) *uint64 {
return &n
}

func LoadOPStackChainConfig(chainID uint64) (*ChainConfig, error) {
chConfig, ok := superchain.OPChains[chainID]
if !ok {
Expand Down Expand Up @@ -75,46 +80,27 @@ func LoadOPStackChainConfig(chainID uint64) (*ChainConfig, error) {
TerminalTotalDifficultyPassed: true,
Ethash: nil,
Clique: nil,
Optimism: &OptimismConfig{
EIP1559Elasticity: 6,
EIP1559Denominator: 50,
EIP1559DenominatorCanyon: newUint64(250),
},
}

if chConfig.Optimism != nil {
out.Optimism = &OptimismConfig{
EIP1559Elasticity: chConfig.Optimism.EIP1559Elasticity,
EIP1559Denominator: chConfig.Optimism.EIP1559Denominator,
}
if chConfig.Optimism.EIP1559DenominatorCanyon != nil {
out.Optimism.EIP1559DenominatorCanyon = uint64ptr(*chConfig.Optimism.EIP1559DenominatorCanyon)
}
}

// special overrides for OP-Stack chains with pre-Regolith upgrade history
switch chainID {
case OPGoerliChainID:
out.LondonBlock = big.NewInt(4061224)
out.ArrowGlacierBlock = big.NewInt(4061224)
out.GrayGlacierBlock = big.NewInt(4061224)
out.MergeNetsplitBlock = big.NewInt(4061224)
out.BedrockBlock = big.NewInt(4061224)
out.RegolithTime = &OptimismGoerliRegolithTime
out.Optimism.EIP1559Elasticity = 10
case OPMainnetChainID:
out.BerlinBlock = big.NewInt(3950000)
out.LondonBlock = big.NewInt(105235063)
out.ArrowGlacierBlock = big.NewInt(105235063)
out.GrayGlacierBlock = big.NewInt(105235063)
out.MergeNetsplitBlock = big.NewInt(105235063)
out.BedrockBlock = big.NewInt(105235063)
case BaseGoerliChainID:
out.RegolithTime = &BaseGoerliRegolithTime
out.Optimism.EIP1559Elasticity = 10
case baseSepoliaChainID:
out.Optimism.EIP1559Elasticity = 10
case baseGoerliDevnetChainID:
out.RegolithTime = &baseGoerliDevnetRegolithTime
case pgnSepoliaChainID:
out.Optimism.EIP1559Elasticity = 2
out.Optimism.EIP1559Denominator = 8
case devnetChainID:
out.RegolithTime = &devnetRegolithTime
out.Optimism.EIP1559Elasticity = 10
case chaosnetChainID:
out.RegolithTime = &chaosnetRegolithTime
out.Optimism.EIP1559Elasticity = 10
}

return out, nil
Expand Down

0 comments on commit 6003812

Please sign in to comment.