Skip to content

Commit

Permalink
Fix Pending Queue Deadline Bug (#13145)
Browse files Browse the repository at this point in the history
* rearrange deadline

* naming
  • Loading branch information
nisdas authored and saolyn committed Oct 31, 2023
1 parent a4b25ff commit 384454d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions beacon-chain/sync/pending_blocks_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,17 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
continue
}

// Calculate the deadline time by adding three slots duration to the current time
secondsPerSlot := params.BeaconConfig().SecondsPerSlot
threeSlotDuration := 3 * time.Duration(secondsPerSlot) * time.Second
ctxWithTimeout, cancelFunction := context.WithTimeout(ctx, threeSlotDuration)
// Process and broadcast the block.
if err := s.processAndBroadcastBlock(ctx, b, blkRoot); err != nil {
s.handleBlockProcessingError(ctx, err, b, blkRoot)
if err := s.processAndBroadcastBlock(ctxWithTimeout, b, blkRoot); err != nil {
s.handleBlockProcessingError(ctxWithTimeout, err, b, blkRoot)
cancelFunction()
continue
}
cancelFunction()

// Remove the processed block from the queue.
if err := s.removeBlockFromQueue(b, blkRoot); err != nil {
Expand Down Expand Up @@ -205,12 +211,7 @@ func (s *Service) processAndBroadcastBlock(ctx context.Context, b interfaces.Rea
}
}

// Calculate the deadline time by adding two slots duration to the current time
secondsPerSlot := params.BeaconConfig().SecondsPerSlot
twoSlotDuration := 2 * time.Duration(secondsPerSlot) * time.Second
ctxWithTimeout, cancelFunction := context.WithTimeout(ctx, twoSlotDuration)
defer cancelFunction()
if err := s.cfg.chain.ReceiveBlock(ctxWithTimeout, b, blkRoot); err != nil {
if err := s.cfg.chain.ReceiveBlock(ctx, b, blkRoot); err != nil {
return err
}

Expand Down

0 comments on commit 384454d

Please sign in to comment.