Compare commits

...

1 Commits

Author SHA1 Message Date
terence tsao
94263441a5 Publish and save blobs 2024-08-22 08:18:11 -07:00
3 changed files with 40 additions and 0 deletions

View File

@@ -465,6 +465,7 @@ func (s *Service) beaconEndpoints(
OperationNotifier: s.cfg.OperationNotifier,
Broadcaster: s.cfg.Broadcaster,
BlockReceiver: s.cfg.BlockReceiver,
BlobReceiver: s.cfg.BlobReceiver,
StateGenService: s.cfg.StateGen,
Stater: stater,
Blocker: blocker,

View File

@@ -1584,3 +1584,41 @@ func (s *Server) broadcastSeenBlockSidecars(
}
return nil
}
func (s *Server) PublishBlobs(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "beacon.PublishBlobs")
defer span.End()
if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) {
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
httputil.HandleError(w, "Could not read request body", http.StatusInternalServerError)
return
}
blobSidecars := &eth.BlobSidecars{}
if err := blobSidecars.UnmarshalSSZ(body); err != nil {
httputil.HandleError(w, "Could not unmarshal blob sidecars", http.StatusBadRequest)
return
}
for _, blobSidecar := range blobSidecars.Sidecars {
readOnlySc, err := blocks.NewROBlobWithRoot(blobSidecar, [32]byte{}) // TODO: replace [32]byte{} with beacon root
if err != nil {
http.Error(w, "Could not create read-only blob", http.StatusInternalServerError)
return
}
verifiedBlob := blocks.NewVerifiedROBlob(readOnlySc)
if err := s.BlobReceiver.ReceiveBlob(ctx, verifiedBlob); err != nil {
http.Error(w, "Could not receive blob", http.StatusInternalServerError)
return
}
if err := s.Broadcaster.BroadcastBlob(ctx, blobSidecar.Index, blobSidecar); err != nil {
log.WithError(err).Error("Failed to broadcast blob")
}
}
}

View File

@@ -48,4 +48,5 @@ type Server struct {
BLSChangesPool blstoexec.PoolManager
ForkchoiceFetcher blockchain.ForkchoiceFetcher
CoreService *core.Service
BlobReceiver blockchain.BlobReceiver
}