superchain.go 3.71 KB
Newer Older
1 2 3 4 5 6
package rollup

import (
	"fmt"
	"math/big"

7 8
	"github.com/ethereum/go-ethereum/params"

9 10 11 12 13 14
	"github.com/ethereum/go-ethereum/common"

	"github.com/ethereum-optimism/optimism/op-service/eth"
	"github.com/ethereum-optimism/superchain-registry/superchain"
)

15
var OPStackSupport = params.ProtocolVersionV0{Build: [8]byte{}, Major: 9, Minor: 0, Patch: 0, PreRelease: 0}.Encode()
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// LoadOPStackRollupConfig loads the rollup configuration of the requested chain ID from the superchain-registry.
// Some chains may require a SystemConfigProvider to retrieve any values not part of the registry.
func LoadOPStackRollupConfig(chainID uint64) (*Config, error) {
	chConfig, ok := superchain.OPChains[chainID]
	if !ok {
		return nil, fmt.Errorf("unknown chain ID: %d", chainID)
	}

	superChain, ok := superchain.Superchains[chConfig.Superchain]
	if !ok {
		return nil, fmt.Errorf("chain %d specifies unknown superchain: %q", chainID, chConfig.Superchain)
	}

	var genesisSysConfig eth.SystemConfig
	if sysCfg, ok := superchain.GenesisSystemConfigs[chainID]; ok {
		genesisSysConfig = eth.SystemConfig{
			BatcherAddr: common.Address(sysCfg.BatcherAddr),
			Overhead:    eth.Bytes32(sysCfg.Overhead),
			Scalar:      eth.Bytes32(sysCfg.Scalar),
			GasLimit:    sysCfg.GasLimit,
		}
	} else {
		return nil, fmt.Errorf("unable to retrieve genesis SystemConfig of chain %d", chainID)
	}

42 43
	addrs, ok := superchain.Addresses[chainID]
	if !ok {
44 45 46
		return nil, fmt.Errorf("unable to retrieve deposit contract address")
	}

47 48
	var altDA *AltDAConfig
	if chConfig.AltDA != nil {
49 50 51 52 53 54 55 56 57 58 59 60
		altDA = &AltDAConfig{}
		if chConfig.AltDA.DAChallengeAddress != nil {
			altDA.DAChallengeAddress = common.Address(*chConfig.AltDA.DAChallengeAddress)
		}
		if chConfig.AltDA.DAChallengeWindow != nil {
			altDA.DAChallengeWindow = *chConfig.AltDA.DAChallengeWindow
		}
		if chConfig.AltDA.DAResolveWindow != nil {
			altDA.DAResolveWindow = *chConfig.AltDA.DAResolveWindow
		}
		if chConfig.AltDA.DACommitmentType != nil {
			altDA.CommitmentType = *chConfig.AltDA.DACommitmentType
61 62 63
		}
	}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	regolithTime := uint64(0)
	cfg := &Config{
		Genesis: Genesis{
			L1: eth.BlockID{
				Hash:   common.Hash(chConfig.Genesis.L1.Hash),
				Number: chConfig.Genesis.L1.Number,
			},
			L2: eth.BlockID{
				Hash:   common.Hash(chConfig.Genesis.L2.Hash),
				Number: chConfig.Genesis.L2.Number,
			},
			L2Time:       chConfig.Genesis.L2Time,
			SystemConfig: genesisSysConfig,
		},
		// The below chain parameters can be different per OP-Stack chain,
79 80 81 82
		// therefore they are read from the superchain-registry configs.
		// Note: hardcoded values are not yet represented in the registry but should be
		// soon, then will be read and set in the same fashion.
		BlockTime:              chConfig.BlockTime,
83
		MaxSequencerDrift:      chConfig.MaxSequencerDrift,
84
		SeqWindowSize:          chConfig.SequencerWindowSize,
85
		ChannelTimeoutBedrock:  300,
86 87 88
		L1ChainID:              new(big.Int).SetUint64(superChain.Config.L1.ChainID),
		L2ChainID:              new(big.Int).SetUint64(chConfig.ChainID),
		RegolithTime:           &regolithTime,
89 90 91 92
		CanyonTime:             chConfig.CanyonTime,
		DeltaTime:              chConfig.DeltaTime,
		EcotoneTime:            chConfig.EcotoneTime,
		FjordTime:              chConfig.FjordTime,
93
		GraniteTime:            chConfig.GraniteTime,
94
		HoloceneTime:           chConfig.HoloceneTime,
95
		BatchInboxAddress:      common.Address(chConfig.BatchInboxAddr),
96 97
		DepositContractAddress: common.Address(addrs.OptimismPortalProxy),
		L1SystemConfigAddress:  common.Address(addrs.SystemConfigProxy),
98
		AltDAConfig:            altDA,
99
	}
100

101 102 103
	if superChain.Config.ProtocolVersionsAddr != nil { // Set optional protocol versions address
		cfg.ProtocolVersionsAddress = common.Address(*superChain.Config.ProtocolVersionsAddr)
	}
104 105
	return cfg, nil
}