From d2593d5ec3a3487c50f7afb544a54b7304164b39 Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev Date: Thu, 13 Jun 2024 18:01:37 +0300 Subject: [PATCH] Add Capella hard fork to networks in eth2util --- cmd/run.go | 1 + docs/configuration.md | 1 + eth2util/helper_capella.go | 20 ++++++++------------ eth2util/network.go | 7 +++++++ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 06cc0c41b..af1faa668 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -85,6 +85,7 @@ func bindRunFlags(cmd *cobra.Command, config *app.Config) { cmd.Flags().StringVar(&config.TestnetConfig.GenesisForkVersionHex, "testnet-fork-version", "", "Genesis fork version in hex of the custom test network.") cmd.Flags().Uint64Var(&config.TestnetConfig.ChainID, "testnet-chain-id", 0, "Chain ID of the custom test network.") cmd.Flags().Int64Var(&config.TestnetConfig.GenesisTimestamp, "testnet-genesis-timestamp", 0, "Genesis timestamp of the custom test network.") + cmd.Flags().StringVar(&config.TestnetConfig.CapellaHardFork, "testnet-capella-hard-fork", "", "Capella hard fork version of the custom test network.") wrapPreRunE(cmd, func(cmd *cobra.Command, args []string) error { if len(config.BeaconNodeAddrs) == 0 && !config.SimnetBMock { diff --git a/docs/configuration.md b/docs/configuration.md index 75bfe90bf..4f2bc0b75 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -181,6 +181,7 @@ Flags: --simnet-validator-keys-dir string The directory containing the simnet validator key shares. (default ".charon/validator_keys") --simnet-validator-mock Enables an internal mock validator client when running a simnet. Requires simnet-beacon-mock. --synthetic-block-proposals Enables additional synthetic block proposal duties. Used for testing of rare duties. + --testnet-capella-hard-fork string Capella hard fork version of the custom test network. --testnet-chain-id uint Chain ID of the custom test network. --testnet-fork-version string Genesis fork version in hex of the custom test network. --testnet-genesis-timestamp int Genesis timestamp of the custom test network. diff --git a/eth2util/helper_capella.go b/eth2util/helper_capella.go index 0ddf7b040..3c44c21f1 100644 --- a/eth2util/helper_capella.go +++ b/eth2util/helper_capella.go @@ -15,23 +15,19 @@ import ( "github.com/obolnetwork/charon/app/errors" ) -var capellaForkMap = map[string]string{ - "0x00000000": "0x03000000", - "0x00001020": "0x03001020", - "0x00000064": "0x03000064", - "0x90000069": "0x90000072", - "0x01017000": "0x04017000", -} - // CapellaFork maps generic fork hashes to their specific Capella hardfork // values. func CapellaFork(forkHash string) (string, error) { - d, ok := capellaForkMap[forkHash] - if !ok { - return "", errors.New("no capella fork for specified fork") + networksMu.Lock() + defer networksMu.Unlock() + + for _, n := range supportedNetworks { + if n.GenesisForkVersionHex == forkHash { + return n.CapellaHardFork, nil + } } - return d, nil + return "", errors.New("no capella fork for specified fork") } type forkDataType struct { diff --git a/eth2util/network.go b/eth2util/network.go index 2fc92b2c7..9811f6882 100644 --- a/eth2util/network.go +++ b/eth2util/network.go @@ -25,6 +25,8 @@ type Network struct { GenesisForkVersionHex string // GenesisTimestamp represents genesis timestamp of the network in unix format GenesisTimestamp int64 + // CapellaHardFork represents capella fork version, used for computing domains for signatures + CapellaHardFork string } // IsNonZero checks if each field in this struct is not equal to its zero value. @@ -39,24 +41,28 @@ var ( Name: "mainnet", GenesisForkVersionHex: "0x00000000", GenesisTimestamp: 1606824023, + CapellaHardFork: "0x03000000", } Goerli = Network{ ChainID: 5, Name: "goerli", GenesisForkVersionHex: "0x00001020", GenesisTimestamp: 1616508000, + CapellaHardFork: "0x03001020", } Gnosis = Network{ ChainID: 100, Name: "gnosis", GenesisForkVersionHex: "0x00000064", GenesisTimestamp: 1638993340, + CapellaHardFork: "0x03000064", } Sepolia = Network{ ChainID: 11155111, Name: "sepolia", GenesisForkVersionHex: "0x90000069", GenesisTimestamp: 1655733600, + CapellaHardFork: "0x90000072", } // Holesky metadata taken from https://github.com/eth-clients/holesky#metadata. Holesky = Network{ @@ -64,6 +70,7 @@ var ( Name: "holesky", GenesisForkVersionHex: "0x01017000", GenesisTimestamp: 1696000704, + CapellaHardFork: "0x04017000", } )