-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make Dora Happy #16441
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
Make Dora Happy #16441
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package beacon | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/OffchainLabs/prysm/v7/api" | ||
| "github.com/OffchainLabs/prysm/v7/api/server/structs" | ||
| "github.com/OffchainLabs/prysm/v7/beacon-chain/db" | ||
| "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" | ||
| "github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace" | ||
| "github.com/OffchainLabs/prysm/v7/network/httputil" | ||
| "github.com/OffchainLabs/prysm/v7/runtime/version" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // GetExecutionPayloadEnvelope retrieves a full execution payload envelope by beacon block root. | ||
| // The blinded envelope is fetched from the DB and the full execution payload is reconstructed | ||
| // from the EL via eth_getBlockByHash. | ||
| func (s *Server) GetExecutionPayloadEnvelope(w http.ResponseWriter, r *http.Request) { | ||
| ctx, span := trace.StartSpan(r.Context(), "beacon.GetExecutionPayloadEnvelope") | ||
| defer span.End() | ||
|
|
||
| rootBytes, err := bytesutil.DecodeHexWithLength(r.PathValue("block_root"), 32) | ||
| if err != nil { | ||
| httputil.HandleError(w, "Could not decode block root: "+err.Error(), http.StatusBadRequest) | ||
| return | ||
| } | ||
| root := [32]byte(rootBytes) | ||
| blinded, err := s.BeaconDB.ExecutionPayloadEnvelope(ctx, root) | ||
| if err != nil { | ||
| if errors.Is(err, db.ErrNotFound) { | ||
| httputil.HandleError(w, "execution payload envelope not found", http.StatusNotFound) | ||
| return | ||
| } | ||
| httputil.HandleError(w, "could not retrieve execution payload envelope: "+err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| full, err := s.ExecutionReconstructor.ReconstructExecutionPayloadEnvelope(ctx, blinded) | ||
| if err != nil { | ||
| httputil.HandleError(w, "could not reconstruct execution payload envelope: "+err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
|
|
||
| w.Header().Set(api.VersionHeader, version.String(version.Gloas)) | ||
|
|
||
| if httputil.RespondWithSsz(r) { | ||
| sszBytes, err := full.MarshalSSZ() | ||
| if err != nil { | ||
| httputil.HandleError(w, "could not marshal envelope to SSZ: "+err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| httputil.WriteSsz(w, sszBytes) | ||
| return | ||
| } | ||
|
|
||
| isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, root) | ||
| if err != nil { | ||
| httputil.HandleError(w, "could not check optimistic status: "+err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| finalized := s.FinalizationFetcher.IsFinalized(ctx, root) | ||
|
|
||
| jsonEnvelope, err := structs.SignedExecutionPayloadEnvelopeFromConsensus(full) | ||
| if err != nil { | ||
| httputil.HandleError(w, "could not convert envelope to JSON: "+err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| httputil.WriteJson(w, &structs.GetExecutionPayloadEnvelopeResponse{ | ||
| Version: version.String(version.Gloas), | ||
| ExecutionOptimistic: isOptimistic, | ||
| Finalized: finalized, | ||
| Data: jsonEnvelope, | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,11 @@ const ( | |
| LightClientOptimisticUpdateTopic = "light_client_optimistic_update" | ||
| // DataColumnTopic represents a data column sidecar event topic | ||
| DataColumnTopic = "data_column_sidecar" | ||
| // ExecutionPayloadTopic represents a new execution payload envelope event topic | ||
| ExecutionPayloadTopic = "execution_payload_available" | ||
| // ExecutionPayloadBidTopic represents a new execution payload bid event topic. | ||
| // This topic is currently not triggered but is recognized to avoid client subscription errors. | ||
| ExecutionPayloadBidTopic = "execution_payload_bid" | ||
|
Contributor
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. we need some tests for this events.go file
Contributor
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. you can take it from this pr #16323
Contributor
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. we don'tneed payload_attestation_message for dora to be happy?
Contributor
Author
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 for now, payloads and the payload event are enough to show the green/yellow status of payloads. |
||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -118,9 +123,14 @@ var stateFeedEventTopics = map[feed.EventType]string{ | |
| statefeed.Reorg: ChainReorgTopic, | ||
| statefeed.BlockProcessed: BlockTopic, | ||
| statefeed.PayloadAttributes: PayloadAttributesTopic, | ||
| statefeed.PayloadProcessed: ExecutionPayloadTopic, | ||
| } | ||
|
|
||
| var topicsForStateFeed = topicsForFeed(stateFeedEventTopics) | ||
| var topicsForStateFeed = func() map[string]bool { | ||
| m := topicsForFeed(stateFeedEventTopics) | ||
| m[ExecutionPayloadBidTopic] = true | ||
| return m | ||
| }() | ||
| var topicsForOpsFeed = topicsForFeed(opsFeedEventTopics) | ||
|
|
||
| func topicsForFeed(em map[feed.EventType]string) map[string]bool { | ||
|
|
@@ -466,6 +476,8 @@ func topicForEvent(event *feed.Event) string { | |
| return PayloadAttributesTopic | ||
| case *operation.DataColumnReceivedData: | ||
| return DataColumnTopic | ||
| case *statefeed.PayloadProcessedData: | ||
| return ExecutionPayloadTopic | ||
| default: | ||
| return InvalidTopic | ||
| } | ||
|
|
@@ -638,6 +650,13 @@ func (s *Server) lazyReaderForEvent(ctx context.Context, event *feed.Event, topi | |
| } | ||
| return jsonMarshalReader(eventName, blk) | ||
| }, nil | ||
| case *statefeed.PayloadProcessedData: | ||
| return func() io.Reader { | ||
| return jsonMarshalReader(eventName, &structs.PayloadEvent{ | ||
| Slot: fmt.Sprintf("%d", v.Slot), | ||
| BlockRoot: hexutil.Encode(v.BlockRoot[:]), | ||
| }) | ||
| }, nil | ||
| default: | ||
| return nil, errors.Wrapf(errUnhandledEventData, "event data type %T unsupported", v) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ### Added | ||
| - Add Gloas payload_envelope endpoint and some event streams. |
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.
do we need context if it's not used?
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.
This is in the mock, the original function uses it.
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.
thanks just noticed that didn't realize in initial review