Add context deadline for pending queue's receive block (#13114)

* Add context dead like for pending queue's receive block

* Use timeout
This commit is contained in:
terencechain
2023-10-25 12:40:17 -07:00
committed by GitHub
parent 5a01eecc50
commit cabf3476e7

View File

@@ -205,7 +205,12 @@ func (s *Service) processAndBroadcastBlock(ctx context.Context, b interfaces.Rea
}
}
if err := s.cfg.chain.ReceiveBlock(ctx, b, blkRoot); err != nil {
// 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 {
return err
}