Skip to content
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

fix: resolve the errors in GetLightClientUpdatesByRange function #14171

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions beacon-chain/rpc/eth/light-client/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,63 +130,65 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
}
firstSlotInPeriod := period * slotsPerPeriod

// Let's not use the first slot in the period, otherwise the attested header will be in previous period
firstSlotInPeriod++

var state state.BeaconState
var block interfaces.ReadOnlySignedBeaconBlock
for slot := lastSlotInPeriod; slot >= firstSlotInPeriod; slot-- {
state, err = s.Stater.StateBySlot(ctx, types.Slot(slot))
if err != nil {
continue
httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
return
}

// Get the block
latestBlockHeader := state.LatestBlockHeader()
latestStateRoot, err := state.HashTreeRoot(ctx)
if err != nil {
continue
httputil.HandleError(w, "Could not get state root: "+err.Error(), http.StatusInternalServerError)
return
}
latestBlockHeader.StateRoot = latestStateRoot[:]
blockRoot, err := latestBlockHeader.HashTreeRoot()
if err != nil {
continue
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return
}

block, err = s.Blocker.Block(ctx, blockRoot[:])
if err != nil || block == nil {
continue
httputil.HandleError(w, "Could not get block: "+err.Error(), http.StatusInternalServerError)
return
}

syncAggregate, err := block.Block().Body().SyncAggregate()
if err != nil || syncAggregate == nil {
continue
httputil.HandleError(w, "Could not get sync aggregate: "+err.Error(), http.StatusInternalServerError)
return
}

if syncAggregate.SyncCommitteeBits.Count()*3 < config.SyncCommitteeSize*2 {
if syncAggregate.SyncCommitteeBits.Count() < 1 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we even should filter out the blocks with zero SyncComitteeBits. since the light clients themselves check that.
But according to the specs, this will not count as a valid update anyway, so maybe we could save them the trouble of computation and just don't send them invalid updates.
Unless there is another use for this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full node spec does not require to send only updates with 1 or more participants, but since it's the sync committee that provides an update, having 0 participants essentially means that the sync committee did not give an update.

// Not enough votes
continue
httputil.HandleError(w, "Not enough votes", http.StatusNotFound)
rupam-04 marked this conversation as resolved.
Show resolved Hide resolved
}

break
}

if block == nil {
// No valid block found for the period
continue
httputil.HandleError(w, "No valid block found for the period", http.StatusNotFound)
rupam-04 marked this conversation as resolved.
Show resolved Hide resolved
}

// Get attested state
attestedRoot := block.Block().ParentRoot()
attestedBlock, err := s.Blocker.Block(ctx, attestedRoot[:])
if err != nil || attestedBlock == nil {
continue
httputil.HandleError(w, "Could not get attested block: "+err.Error(), http.StatusInternalServerError)
rupam-04 marked this conversation as resolved.
Show resolved Hide resolved
}

attestedSlot := attestedBlock.Block().Slot()
attestedState, err := s.Stater.StateBySlot(ctx, attestedSlot)
if err != nil {
continue
httputil.HandleError(w, "Could not get attested state: "+err.Error(), http.StatusInternalServerError)
rupam-04 marked this conversation as resolved.
Show resolved Hide resolved
}

// Get finalized block
Expand Down
Loading