diff --git a/shared/services/bc-manager.go b/shared/services/bc-manager.go index 70fd2e1f..3f3c7dfa 100644 --- a/shared/services/bc-manager.go +++ b/shared/services/bc-manager.go @@ -256,9 +256,9 @@ func (m *BeaconClientManager) GetValidatorProposerDuties(indices []uint64, epoch } // Get the Beacon chain's domain data -func (m *BeaconClientManager) GetExitDomainData(domainType []byte) ([]byte, error) { +func (m *BeaconClientManager) GetExitDomainData(domainType []byte, network cfgtypes.Network) ([]byte, error) { result, err := m.runFunction1(func(client beacon.Client) (interface{}, error) { - return client.GetExitDomainData(domainType) + return client.GetExitDomainData(domainType, network) }) if err != nil { return nil, err diff --git a/shared/services/beacon/client.go b/shared/services/beacon/client.go index 31f9856c..dcbf32b5 100644 --- a/shared/services/beacon/client.go +++ b/shared/services/beacon/client.go @@ -22,6 +22,7 @@ package beacon import ( "github.com/ethereum/go-ethereum/common" "github.com/prysmaticlabs/go-bitfield" + "github.com/stader-labs/stader-node/shared/types/config" "github.com/stader-labs/stader-node/stader-lib/types" ) @@ -143,7 +144,7 @@ type Client interface { GetValidatorIndex(pubkey types.ValidatorPubkey) (uint64, error) GetValidatorSyncDuties(indices []uint64, epoch uint64) (map[uint64]bool, error) GetValidatorProposerDuties(indices []uint64, epoch uint64) (map[uint64]uint64, error) - GetExitDomainData(domainType []byte) ([]byte, error) + GetExitDomainData(domainType []byte, network config.Network) ([]byte, error) ExitValidator(validatorIndex, epoch uint64, signature types.ValidatorSignature) error Close() error GetEth1DataForEth2Block(blockId string) (Eth1Data, bool, error) diff --git a/shared/services/beacon/client/std-http-client.go b/shared/services/beacon/client/std-http-client.go index 61785329..5c7de393 100644 --- a/shared/services/beacon/client/std-http-client.go +++ b/shared/services/beacon/client/std-http-client.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/prysmaticlabs/prysm/v3/crypto/bls" + "github.com/stader-labs/stader-node/shared/types/config" "github.com/stader-labs/stader-node/stader-lib/types" eth2types "github.com/wealdtech/go-eth2-types/v2" "golang.org/x/sync/errgroup" @@ -62,8 +63,6 @@ const ( MaxRequestValidatorsCount = 600 threadLimit int = 6 - - CapellaForkVersion = "0x03001020" ) // Beacon client using the standard Beacon HTTP REST API (https://ethereum.github.io/beacon-APIs/) @@ -411,14 +410,22 @@ func (c *StandardHttpClient) GetValidatorIndex(pubkey types.ValidatorPubkey) (ui } // Get domain data for a domain type at a given epoch -func (c *StandardHttpClient) GetExitDomainData(domainType []byte) ([]byte, error) { +func (c *StandardHttpClient) GetExitDomainData(domainType []byte, network config.Network) ([]byte, error) { var genesis GenesisResponse genesis, err := c.getGenesis() // Get fork version - forkVersion, err := hexutil.Decode(CapellaForkVersion) + var capellaForkVersion string + // TODO - we currently only support mainnet and testnet envs. We will have to update this as we change n/ws + if network == config.Network_Mainnet { + capellaForkVersion = eth2.MainnetCapellaForkVersion + } else { + capellaForkVersion = eth2.GoerliCapellaForkVersion + } + + decodedForkVersion, err := hexutil.Decode(capellaForkVersion) if err != nil { return []byte{}, err } @@ -426,7 +433,7 @@ func (c *StandardHttpClient) GetExitDomainData(domainType []byte) ([]byte, error // Compute & return domain var dt [4]byte copy(dt[:], domainType[:]) - return eth2types.Domain(dt, forkVersion, genesis.Data.GenesisValidatorsRoot), nil + return eth2types.Domain(dt, decodedForkVersion, genesis.Data.GenesisValidatorsRoot), nil } diff --git a/shared/utils/eth2/eth2.go b/shared/utils/eth2/eth2.go index 89eec3a6..0406c407 100644 --- a/shared/utils/eth2/eth2.go +++ b/shared/utils/eth2/eth2.go @@ -23,6 +23,11 @@ import ( "github.com/stader-labs/stader-node/shared/services/beacon" ) +const ( + GoerliCapellaForkVersion = "0x03001020" + MainnetCapellaForkVersion = "0x03000000" +) + // Get an eth2 epoch number by time func EpochAt(config beacon.Eth2Config, time uint64) uint64 { return config.GenesisEpoch + (time-config.GenesisTime)/config.SecondsPerEpoch diff --git a/stader/api/validator/exit.go b/stader/api/validator/exit.go index 668e8f21..7789a1c2 100644 --- a/stader/api/validator/exit.go +++ b/stader/api/validator/exit.go @@ -1,8 +1,11 @@ package validator import ( + "fmt" + "github.com/stader-labs/stader-node/shared/services" "github.com/stader-labs/stader-node/shared/types/api" + "github.com/stader-labs/stader-node/shared/types/config" "github.com/stader-labs/stader-node/shared/utils/eth2" "github.com/stader-labs/stader-node/shared/utils/validator" "github.com/stader-labs/stader-node/stader-lib/types" @@ -83,6 +86,11 @@ func exitValidator(c *cli.Context, validatorPubKey types.ValidatorPubkey) (*api. return nil, err } + network, ok := cfg.StaderNode.Network.Value.(config.Network) + if !ok { + return nil, fmt.Errorf("invalid network configuration: %s", cfg.StaderNode.Network.Value) + } + // Response response := api.ExitValidatorResponse{} @@ -93,7 +101,7 @@ func exitValidator(c *cli.Context, validatorPubKey types.ValidatorPubkey) (*api. } // Get voluntary exit signature domain - signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:]) + signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:], network) if err != nil { return nil, err } diff --git a/stader/node/node.go b/stader/node/node.go index 20b288e7..77184a44 100644 --- a/stader/node/node.go +++ b/stader/node/node.go @@ -30,6 +30,7 @@ import ( "sync" "time" + cfgtypes "github.com/stader-labs/stader-node/shared/types/config" stader_backend "github.com/stader-labs/stader-node/shared/types/stader-backend" "github.com/stader-labs/stader-node/shared/utils/crypto" "github.com/stader-labs/stader-node/shared/utils/eth2" @@ -153,6 +154,18 @@ func run(c *cli.Context) error { } } + cfg, err := services.GetConfig(c) + if err != nil { + errorLog.Printf("Failed to get config with error %s\n", err.Error()) + continue + } + + network, ok := cfg.StaderNode.Network.Value.(cfgtypes.Network) + if !ok { + errorLog.Printf("Failed to get network from config: %s\n", cfg.StaderNode.Network.Value) + continue + } + operatorId, err := node.GetOperatorId(pnr, nodeAccount.Address, nil) if err != nil { errorLog.Printf("Failed to get operator id: %s\n", err.Error()) @@ -257,7 +270,7 @@ func run(c *cli.Context) error { exitEpoch := currentHead.Epoch - signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:]) + signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:], network) if err != nil { errorLog.Printf("Failed to get the signature domain from beacon chain with err: %s\n", err.Error()) continue