mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-09 14:07:56 -05:00
Separate current and exit fork versions.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
1.34.0:
|
||||
- update dependencies
|
||||
- use Capella fork for all exits
|
||||
|
||||
1.33.2:
|
||||
- fix windows build
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user