Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Don't wait for CL in initialCycle (ledgerwatch#4841)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Jul 27, 2022
1 parent c591266 commit 1ffa984
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
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

0 comments on commit 1ffa984

Please sign in to comment.