-
Notifications
You must be signed in to change notification settings - Fork 1.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
Update Beacon API events to Electra #14855
Changes from 2 commits
7af962f
35122f6
51b0afd
545408f
39eab6d
1006d25
c87c634
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 |
---|---|---|
|
@@ -236,6 +236,13 @@ func (s *Service) monitorRoutine(stateChannel chan *feed.Event, stateSub event.S | |
} else { | ||
s.processAggregatedAttestation(s.ctx, data.Attestation) | ||
} | ||
case operation.SingleAttReceived: | ||
data, ok := e.Data.(*operation.SingleAttReceivedData) | ||
if !ok { | ||
log.Error("Event feed data is not of type *operation.SingleAttReceivedData") | ||
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 wonder why we don't print the Type of the data here for old ones, maybe that would be useful 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. is it because we already do that once in the marshal reader? 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. Are you sure you are looking at the correct file? I don't see any marshal reader in the monitor 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. oops then maybe we should print the type somewhere. |
||
} else { | ||
s.processUnaggregatedAttestation(s.ctx, data.Attestation) | ||
} | ||
case operation.ExitReceived: | ||
data, ok := e.Data.(*operation.ExitReceivedData) | ||
if !ok { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,13 @@ func (s *Server) handleAttestationsElectra( | |
} | ||
|
||
for i, singleAtt := range validAttestations { | ||
s.OperationNotifier.OperationFeed().Send(&feed.Event{ | ||
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. why did we need to move this? 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. So that we send a single attestation and not an Electra one. Previously we were sending |
||
Type: operation.SingleAttReceived, | ||
Data: &operation.SingleAttReceivedData{ | ||
Attestation: singleAtt, | ||
rkapka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}) | ||
|
||
targetState, err := s.AttestationStateFetcher.AttestationTargetState(ctx, singleAtt.Data.Target) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "could not get target state for attestation") | ||
|
@@ -330,13 +337,6 @@ func (s *Server) handleAttestationsElectra( | |
} | ||
att := singleAtt.ToAttestationElectra(committee) | ||
|
||
s.OperationNotifier.OperationFeed().Send(&feed.Event{ | ||
Type: operation.UnaggregatedAttReceived, | ||
Data: &operation.UnAggregatedAttReceivedData{ | ||
Attestation: att, | ||
}, | ||
}) | ||
|
||
wantedEpoch := slots.ToEpoch(att.Data.Slot) | ||
vals, err := s.HeadFetcher.HeadValidatorsIndices(ctx, wantedEpoch) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ const ( | |
BlockTopic = "block" | ||
// AttestationTopic represents a new submitted attestation event topic. | ||
AttestationTopic = "attestation" | ||
// SingleAttestationTopic represents a new submitted single attestation event topic. | ||
SingleAttestationTopic = "single_attestation" | ||
// VoluntaryExitTopic represents a new performed voluntary exit event topic. | ||
VoluntaryExitTopic = "voluntary_exit" | ||
// FinalizedCheckpointTopic represents a new finalized checkpoint event topic. | ||
|
@@ -92,6 +94,7 @@ type lazyReader func() io.Reader | |
var opsFeedEventTopics = map[feed.EventType]string{ | ||
operation.AggregatedAttReceived: AttestationTopic, | ||
operation.UnaggregatedAttReceived: AttestationTopic, | ||
operation.SingleAttReceived: SingleAttestationTopic, | ||
operation.ExitReceived: VoluntaryExitTopic, | ||
operation.SyncCommitteeContributionReceived: SyncCommitteeContributionTopic, | ||
operation.BLSToExecutionChangeReceived: BLSToExecutionChangeTopic, | ||
|
@@ -403,7 +406,7 @@ func (es *eventStreamer) writeOutbox(ctx context.Context, w *streamingResponseWr | |
func jsonMarshalReader(name string, v any) io.Reader { | ||
d, err := json.Marshal(v) | ||
if err != nil { | ||
log.WithError(err).WithField("type_name", fmt.Sprintf("%T", v)).Error("Could not marshal event data.") | ||
log.WithError(err).WithField("type_name", fmt.Sprintf("%T", v)).Error("Could not marshal event data") | ||
return nil | ||
} | ||
return bytes.NewBufferString("event: " + name + "\ndata: " + string(d) + "\n\n") | ||
|
@@ -415,6 +418,8 @@ func topicForEvent(event *feed.Event) string { | |
return AttestationTopic | ||
case *operation.UnAggregatedAttReceivedData: | ||
return AttestationTopic | ||
case *operation.SingleAttReceivedData: | ||
return SingleAttestationTopic | ||
case *operation.ExitReceivedData: | ||
return VoluntaryExitTopic | ||
case *operation.SyncCommitteeContributionReceivedData: | ||
|
@@ -464,10 +469,20 @@ func (s *Server) lazyReaderForEvent(ctx context.Context, event *feed.Event, topi | |
return jsonMarshalReader(eventName, structs.HeadEventFromV1(v)) | ||
}, nil | ||
case *operation.AggregatedAttReceivedData: | ||
return func() io.Reader { | ||
att := structs.AttFromConsensus(v.Attestation.Aggregate) | ||
return jsonMarshalReader(eventName, att) | ||
}, nil | ||
switch att := v.Attestation.AggregateVal().(type) { | ||
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. would this ever panic? v.Attestation being nil? |
||
case *eth.Attestation: | ||
return func() io.Reader { | ||
att := structs.AttFromConsensus(att) | ||
return jsonMarshalReader(eventName, att) | ||
}, nil | ||
case *eth.AttestationElectra: | ||
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. shoot this must have been missed... 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 change in |
||
return func() io.Reader { | ||
att := structs.AttElectraFromConsensus(att) | ||
return jsonMarshalReader(eventName, att) | ||
}, nil | ||
default: | ||
return nil, errors.Wrapf(errUnhandledEventData, "Unexpected type %T for the .Attestation field of AggregatedAttReceivedData", v.Attestation) | ||
} | ||
case *operation.UnAggregatedAttReceivedData: | ||
switch att := v.Attestation.(type) { | ||
case *eth.Attestation: | ||
|
@@ -483,6 +498,16 @@ func (s *Server) lazyReaderForEvent(ctx context.Context, event *feed.Event, topi | |
default: | ||
return nil, errors.Wrapf(errUnhandledEventData, "Unexpected type %T for the .Attestation field of UnAggregatedAttReceivedData", v.Attestation) | ||
} | ||
case *operation.SingleAttReceivedData: | ||
switch att := v.Attestation.(type) { | ||
case *eth.SingleAttestation: | ||
return func() io.Reader { | ||
att := structs.SingleAttFromConsensus(att) | ||
return jsonMarshalReader(eventName, att) | ||
}, nil | ||
default: | ||
return nil, errors.Wrapf(errUnhandledEventData, "Unexpected type %T for the .Attestation field of SingleAttReceivedData", v.Attestation) | ||
} | ||
case *operation.ExitReceivedData: | ||
return func() io.Reader { | ||
return jsonMarshalReader(eventName, structs.SignedExitFromConsensus(v.Exit)) | ||
|
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.
not a comment here but something i forgot why we did it, why do we not check if a.Data is not nil? do we do that somewhere else? i forgot.