Skip to content

Commit

Permalink
Merge pull request #178 from stader-labs/fix-exit-fork-version
Browse files Browse the repository at this point in the history
use capella fork version for exit signature
  • Loading branch information
bharath-123 authored Jan 18, 2024
2 parents d9e42b2 + 6069840 commit 99e83d4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
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 @@ const (

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 @@ 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
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" {

Check failure on line 28 in shared/utils/hex/hex.go

View workflow job for this annotation

GitHub Actions / build

string `0x` has 3 occurrences, make it a constant (goconst)
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

0 comments on commit 99e83d4

Please sign in to comment.