Skip to content

Commit a109732

Browse files
authored
Merge pull request #179 from stader-labs/fix-exit-fork-version
make capella fork version for exits n/w dependant
2 parents 6d5d886 + d58ff31 commit a109732

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

shared/services/bc-manager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ func (m *BeaconClientManager) GetValidatorProposerDuties(indices []uint64, epoch
256256
}
257257

258258
// Get the Beacon chain's domain data
259-
func (m *BeaconClientManager) GetExitDomainData(domainType []byte) ([]byte, error) {
259+
func (m *BeaconClientManager) GetExitDomainData(domainType []byte, network cfgtypes.Network) ([]byte, error) {
260260
result, err := m.runFunction1(func(client beacon.Client) (interface{}, error) {
261-
return client.GetExitDomainData(domainType)
261+
return client.GetExitDomainData(domainType, network)
262262
})
263263
if err != nil {
264264
return nil, err

shared/services/beacon/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package beacon
2222
import (
2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/prysmaticlabs/go-bitfield"
25+
"github.com/stader-labs/stader-node/shared/types/config"
2526
"github.com/stader-labs/stader-node/stader-lib/types"
2627
)
2728

@@ -143,7 +144,7 @@ type Client interface {
143144
GetValidatorIndex(pubkey types.ValidatorPubkey) (uint64, error)
144145
GetValidatorSyncDuties(indices []uint64, epoch uint64) (map[uint64]bool, error)
145146
GetValidatorProposerDuties(indices []uint64, epoch uint64) (map[uint64]uint64, error)
146-
GetExitDomainData(domainType []byte) ([]byte, error)
147+
GetExitDomainData(domainType []byte, network config.Network) ([]byte, error)
147148
ExitValidator(validatorIndex, epoch uint64, signature types.ValidatorSignature) error
148149
Close() error
149150
GetEth1DataForEth2Block(blockId string) (Eth1Data, bool, error)

shared/services/beacon/client/std-http-client.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/ethereum/go-ethereum/common"
3434
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
35+
"github.com/stader-labs/stader-node/shared/types/config"
3536
"github.com/stader-labs/stader-node/stader-lib/types"
3637
eth2types "github.com/wealdtech/go-eth2-types/v2"
3738
"golang.org/x/sync/errgroup"
@@ -62,8 +63,6 @@ const (
6263

6364
MaxRequestValidatorsCount = 600
6465
threadLimit int = 6
65-
66-
CapellaForkVersion = "0x03001020"
6766
)
6867

6968
// Beacon client using the standard Beacon HTTP REST API (https://ethereum.github.io/beacon-APIs/)
@@ -411,22 +410,30 @@ func (c *StandardHttpClient) GetValidatorIndex(pubkey types.ValidatorPubkey) (ui
411410
}
412411

413412
// Get domain data for a domain type at a given epoch
414-
func (c *StandardHttpClient) GetExitDomainData(domainType []byte) ([]byte, error) {
413+
func (c *StandardHttpClient) GetExitDomainData(domainType []byte, network config.Network) ([]byte, error) {
415414

416415
var genesis GenesisResponse
417416

418417
genesis, err := c.getGenesis()
419418

420419
// Get fork version
421-
forkVersion, err := hexutil.Decode(CapellaForkVersion)
420+
var capellaForkVersion string
421+
// TODO - we currently only support mainnet and testnet envs. We will have to update this as we change n/ws
422+
if network == config.Network_Mainnet {
423+
capellaForkVersion = eth2.MainnetCapellaForkVersion
424+
} else {
425+
capellaForkVersion = eth2.GoerliCapellaForkVersion
426+
}
427+
428+
decodedForkVersion, err := hexutil.Decode(capellaForkVersion)
422429
if err != nil {
423430
return []byte{}, err
424431
}
425432

426433
// Compute & return domain
427434
var dt [4]byte
428435
copy(dt[:], domainType[:])
429-
return eth2types.Domain(dt, forkVersion, genesis.Data.GenesisValidatorsRoot), nil
436+
return eth2types.Domain(dt, decodedForkVersion, genesis.Data.GenesisValidatorsRoot), nil
430437

431438
}
432439

shared/utils/eth2/eth2.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import (
2323
"github.com/stader-labs/stader-node/shared/services/beacon"
2424
)
2525

26+
const (
27+
GoerliCapellaForkVersion = "0x03001020"
28+
MainnetCapellaForkVersion = "0x03000000"
29+
)
30+
2631
// Get an eth2 epoch number by time
2732
func EpochAt(config beacon.Eth2Config, time uint64) uint64 {
2833
return config.GenesisEpoch + (time-config.GenesisTime)/config.SecondsPerEpoch

stader/api/validator/exit.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package validator
22

33
import (
4+
"fmt"
5+
46
"github.com/stader-labs/stader-node/shared/services"
57
"github.com/stader-labs/stader-node/shared/types/api"
8+
"github.com/stader-labs/stader-node/shared/types/config"
69
"github.com/stader-labs/stader-node/shared/utils/eth2"
710
"github.com/stader-labs/stader-node/shared/utils/validator"
811
"github.com/stader-labs/stader-node/stader-lib/types"
@@ -83,6 +86,11 @@ func exitValidator(c *cli.Context, validatorPubKey types.ValidatorPubkey) (*api.
8386
return nil, err
8487
}
8588

89+
network, ok := cfg.StaderNode.Network.Value.(config.Network)
90+
if !ok {
91+
return nil, fmt.Errorf("invalid network configuration: %s", cfg.StaderNode.Network.Value)
92+
}
93+
8694
// Response
8795
response := api.ExitValidatorResponse{}
8896

@@ -93,7 +101,7 @@ func exitValidator(c *cli.Context, validatorPubKey types.ValidatorPubkey) (*api.
93101
}
94102

95103
// Get voluntary exit signature domain
96-
signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:])
104+
signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:], network)
97105
if err != nil {
98106
return nil, err
99107
}

stader/node/node.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sync"
3131
"time"
3232

33+
cfgtypes "github.com/stader-labs/stader-node/shared/types/config"
3334
stader_backend "github.com/stader-labs/stader-node/shared/types/stader-backend"
3435
"github.com/stader-labs/stader-node/shared/utils/crypto"
3536
"github.com/stader-labs/stader-node/shared/utils/eth2"
@@ -153,6 +154,18 @@ func run(c *cli.Context) error {
153154
}
154155
}
155156

157+
cfg, err := services.GetConfig(c)
158+
if err != nil {
159+
errorLog.Printf("Failed to get config with error %s\n", err.Error())
160+
continue
161+
}
162+
163+
network, ok := cfg.StaderNode.Network.Value.(cfgtypes.Network)
164+
if !ok {
165+
errorLog.Printf("Failed to get network from config: %s\n", cfg.StaderNode.Network.Value)
166+
continue
167+
}
168+
156169
operatorId, err := node.GetOperatorId(pnr, nodeAccount.Address, nil)
157170
if err != nil {
158171
errorLog.Printf("Failed to get operator id: %s\n", err.Error())
@@ -257,7 +270,7 @@ func run(c *cli.Context) error {
257270

258271
exitEpoch := currentHead.Epoch
259272

260-
signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:])
273+
signatureDomain, err := bc.GetExitDomainData(eth2types.DomainVoluntaryExit[:], network)
261274
if err != nil {
262275
errorLog.Printf("Failed to get the signature domain from beacon chain with err: %s\n", err.Error())
263276
continue

0 commit comments

Comments
 (0)