From b7757d07b851366184f838f84d20747da63e8b56 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Wed, 27 Jul 2022 12:56:28 +0200 Subject: [PATCH] Don't wait for CL in initialCycle --- eth/stagedsync/stage_headers.go | 8 +++++++- turbo/stages/sentry_mock_test.go | 26 ++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index 186702f2ce9..88f5bd4f6a8 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -139,7 +139,7 @@ func SpawnStageHeaders( if transitionedToPoS { libcommon.SafeClose(cfg.hd.QuitPoWMining) - return HeadersPOS(s, u, ctx, tx, cfg, test, useExternalTx) + return HeadersPOS(s, u, ctx, tx, cfg, initialCycle, test, useExternalTx) } else { return HeadersPOW(s, u, ctx, tx, cfg, initialCycle, test, useExternalTx) } @@ -153,9 +153,15 @@ func HeadersPOS( ctx context.Context, tx kv.RwTx, cfg HeadersCfg, + initialCycle bool, test bool, useExternalTx bool, ) error { + if initialCycle { + // Let execution and other stages to finish before waiting for CL + return nil + } + log.Info(fmt.Sprintf("[%s] Waiting for Beacon Chain...", s.LogPrefix())) onlyNewRequests := cfg.hd.PosStatus() == headerdownload.Syncing diff --git a/turbo/stages/sentry_mock_test.go b/turbo/stages/sentry_mock_test.go index 8ae8f893c22..be73c12ddc6 100644 --- a/turbo/stages/sentry_mock_test.go +++ b/turbo/stages/sentry_mock_test.go @@ -519,7 +519,8 @@ func TestForkchoiceToGenesis(t *testing.T) { } m.SendForkChoiceRequest(&forkChoiceMessage) - headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil) + initialCycle := false + 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) @@ -540,7 +541,8 @@ func TestBogusForkchoice(t *testing.T) { } m.SendForkChoiceRequest(&forkChoiceMessage) - headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil) + initialCycle := false + 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) @@ -555,7 +557,7 @@ func TestBogusForkchoice(t *testing.T) { } m.SendForkChoiceRequest(&forkChoiceMessage) - headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + 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) @@ -573,7 +575,9 @@ func TestPoSDownloader(t *testing.T) { // Send a payload whose parent isn't downloaded yet m.SendPayloadRequest(chain.TopBlock) - headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil) + + initialCycle := false + 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) @@ -593,12 +597,12 @@ func TestPoSDownloader(t *testing.T) { m.ReceiveWg.Wait() // First cycle: save the downloaded header - headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + 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) // Second cycle: process the previous beacon request - headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + 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) @@ -610,7 +614,7 @@ func TestPoSDownloader(t *testing.T) { FinalizedBlockHash: chain.TopBlock.Hash(), } m.SendForkChoiceRequest(&forkChoiceMessage) - headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + 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) @@ -639,7 +643,9 @@ func TestPoSSyncWithInvalidHeader(t *testing.T) { // Send a payload with the parent missing payloadMessage := types.NewBlockFromStorage(invalidTip.Hash(), invalidTip, chain.TopBlock.Transactions(), nil) m.SendPayloadRequest(payloadMessage) - headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil) + + initialCycle := false + 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) @@ -658,7 +664,7 @@ func TestPoSSyncWithInvalidHeader(t *testing.T) { } m.ReceiveWg.Wait() - headBlockHash, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + 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) @@ -669,7 +675,7 @@ func TestPoSSyncWithInvalidHeader(t *testing.T) { FinalizedBlockHash: invalidTip.Hash(), } m.SendForkChoiceRequest(&forkChoiceMessage) - _, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, false, m.UpdateHead, nil) + _, err = stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, initialCycle, m.UpdateHead, nil) require.NoError(t, err) bad, lastValidHash := m.HeaderDownload().IsBadHeaderPoS(invalidTip.Hash())