Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caplin: fixed attestation broadcasting #10041

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cl/beacon/handler/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ func (a *ApiHandler) PostEthV1BeaconPoolAttestations(w http.ResponseWriter, r *h
})
continue
}
// if a.sentinel != nil {
// encodedSSZ, err := attestation.EncodeSSZ(nil)
// if err != nil {
// beaconhttp.NewEndpointError(http.StatusInternalServerError, err).WriteTo(w)
// return
// }
// if _, err := a.sentinel.PublishGossip(r.Context(), &sentinel.GossipData{
// Data: encodedSSZ,
// Name: gossip.TopicNamePrefixBeaconAttestation,
// SubnetId: &subnet,
// }); err != nil {
// beaconhttp.NewEndpointError(http.StatusInternalServerError, err).WriteTo(w)
// return
// }
// }
if a.sentinel != nil {
encodedSSZ, err := attestation.EncodeSSZ(nil)
if err != nil {
beaconhttp.NewEndpointError(http.StatusInternalServerError, err).WriteTo(w)
return
}
if _, err := a.sentinel.PublishGossip(r.Context(), &sentinel.GossipData{
Data: encodedSSZ,
Name: gossip.TopicNamePrefixBeaconAttestation,
SubnetId: &subnet,
}); err != nil {
beaconhttp.NewEndpointError(http.StatusInternalServerError, err).WriteTo(w)
return
}
}
}
if len(failures) > 0 {
errResp := poolingError{
Expand Down
3 changes: 3 additions & 0 deletions cl/cltypes/solid/attestation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solid

import (
"encoding/binary"
"encoding/json"

libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -49,6 +50,7 @@ func NewAttestionFromParameters(
signature [96]byte,
) *Attestation {
a := &Attestation{}
binary.LittleEndian.PutUint32(a.staticBuffer[:4], aggregationBitsOffset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah where is the doc regarding the bytes content of attestation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the ssz encoding: https://www.ssz.dev/

a.SetAttestationData(attestationData)
a.SetSignature(signature)
a.SetAggregationBits(aggregationBits)
Expand Down Expand Up @@ -77,6 +79,7 @@ func (a *Attestation) UnmarshalJSON(buf []byte) error {
if err := json.Unmarshal(buf, &tmp); err != nil {
return err
}
binary.LittleEndian.PutUint32(a.staticBuffer[:4], aggregationBitsOffset)
a.SetAggregationBits(tmp.AggregationBits)
a.SetSignature(tmp.Signature)
a.SetAttestationData(tmp.Data)
Expand Down
10 changes: 8 additions & 2 deletions cl/phase1/network/services/attestation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package services

import (
"context"
"errors"
"fmt"
"time"

"github.com/Giulio2002/bls"
"github.com/ledgerwatch/erigon/cl/aggregation"
"github.com/ledgerwatch/erigon/cl/beacon/synced_data"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
Expand Down Expand Up @@ -71,7 +73,7 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
// [REJECT] The committee index is within the expected range
committeeCount := computeCommitteeCountPerSlot(headState, slot, s.beaconCfg.SlotsPerEpoch)
if committeeIndex >= committeeCount {
return fmt.Errorf("committee index out of range")
return fmt.Errorf("committee index out of range, %d >= %d", committeeIndex, committeeCount)
}
// [REJECT] The attestation is for the correct subnet -- i.e. compute_subnet_for_attestation(committees_per_slot, attestation.data.slot, index) == subnet_id
subnetId := computeSubnetForAttestation(committeeCount, slot, committeeIndex, s.beaconCfg.SlotsPerEpoch, s.netCfg.AttestationSubnetCount)
Expand Down Expand Up @@ -175,5 +177,9 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
return fmt.Errorf("invalid finalized checkpoint %w", ErrIgnore)
}

return s.committeeSubscribe.CheckAggregateAttestation(att)
err = s.committeeSubscribe.CheckAggregateAttestation(att)
if errors.Is(err, aggregation.ErrIsSuperset) {
return ErrIgnore
}
return err
}
Loading