From 32a34fb9c138f45dabceca1eec798ab0872868e6 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Wed, 29 Nov 2023 12:09:15 +0000 Subject: [PATCH] Separate current and exit fork versions. --- CHANGELOG.md | 1 + beacon/chaininfo.go | 29 +++++++++++++++++++++++++++-- cmd/validator/exit/process.go | 10 ++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9b02e..6037080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 1.34.0: - update dependencies + - use Capella fork for all exits 1.33.2: - fix windows build diff --git a/beacon/chaininfo.go b/beacon/chaininfo.go index af544f4..d25ca51 100644 --- a/beacon/chaininfo.go +++ b/beacon/chaininfo.go @@ -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 @@ -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"` @@ -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), @@ -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 @@ -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") } @@ -236,7 +251,7 @@ func ObtainChainInfoFromNode(ctx context.Context, error, ) { res := &ChainInfo{ - Version: 2, + Version: 3, Validators: make([]*ValidatorInfo, 0), Epoch: chainTime.CurrentEpoch(), } @@ -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 { diff --git a/cmd/validator/exit/process.go b/cmd/validator/exit/process.go index 7e5820a..2a532a8 100644 --- a/cmd/validator/exit/process.go +++ b/cmd/validator/exit/process.go @@ -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 } @@ -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 != "" { @@ -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 }