Skip to content

Commit

Permalink
Fix submitAttestations parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Jan 27, 2025
1 parent 461f76b commit cab802c
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions core/validatorapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down Expand Up @@ -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)
}

Check warning on line 475 in core/validatorapi/router.go

View check run for this annotation

Codecov / codecov/patch

core/validatorapi/router.go#L463-L475

Added lines #L463 - L475 were not covered by tests

return nil, nil, p.SubmitAttestations(ctx, &eth2api.SubmitAttestationsOpts{
Attestations: atts,
})

Check warning on line 479 in core/validatorapi/router.go

View check run for this annotation

Codecov / codecov/patch

core/validatorapi/router.go#L477-L479

Added lines #L477 - L479 were not covered by tests
}

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)
}

Check warning on line 491 in core/validatorapi/router.go

View check run for this annotation

Codecov / codecov/patch

core/validatorapi/router.go#L482-L491

Added lines #L482 - L491 were not covered by tests

return nil, nil, p.SubmitAttestations(ctx, &eth2api.SubmitAttestationsOpts{
Attestations: atts,
})

Check warning on line 495 in core/validatorapi/router.go

View check run for this annotation

Codecov / codecov/patch

core/validatorapi/router.go#L493-L495

Added lines #L493 - L495 were not covered by tests
}

return nil, nil, p.SubmitAttestations(ctx, &eth2api.SubmitAttestationsOpts{Attestations: atts})
return nil, nil, errors.New("invalid attestations", z.Hex("body", body))

Check warning on line 498 in core/validatorapi/router.go

View check run for this annotation

Codecov / codecov/patch

core/validatorapi/router.go#L498

Added line #L498 was not covered by tests
}
}

Expand Down

0 comments on commit cab802c

Please sign in to comment.