From cabf3476e7c3f56100dde2705a0de541097640d7 Mon Sep 17 00:00:00 2001 From: terencechain Date: Wed, 25 Oct 2023 12:40:17 -0700 Subject: [PATCH] Add context deadline for pending queue's receive block (#13114) * Add context dead like for pending queue's receive block * Use timeout --- beacon-chain/sync/pending_blocks_queue.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index c3439e5f4e..5ae5de1780 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -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 }