Update to use electra version of go-eth2-client

This commit is contained in:
Chris Berry
2025-01-27 10:01:36 +00:00
parent fcafa037f8
commit 7d0e607f96
11 changed files with 163 additions and 75 deletions

View File

@@ -17,19 +17,25 @@ import (
"bytes"
"context"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/pkg/errors"
"github.com/wealdtech/ethdo/services/chaintime"
)
// AttestationHead returns the head for which the attestation should have voted.
func AttestationHead(ctx context.Context,
headersCache *BeaconBlockHeaderCache,
attestation *phase0.Attestation,
attestation *spec.VersionedAttestation,
) (
phase0.Root,
error,
) {
slot := attestation.Data.Slot
attestationData, err := attestation.Data()
if err != nil {
return phase0.Root{}, errors.Wrap(err, "failed to obtain attestation data")
}
slot := attestationData.Slot
for {
header, err := headersCache.Fetch(ctx, slot)
if err != nil {
@@ -53,12 +59,16 @@ func AttestationHead(ctx context.Context,
// AttestationHeadCorrect returns true if the given attestation had the correct head.
func AttestationHeadCorrect(ctx context.Context,
headersCache *BeaconBlockHeaderCache,
attestation *phase0.Attestation,
attestation *spec.VersionedAttestation,
) (
bool,
error,
) {
slot := attestation.Data.Slot
attestationData, err := attestation.Data()
if err != nil {
return false, errors.Wrap(err, "failed to obtain attestation data")
}
slot := attestationData.Slot
for {
header, err := headersCache.Fetch(ctx, slot)
if err != nil {
@@ -74,7 +84,7 @@ func AttestationHeadCorrect(ctx context.Context,
slot--
continue
}
return bytes.Equal(header.Root[:], attestation.Data.BeaconBlockRoot[:]), nil
return bytes.Equal(header.Root[:], attestationData.BeaconBlockRoot[:]), nil
}
}
@@ -82,13 +92,17 @@ func AttestationHeadCorrect(ctx context.Context,
func AttestationTarget(ctx context.Context,
headersCache *BeaconBlockHeaderCache,
chainTime chaintime.Service,
attestation *phase0.Attestation,
attestation *spec.VersionedAttestation,
) (
phase0.Root,
error,
) {
attestationData, err := attestation.Data()
if err != nil {
return phase0.Root{}, errors.Wrap(err, "failed to obtain attestation data")
}
// Start with first slot of the target epoch.
slot := chainTime.FirstSlotOfEpoch(attestation.Data.Target.Epoch)
slot := chainTime.FirstSlotOfEpoch(attestationData.Target.Epoch)
for {
header, err := headersCache.Fetch(ctx, slot)
if err != nil {
@@ -113,13 +127,17 @@ func AttestationTarget(ctx context.Context,
func AttestationTargetCorrect(ctx context.Context,
headersCache *BeaconBlockHeaderCache,
chainTime chaintime.Service,
attestation *phase0.Attestation,
attestation *spec.VersionedAttestation,
) (
bool,
error,
) {
attestationData, err := attestation.Data()
if err != nil {
return false, errors.Wrap(err, "failed to obtain attestation data")
}
// Start with first slot of the target epoch.
slot := chainTime.FirstSlotOfEpoch(attestation.Data.Target.Epoch)
slot := chainTime.FirstSlotOfEpoch(attestationData.Target.Epoch)
for {
header, err := headersCache.Fetch(ctx, slot)
if err != nil {
@@ -135,6 +153,6 @@ func AttestationTargetCorrect(ctx context.Context,
slot--
continue
}
return bytes.Equal(header.Root[:], attestation.Data.Target.Root[:]), nil
return bytes.Equal(header.Root[:], attestationData.Target.Root[:]), nil
}
}