Skip to content

Commit

Permalink
Separate current and exit fork versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Nov 29, 2023
1 parent e356e9e commit 32a34fb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.34.0:
- update dependencies
- use Capella fork for all exits

1.33.2:
- fix windows build
Expand Down
29 changes: 27 additions & 2 deletions beacon/chaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ChainInfo struct {
GenesisValidatorsRoot phase0.Root
Epoch phase0.Epoch
GenesisForkVersion phase0.Version
ExitForkVersion phase0.Version
CurrentForkVersion phase0.Version
BLSToExecutionChangeDomainType phase0.DomainType
VoluntaryExitDomainType phase0.DomainType
Expand All @@ -46,6 +47,7 @@ type chainInfoJSON struct {
GenesisValidatorsRoot string `json:"genesis_validators_root"`
Epoch string `json:"epoch"`
GenesisForkVersion string `json:"genesis_fork_version"`
ExitForkVersion string `json:"exit_fork_version"`
CurrentForkVersion string `json:"current_fork_version"`
BLSToExecutionChangeDomainType string `json:"bls_to_execution_change_domain_type"`
VoluntaryExitDomainType string `json:"voluntary_exit_domain_type"`
Expand All @@ -63,6 +65,7 @@ func (c *ChainInfo) MarshalJSON() ([]byte, error) {
GenesisValidatorsRoot: fmt.Sprintf("%#x", c.GenesisValidatorsRoot),
Epoch: fmt.Sprintf("%d", c.Epoch),
GenesisForkVersion: fmt.Sprintf("%#x", c.GenesisForkVersion),
ExitForkVersion: fmt.Sprintf("%#x", c.ExitForkVersion),
CurrentForkVersion: fmt.Sprintf("%#x", c.CurrentForkVersion),
BLSToExecutionChangeDomainType: fmt.Sprintf("%#x", c.BLSToExecutionChangeDomainType),
VoluntaryExitDomainType: fmt.Sprintf("%#x", c.VoluntaryExitDomainType),
Expand All @@ -83,7 +86,7 @@ func (c *ChainInfo) UnmarshalJSON(input []byte) error {
if err != nil {
return errors.Wrap(err, "version invalid")
}
if version < 2 {
if version < 3 {
return errors.New("outdated version; please regenerate your offline data")
}
c.Version = version
Expand Down Expand Up @@ -131,6 +134,18 @@ func (c *ChainInfo) UnmarshalJSON(input []byte) error {
}
copy(c.GenesisForkVersion[:], genesisForkVersionBytes)

if data.ExitForkVersion == "" {
return errors.New("exit fork version missing")
}
exitForkVersionBytes, err := hex.DecodeString(strings.TrimPrefix(data.ExitForkVersion, "0x"))
if err != nil {
return errors.Wrap(err, "exit fork version invalid")
}
if len(exitForkVersionBytes) != phase0.ForkVersionLength {
return errors.New("exit fork version incorrect length")
}
copy(c.ExitForkVersion[:], exitForkVersionBytes)

if data.CurrentForkVersion == "" {
return errors.New("current fork version missing")
}
Expand Down Expand Up @@ -236,7 +251,7 @@ func ObtainChainInfoFromNode(ctx context.Context,
error,
) {
res := &ChainInfo{
Version: 2,
Version: 3,
Validators: make([]*ValidatorInfo, 0),
Epoch: chainTime.CurrentEpoch(),
}
Expand Down Expand Up @@ -278,6 +293,16 @@ func ObtainChainInfoFromNode(ctx context.Context,
return nil, errors.New("could not obtain GENESIS_FORK_VERSION")
}

// Fetch the exit fork version (Capella) from the specification.
tmp, exists = specResponse.Data["CAPELLA_FORK_VERSION"]
if !exists {
return nil, errors.New("capella fork version not known by chain")
}
res.ExitForkVersion, isForkVersion = tmp.(phase0.Version)
if !isForkVersion {
return nil, errors.New("could not obtain CAPELLA_FORK_VERSION")
}

// Fetch the current fork version from the fork schedule.
forkScheduleResponse, err := consensusClient.(consensusclient.ForkScheduleProvider).ForkSchedule(ctx)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/validator/exit/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (c *command) generateDomain(ctx context.Context) error {
if err != nil {
return err
}
forkVersion, err := c.obtainForkVersion(ctx)
forkVersion, err := c.obtainExitForkVersion(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -661,10 +661,11 @@ func (c *command) obtainGenesisValidatorsRoot(_ context.Context) (phase0.Root, e
if c.debug {
fmt.Fprintf(os.Stderr, "Using genesis validators root %#x\n", genesisValidatorsRoot)
}

return genesisValidatorsRoot, nil
}

func (c *command) obtainForkVersion(_ context.Context) (phase0.Version, error) {
func (c *command) obtainExitForkVersion(_ context.Context) (phase0.Version, error) {
forkVersion := phase0.Version{}

if c.forkVersion != "" {
Expand All @@ -683,12 +684,13 @@ func (c *command) obtainForkVersion(_ context.Context) (phase0.Version, error) {
if c.debug {
fmt.Fprintf(os.Stderr, "Fork version obtained from chain info\n")
}
// Use the current fork version for generating an exit as per the spec.
copy(forkVersion[:], c.chainInfo.CurrentForkVersion[:])
// Use the Capella fork version for generating an exit as per the spec.
copy(forkVersion[:], c.chainInfo.ExitForkVersion[:])
}

if c.debug {
fmt.Fprintf(os.Stderr, "Using fork version %#x\n", forkVersion)
}

return forkVersion, nil
}

0 comments on commit 32a34fb

Please sign in to comment.