diff --git a/core/validatorapi/router.go b/core/validatorapi/router.go index 95cecdd2f..25842f904 100644 --- a/core/validatorapi/router.go +++ b/core/validatorapi/router.go @@ -120,6 +120,12 @@ func NewRouter(ctx context.Context, h Handler, eth2Cl eth2wrap.Client, builderEn { Name: "submit_attestations", Path: "/eth/v1/beacon/pool/attestations", + Handler: respond404("/eth/v1/beacon/pool/attestations"), + Methods: []string{http.MethodPost}, + }, + { + Name: "submit_attestations_v2", + Path: "/eth/v2/beacon/pool/attestations", Handler: submitAttestations(h), Methods: []string{http.MethodPost}, }, @@ -454,13 +460,42 @@ func attestationData(p eth2client.AttestationDataProvider) handlerFunc { // submitAttestations returns a handler function for the attestation submitter endpoint. func submitAttestations(p eth2client.AttestationsSubmitter) handlerFunc { return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) { - var atts []*eth2spec.VersionedAttestation - err := unmarshal(typ, body, &atts) - if err != nil { - return nil, nil, errors.Wrap(err, "unmarshal attestations") + atts := []*eth2spec.VersionedAttestation{} + + denebAtts := new([]eth2p0.Attestation) + err := unmarshal(typ, body, denebAtts) + if err == nil { + for _, att := range *denebAtts { + // TODO: Data version is not Deneb, it might be anything between Phase0 and Deneb + versionedAgg := eth2spec.VersionedAttestation{ + Version: eth2spec.DataVersionDeneb, + Deneb: &att, + } + atts = append(atts, &versionedAgg) + } + + return nil, nil, p.SubmitAttestations(ctx, ð2api.SubmitAttestationsOpts{ + Attestations: atts, + }) + } + + electraAtts := new([]electra.Attestation) + err = unmarshal(typ, body, electraAtts) + if err == nil { + for _, att := range *electraAtts { + versionedAtt := eth2spec.VersionedAttestation{ + Version: eth2spec.DataVersionElectra, + Electra: &att, + } + atts = append(atts, &versionedAtt) + } + + return nil, nil, p.SubmitAttestations(ctx, ð2api.SubmitAttestationsOpts{ + Attestations: atts, + }) } - return nil, nil, p.SubmitAttestations(ctx, ð2api.SubmitAttestationsOpts{Attestations: atts}) + return nil, nil, errors.New("invalid attestations", z.Hex("body", body)) } }