diff --git a/shared/services/bc-manager.go b/shared/services/bc-manager.go index 2fa11124f..0dd042bfa 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) GetDomainData(domainType []byte, epoch uint64, useGenesisFork bool) ([]byte, error) { +func (m *BeaconClientManager) GetExitDomainData(domainType []byte) ([]byte, error) { result, err := m.runFunction1(func(client beacon.Client) (interface{}, error) { - return client.GetDomainData(domainType, epoch, useGenesisFork) + return client.GetExitDomainData(domainType) }) if err != nil { return nil, err diff --git a/shared/services/beacon/client.go b/shared/services/beacon/client.go index 273d82cbf..cd261f283 100644 --- a/shared/services/beacon/client.go +++ b/shared/services/beacon/client.go @@ -143,7 +143,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) - GetDomainData(domainType []byte, epoch uint64, useGenesisFork bool) ([]byte, error) + GetExitDomainData(domainType []byte) ([]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 6bcb5628f..00c670f6e 100644 --- a/shared/services/beacon/client/std-http-client.go +++ b/shared/services/beacon/client/std-http-client.go @@ -62,6 +62,8 @@ const ( MaxRequestValidatorsCount = 600 threadLimit int = 6 + + CapellaForkVersion = "0x03001020" ) // Beacon client using the standard Beacon HTTP REST API (https://ethereum.github.io/beacon-APIs/) @@ -409,40 +411,16 @@ func (c *StandardHttpClient) GetValidatorIndex(pubkey types.ValidatorPubkey) (ui } // Get domain data for a domain type at a given epoch -func (c *StandardHttpClient) GetDomainData(domainType []byte, epoch uint64, useGenesisFork bool) ([]byte, error) { +func (c *StandardHttpClient) GetExitDomainData(domainType []byte) ([]byte, error) { - // Data - var wg errgroup.Group var genesis GenesisResponse - var fork ForkResponse - // Get genesis - wg.Go(func() error { - var err error - genesis, err = c.getGenesis() - return err - }) - - // Get fork - wg.Go(func() error { - var err error - fork, err = c.getFork("head") - return err - }) - - // Wait for data - if err := wg.Wait(); err != nil { - return []byte{}, err - } + genesis, err := c.getGenesis() // Get fork version - var forkVersion []byte - if useGenesisFork { - forkVersion = genesis.Data.GenesisForkVersion - } else if epoch < uint64(fork.Data.Epoch) { - forkVersion = fork.Data.PreviousVersion - } else { - forkVersion = fork.Data.CurrentVersion + forkVersion, err := hexutil.Decode(CapellaForkVersion) + if err != nil { + return []byte{}, err } // Compute & return domain diff --git a/shared/utils/hex/hex.go b/shared/utils/hex/hex.go index 202892ae3..3f56c2733 100644 --- a/shared/utils/hex/hex.go +++ b/shared/utils/hex/hex.go @@ -19,6 +19,10 @@ along with this program. If not, see . */ package hex +import ( + "github.com/ethereum/go-ethereum/common/hexutil" +) + // Add a prefix to a hex string if not present func AddPrefix(value string) string { if len(value) < 2 || value[0:2] != "0x" { @@ -34,3 +38,7 @@ func RemovePrefix(value string) string { } return value } + +func Decode(value string) ([]byte, error) { + return hexutil.Decode(value) +} diff --git a/stader/api/validator/exit.go b/stader/api/validator/exit.go index a22a1a9d7..668e8f210 100644 --- a/stader/api/validator/exit.go +++ b/stader/api/validator/exit.go @@ -93,7 +93,7 @@ func exitValidator(c *cli.Context, validatorPubKey types.ValidatorPubkey) (*api. } // Get voluntary exit signature domain - signatureDomain, err := bc.GetDomainData(eth2types.DomainVoluntaryExit[:], head.Epoch, false) + signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:]) if err != nil { return nil, err } diff --git a/stader/node/node.go b/stader/node/node.go index 846de41b8..3cd4664a1 100644 --- a/stader/node/node.go +++ b/stader/node/node.go @@ -257,7 +257,7 @@ func run(c *cli.Context) error { exitEpoch := currentHead.Epoch - signatureDomain, err := bc.GetDomainData(eth2types.DomainVoluntaryExit[:], exitEpoch, false) + signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:]) if err != nil { errorLog.Printf("Failed to get the signature domain from beacon chain with err: %s\n", err.Error()) continue