diff --git a/cl/beacon/beaconhttp/api.go b/cl/beacon/beaconhttp/api.go index 1aef8a84a39..85c69abf2d5 100644 --- a/cl/beacon/beaconhttp/api.go +++ b/cl/beacon/beaconhttp/api.go @@ -103,13 +103,21 @@ func HandleEndpoint[T any](h EndpointHandler[T]) http.HandlerFunc { ans, err := h.Handle(w, r) if err != nil { var endpointError *EndpointError - var e *EndpointError - if errors.As(err, &e) { + if e, ok := err.(*EndpointError); ok { + // Directly use the error if it's already an *EndpointError endpointError = e } else { + // Wrap the error in an EndpointError otherwise endpointError = WrapEndpointError(err) } - endpointError.WriteTo(w) + + // Write the endpoint error to the response writer + if endpointError != nil { + endpointError.WriteTo(w) + } else { + // Failsafe: If the error is nil, write a generic 500 error + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } return } // TODO: potentially add a context option to buffer these diff --git a/cl/beacon/handler/block_production.go b/cl/beacon/handler/block_production.go index 9d9b4bf239c..a1a43c00bd8 100644 --- a/cl/beacon/handler/block_production.go +++ b/cl/beacon/handler/block_production.go @@ -1144,8 +1144,7 @@ func (a *ApiHandler) broadcastBlock(ctx context.Context, blk *cltypes.SignedBeac Name: gossip.TopicNameBeaconBlock, Data: blkSSZ, }); err != nil { - log.Error("Failed to publish block", "err", err) - return err + a.logger.Error("Failed to publish block", "err", err) } for idx, blob := range blobsSidecarsBytes { idx64 := uint64(idx) @@ -1154,8 +1153,7 @@ func (a *ApiHandler) broadcastBlock(ctx context.Context, blk *cltypes.SignedBeac Data: blob, SubnetId: &idx64, }); err != nil { - log.Error("Failed to publish blob sidecar", "err", err) - return err + a.logger.Error("Failed to publish blob sidecar", "err", err) } } return nil diff --git a/cl/beacon/handler/duties_attester.go b/cl/beacon/handler/duties_attester.go index 46731805819..84a47232a84 100644 --- a/cl/beacon/handler/duties_attester.go +++ b/cl/beacon/handler/duties_attester.go @@ -48,6 +48,10 @@ func (a *ApiHandler) getDependentRoot(epoch uint64, attester bool) (libcommon.Ha if attester { dependentRootSlot = ((epoch - 1) * a.beaconChainCfg.SlotsPerEpoch) - 1 } + if !a.syncedData.Syncing() && dependentRootSlot == a.syncedData.HeadSlot() { + dependentRoot = a.syncedData.HeadRoot() + return nil + } maxIterations := 2048 for i := 0; i < maxIterations; i++ { if dependentRootSlot > epoch*a.beaconChainCfg.SlotsPerEpoch { diff --git a/cl/beacon/handler/pool.go b/cl/beacon/handler/pool.go index 368bc155f33..2b00af03713 100644 --- a/cl/beacon/handler/pool.go +++ b/cl/beacon/handler/pool.go @@ -145,8 +145,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolAttestations(w http.ResponseWriter, r *h Name: gossip.TopicNamePrefixBeaconAttestation, SubnetId: &subnet, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish attestation to gossip", "err", err) } } } @@ -191,8 +190,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolVoluntaryExits(w http.ResponseWriter, r Data: encodedSSZ, Name: gossip.TopicNameVoluntaryExit, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish voluntary exit to gossip", "err", err) } } // Only write 200 @@ -222,8 +220,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolAttesterSlashings(w http.ResponseWriter, Data: encodedSSZ, Name: gossip.TopicNameAttesterSlashing, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish attester slashing to gossip", "err", err) } } // Only write 200 @@ -251,8 +248,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolProposerSlashings(w http.ResponseWriter, Data: encodedSSZ, Name: gossip.TopicNameProposerSlashing, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish proposer slashing to gossip", "err", err) } } // Only write 200 @@ -295,8 +291,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolBlsToExecutionChanges(w http.ResponseWri Data: encodedSSZ, Name: gossip.TopicNameBlsToExecutionChange, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish bls-to-execution-change to gossip", "err", err) } } } @@ -342,8 +337,7 @@ func (a *ApiHandler) PostEthV1ValidatorAggregatesAndProof(w http.ResponseWriter, Data: encodedSSZ, Name: gossip.TopicNameBeaconAggregateAndProof, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish aggregate and proof to gossip", "err", err) } } } @@ -398,8 +392,7 @@ func (a *ApiHandler) PostEthV1BeaconPoolSyncCommittees(w http.ResponseWriter, r Name: gossip.TopicNamePrefixSyncCommittee, SubnetId: &subnetId, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish sync committee message to gossip", "err", err) } } } @@ -448,8 +441,7 @@ func (a *ApiHandler) PostEthV1ValidatorContributionsAndProofs(w http.ResponseWri Data: encodedSSZ, Name: gossip.TopicNameSyncCommitteeContributionAndProof, }); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + a.logger.Debug("[Beacon REST] failed to publish sync committee contribution to gossip", "err", err) } } } diff --git a/cl/rpc/rpc.go b/cl/rpc/rpc.go index 7f71b382a07..2fec27767c2 100644 --- a/cl/rpc/rpc.go +++ b/cl/rpc/rpc.go @@ -296,18 +296,6 @@ func (b *BeaconRpcP2P) SetStatus(finalizedRoot libcommon.Hash, finalizedEpoch ui return err } -func (b *BeaconRpcP2P) PropagateBlock(block *cltypes.SignedBeaconBlock) error { - encoded, err := block.EncodeSSZ(nil) - if err != nil { - return err - } - _, err = b.sentinel.PublishGossip(b.ctx, &sentinel.GossipData{ - Data: encoded, - Name: "beacon_block", - }) - return err -} - func (b *BeaconRpcP2P) BanPeer(pid string) { b.sentinel.BanPeer(b.ctx, &sentinel.Peer{Pid: pid}) }