Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wait for CL in initialCycle #4841

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
26 changes: 16 additions & 10 deletions turbo/stages/sentry_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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())
Expand Down