-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Separate type for unaggregated network attestations #14659
base: develop
Are you sure you want to change the base?
Changes from all commits
f9232df
76de5f4
e741580
df5338a
c8ecac2
a32321f
4215a95
fd296d9
67e92e0
12795fb
9d70083
b04ccbe
cb58bd1
d3387b3
a9f3844
abf7e6d
023c99d
ce39492
0772e04
bd10a5d
9345e66
bd82335
00f579e
cb59940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,13 @@ type AttestationElectra struct { | |
CommitteeBits string `json:"committee_bits"` | ||
} | ||
|
||
type SingleAttestation struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need the structure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
CommitteeIndex string `json:"committee_index"` | ||
AttesterIndex string `json:"attester_index"` | ||
Data *AttestationData `json:"data"` | ||
Signature string `json:"signature"` | ||
} | ||
|
||
type AttestationData struct { | ||
Slot string `json:"slot"` | ||
CommitteeIndex string `json:"index"` | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,7 +32,7 @@ func ValidateNilAttestation(attestation ethpb.Att) error { | |||||||||||||||||||||||
if attestation.GetData().Target == nil { | ||||||||||||||||||||||||
return errors.New("attestation's target can't be nil") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
if attestation.GetAggregationBits() == nil { | ||||||||||||||||||||||||
if !attestation.IsSingle() && attestation.GetAggregationBits() == nil { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||||||||||||||||||||||||
return errors.New("attestation's bitfield can't be nil") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
Comment on lines
+35
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,16 @@ func TestValidateNilAttestation(t *testing.T) { | |
}, | ||
errString: "", | ||
}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A case with a |
||
name: "single attestation", | ||
attestation: ðpb.SingleAttestation{ | ||
Data: ðpb.AttestationData{ | ||
Target: ðpb.Checkpoint{}, | ||
Source: ðpb.Checkpoint{}, | ||
}, | ||
}, | ||
errString: "", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,8 +285,11 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
func (s *Server) handleAttestationsElectra(ctx context.Context, data json.RawMessage) (attFailures []*server.IndexedVerificationFailure, failedBroadcasts []string, err error) { | ||
var sourceAttestations []*structs.AttestationElectra | ||
func (s *Server) handleAttestationsElectra( | ||
ctx context.Context, | ||
data json.RawMessage, | ||
) (attFailures []*server.IndexedVerificationFailure, failedBroadcasts []string, err error) { | ||
var sourceAttestations []*structs.SingleAttestation | ||
|
||
if err = json.Unmarshal(data, &sourceAttestations); err != nil { | ||
return nil, nil, errors.Wrap(err, "failed to unmarshal attestation") | ||
|
@@ -296,7 +299,7 @@ func (s *Server) handleAttestationsElectra(ctx context.Context, data json.RawMes | |
return nil, nil, errors.New("no data submitted") | ||
} | ||
|
||
var validAttestations []*eth.AttestationElectra | ||
var validAttestations []*eth.SingleAttestation | ||
for i, sourceAtt := range sourceAttestations { | ||
att, err := sourceAtt.ToConsensus() | ||
if err != nil { | ||
|
@@ -317,14 +320,23 @@ func (s *Server) handleAttestationsElectra(ctx context.Context, data json.RawMes | |
} | ||
|
||
for i, att := range validAttestations { | ||
targetState, err := s.AttestationStateFetcher.AttestationTargetState(ctx, att.Data.Target) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "could not get target state for attestation") | ||
} | ||
committee, err := corehelpers.BeaconCommitteeFromState(ctx, targetState, att.Data.Slot, att.CommitteeId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this PR but the bad design here is that we can only access the beacon committee while holding the state, when most of the time this committee is already cached. We should have a method to access the beacon committee from the checkpoint and only handle the failure withing that method, that is, the function would be |
||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "could not get committee for attestation") | ||
} | ||
|
||
// Broadcast the unaggregated attestation on a feed to notify other services in the beacon node | ||
// of a received unaggregated attestation. | ||
// Note we can't send for aggregated att because we don't have selection proof. | ||
if !att.IsAggregated() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is useless, the structure |
||
s.OperationNotifier.OperationFeed().Send(&feed.Event{ | ||
Type: operation.UnaggregatedAttReceived, | ||
Data: &operation.UnAggregatedAttReceivedData{ | ||
Attestation: att, | ||
Attestation: att.ToAttestationElectra(committee), | ||
}, | ||
}) | ||
} | ||
|
@@ -335,28 +347,20 @@ func (s *Server) handleAttestationsElectra(ctx context.Context, data json.RawMes | |
failedBroadcasts = append(failedBroadcasts, strconv.Itoa(i)) | ||
continue | ||
} | ||
committeeIndex, err := att.GetCommitteeIndex() | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "failed to retrieve attestation committee index") | ||
} | ||
subnet := corehelpers.ComputeSubnetFromCommitteeAndSlot(uint64(len(vals)), committeeIndex, att.Data.Slot) | ||
subnet := corehelpers.ComputeSubnetFromCommitteeAndSlot(uint64(len(vals)), att.GetCommitteeIndex(), att.Data.Slot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR but calling |
||
if err = s.Broadcaster.BroadcastAttestation(ctx, subnet, att); err != nil { | ||
log.WithError(err).Errorf("could not broadcast attestation at index %d", i) | ||
failedBroadcasts = append(failedBroadcasts, strconv.Itoa(i)) | ||
continue | ||
} | ||
|
||
if features.Get().EnableExperimentalAttestationPool { | ||
if err = s.AttestationCache.Add(att); err != nil { | ||
if err = s.AttestationCache.Add(att.ToAttestationElectra(committee)); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conversion to |
||
log.WithError(err).Error("could not save attestation") | ||
} | ||
} else if att.IsAggregated() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single attestation can't be aggregated |
||
if err = s.AttestationsPool.SaveAggregatedAttestation(att); err != nil { | ||
log.WithError(err).Error("could not save aggregated attestation") | ||
} | ||
} else { | ||
if err = s.AttestationsPool.SaveUnaggregatedAttestation(att); err != nil { | ||
log.WithError(err).Error("could not save unaggregated attestation") | ||
if err = s.AttestationsPool.SaveUnaggregatedAttestation(att.ToAttestationElectra(committee)); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
log.WithError(err).Error("could not save attestation") | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,11 +205,7 @@ func matchingAtts(atts []ethpbalpha.Att, slot primitives.Slot, attDataRoot []byt | |
// compare the committee index separately. | ||
if postElectra { | ||
if att.Version() >= version.Electra { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole block reads better as follows
|
||
ci, err := att.GetCommitteeIndex() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if ci != index { | ||
if att.GetCommitteeIndex() != index { | ||
continue | ||
} | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put in unreleased section