diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index 34547752448..bde0c1a0ba6 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -306,9 +306,8 @@ func startHandlingForkChoice( if header == nil { log.Info(fmt.Sprintf("[%s] Fork choice: need to download header with hash %x", s.LogPrefix(), headerHash)) - if test { - cfg.hd.BeaconRequestList.Remove(requestId) - } else { + cfg.hd.BeaconRequestList.Remove(requestId) + if !test { schedulePoSDownload(requestId, headerHash, 0 /* header height is unknown, setting to 0 */, headerHash, s, cfg) } return &engineapi.PayloadStatus{Status: remote.EngineStatus_SYNCING}, nil @@ -436,8 +435,8 @@ func handleNewPayload( } if parent == nil { log.Info(fmt.Sprintf("[%s] New payload: need to download parent", s.LogPrefix()), "height", headerNumber, "hash", headerHash, "parentHash", header.ParentHash) + cfg.hd.BeaconRequestList.Remove(requestId) if test { - cfg.hd.BeaconRequestList.Remove(requestId) return &engineapi.PayloadStatus{Status: remote.EngineStatus_SYNCING}, nil } if !schedulePoSDownload(requestId, header.ParentHash, headerNumber-1, headerHash /* downloaderTip */, s, cfg) { diff --git a/turbo/stages/sentry_mock_test.go b/turbo/stages/sentry_mock_test.go index 9f01dd904e5..2ac5763525c 100644 --- a/turbo/stages/sentry_mock_test.go +++ b/turbo/stages/sentry_mock_test.go @@ -601,11 +601,17 @@ func TestPoSDownloader(t *testing.T) { require.NoError(t, err) stages.SendPayloadStatus(m.HeaderDownload(), headBlockHash, err) + // Since we are removing the current request to avoid the deadlock, we need to send the new payload (or fcu) request again. + m.SendPayloadRequest(chain.TopBlock) // Second cycle: process the previous beacon request headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, initialCycle, m.UpdateHead, nil) require.NoError(t, err) stages.SendPayloadStatus(m.HeaderDownload(), headBlockHash, err) assert.Equal(t, chain.TopBlock.Hash(), headBlockHash) + // Second cycle: checking the response + payloadStatus = m.ReceivePayloadStatus() + assert.Equal(t, remote.EngineStatus_VALID, payloadStatus.Status) + assert.Equal(t, chain.TopBlock.Hash(), headBlockHash) // Point forkChoice to the head forkChoiceMessage := engineapi.ForkChoiceMessage{