github.com/ethereum/go-ethereum@v1.14.3/beacon/blsync/config.go (about)

     1  // Copyright 2022 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package blsync
    18  
    19  import (
    20  	"github.com/ethereum/go-ethereum/beacon/types"
    21  	"github.com/ethereum/go-ethereum/cmd/utils"
    22  	"github.com/ethereum/go-ethereum/common"
    23  	"github.com/ethereum/go-ethereum/common/hexutil"
    24  	"github.com/urfave/cli/v2"
    25  )
    26  
    27  // lightClientConfig contains beacon light client configuration
    28  type lightClientConfig struct {
    29  	*types.ChainConfig
    30  	Checkpoint common.Hash
    31  }
    32  
    33  var (
    34  	MainnetConfig = lightClientConfig{
    35  		ChainConfig: (&types.ChainConfig{
    36  			GenesisValidatorsRoot: common.HexToHash("0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"),
    37  			GenesisTime:           1606824023,
    38  		}).
    39  			AddFork("GENESIS", 0, []byte{0, 0, 0, 0}).
    40  			AddFork("ALTAIR", 74240, []byte{1, 0, 0, 0}).
    41  			AddFork("BELLATRIX", 144896, []byte{2, 0, 0, 0}).
    42  			AddFork("CAPELLA", 194048, []byte{3, 0, 0, 0}).
    43  			AddFork("DENEB", 269568, []byte{4, 0, 0, 0}),
    44  		Checkpoint: common.HexToHash("0x388be41594ec7d6a6894f18c73f3469f07e2c19a803de4755d335817ed8e2e5a"),
    45  	}
    46  
    47  	SepoliaConfig = lightClientConfig{
    48  		ChainConfig: (&types.ChainConfig{
    49  			GenesisValidatorsRoot: common.HexToHash("0xd8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078"),
    50  			GenesisTime:           1655733600,
    51  		}).
    52  			AddFork("GENESIS", 0, []byte{144, 0, 0, 105}).
    53  			AddFork("ALTAIR", 50, []byte{144, 0, 0, 112}).
    54  			AddFork("BELLATRIX", 100, []byte{144, 0, 0, 113}).
    55  			AddFork("CAPELLA", 56832, []byte{144, 0, 0, 114}).
    56  			AddFork("DENEB", 132608, []byte{144, 0, 0, 115}),
    57  		Checkpoint: common.HexToHash("0x1005a6d9175e96bfbce4d35b80f468e9bff0b674e1e861d16e09e10005a58e81"),
    58  	}
    59  
    60  	GoerliConfig = lightClientConfig{
    61  		ChainConfig: (&types.ChainConfig{
    62  			GenesisValidatorsRoot: common.HexToHash("0x043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb"),
    63  			GenesisTime:           1614588812,
    64  		}).
    65  			AddFork("GENESIS", 0, []byte{0, 0, 16, 32}).
    66  			AddFork("ALTAIR", 36660, []byte{1, 0, 16, 32}).
    67  			AddFork("BELLATRIX", 112260, []byte{2, 0, 16, 32}).
    68  			AddFork("CAPELLA", 162304, []byte{3, 0, 16, 32}).
    69  			AddFork("DENEB", 231680, []byte{4, 0, 16, 32}),
    70  		Checkpoint: common.HexToHash("0x53a0f4f0a378e2c4ae0a9ee97407eb69d0d737d8d8cd0a5fb1093f42f7b81c49"),
    71  	}
    72  )
    73  
    74  func makeChainConfig(ctx *cli.Context) lightClientConfig {
    75  	var config lightClientConfig
    76  	customConfig := ctx.IsSet(utils.BeaconConfigFlag.Name)
    77  	utils.CheckExclusive(ctx, utils.MainnetFlag, utils.GoerliFlag, utils.SepoliaFlag, utils.BeaconConfigFlag)
    78  	switch {
    79  	case ctx.Bool(utils.MainnetFlag.Name):
    80  		config = MainnetConfig
    81  	case ctx.Bool(utils.SepoliaFlag.Name):
    82  		config = SepoliaConfig
    83  	case ctx.Bool(utils.GoerliFlag.Name):
    84  		config = GoerliConfig
    85  	default:
    86  		if !customConfig {
    87  			config = MainnetConfig
    88  		}
    89  	}
    90  	// Genesis root and time should always be specified together with custom chain config
    91  	if customConfig {
    92  		if !ctx.IsSet(utils.BeaconGenesisRootFlag.Name) {
    93  			utils.Fatalf("Custom beacon chain config is specified but genesis root is missing")
    94  		}
    95  		if !ctx.IsSet(utils.BeaconGenesisTimeFlag.Name) {
    96  			utils.Fatalf("Custom beacon chain config is specified but genesis time is missing")
    97  		}
    98  		if !ctx.IsSet(utils.BeaconCheckpointFlag.Name) {
    99  			utils.Fatalf("Custom beacon chain config is specified but checkpoint is missing")
   100  		}
   101  		config.ChainConfig = &types.ChainConfig{
   102  			GenesisTime: ctx.Uint64(utils.BeaconGenesisTimeFlag.Name),
   103  		}
   104  		if c, err := hexutil.Decode(ctx.String(utils.BeaconGenesisRootFlag.Name)); err == nil && len(c) <= 32 {
   105  			copy(config.GenesisValidatorsRoot[:len(c)], c)
   106  		} else {
   107  			utils.Fatalf("Invalid hex string", "beacon.genesis.gvroot", ctx.String(utils.BeaconGenesisRootFlag.Name), "error", err)
   108  		}
   109  		if err := config.ChainConfig.LoadForks(ctx.String(utils.BeaconConfigFlag.Name)); err != nil {
   110  			utils.Fatalf("Could not load beacon chain config file", "file name", ctx.String(utils.BeaconConfigFlag.Name), "error", err)
   111  		}
   112  	} else {
   113  		if ctx.IsSet(utils.BeaconGenesisRootFlag.Name) {
   114  			utils.Fatalf("Genesis root is specified but custom beacon chain config is missing")
   115  		}
   116  		if ctx.IsSet(utils.BeaconGenesisTimeFlag.Name) {
   117  			utils.Fatalf("Genesis time is specified but custom beacon chain config is missing")
   118  		}
   119  	}
   120  	// Checkpoint is required with custom chain config and is optional with pre-defined config
   121  	if ctx.IsSet(utils.BeaconCheckpointFlag.Name) {
   122  		if c, err := hexutil.Decode(ctx.String(utils.BeaconCheckpointFlag.Name)); err == nil && len(c) <= 32 {
   123  			copy(config.Checkpoint[:len(c)], c)
   124  		} else {
   125  			utils.Fatalf("Invalid hex string", "beacon.checkpoint", ctx.String(utils.BeaconCheckpointFlag.Name), "error", err)
   126  		}
   127  	}
   128  	return config
   129  }