Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use capella fork version for exit signature #178

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shared/services/bc-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shared/services/beacon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 7 additions & 29 deletions shared/services/beacon/client/std-http-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

MaxRequestValidatorsCount = 600
threadLimit int = 6

CapellaForkVersion = "0x03001020"
)

// Beacon client using the standard Beacon HTTP REST API (https://ethereum.github.io/beacon-APIs/)
Expand Down Expand Up @@ -409,40 +411,16 @@
}

// 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) {

Check failure on line 414 in shared/services/beacon/client/std-http-client.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)

// 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()

Check failure on line 418 in shared/services/beacon/client/std-http-client.go

View workflow job for this annotation

GitHub Actions / build

ineffectual assignment to err (ineffassign)

// 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
Expand Down
8 changes: 8 additions & 0 deletions shared/utils/hex/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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" {
Expand All @@ -34,3 +38,7 @@ func RemovePrefix(value string) string {
}
return value
}

func Decode(value string) ([]byte, error) {
return hexutil.Decode(value)
}
2 changes: 1 addition & 1 deletion stader/api/validator/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion stader/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down