Skip to content

Commit

Permalink
Caplin: fixed small bugs (#13362)
Browse files Browse the repository at this point in the history
* Fixed inconsistent dependet_root
* Fixed panics when Erigon is not synced in the Beacon API
* Also do not error on failing to publish
  • Loading branch information
Giulio2002 authored Jan 10, 2025
1 parent c5fe936 commit f5c815d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
14 changes: 11 additions & 3 deletions cl/beacon/beaconhttp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions cl/beacon/handler/block_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cl/beacon/handler/duties_attester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 8 additions & 16 deletions cl/beacon/handler/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions cl/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}

0 comments on commit f5c815d

Please sign in to comment.