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

Optimized PoS header downloader #4775

Merged
merged 6 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 3 additions & 6 deletions eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ func startHandlingForkChoice(

if header == nil {
log.Info(fmt.Sprintf("[%s] Fork choice missing header with hash %x", s.LogPrefix(), headerHash))
hashToDownload := headerHash
cfg.hd.SetPoSDownloaderTip(headerHash)
schedulePoSDownload(requestId, hashToDownload, 0 /* header height is unknown, setting to 0 */, s, cfg)
schedulePoSDownload(requestId, headerHash, 0 /* header height is unknown, setting to 0 */, s, cfg)
return &privateapi.PayloadStatus{Status: remote.EngineStatus_SYNCING}, nil
}

Expand Down Expand Up @@ -487,10 +486,8 @@ func handleNewPayload(
}
if parent == nil {
log.Info(fmt.Sprintf("[%s] New payload missing parent", s.LogPrefix()))
hashToDownload := header.ParentHash
heightToDownload := headerNumber - 1
cfg.hd.SetPoSDownloaderTip(headerHash)
schedulePoSDownload(requestId, hashToDownload, heightToDownload, s, cfg)
schedulePoSDownload(requestId, header.ParentHash, headerNumber-1, s, cfg)
return &privateapi.PayloadStatus{Status: remote.EngineStatus_SYNCING}, nil
}

Expand Down Expand Up @@ -653,7 +650,7 @@ func schedulePoSDownload(

cfg.hd.SetRequestId(requestId)
cfg.hd.SetHeaderToDownloadPoS(hashToDownload, heightToDownload)
cfg.hd.SetPOSSync(true) // This needs to be called afrer SetHeaderToDownloadPOS because SetHeaderToDownloadPOS sets `posAnchor` member field which is used by ProcessHeadersPOS
cfg.hd.SetPOSSync(true) // This needs to be called after SetHeaderToDownloadPOS because SetHeaderToDownloadPOS sets `posAnchor` member field which is used by ProcessHeadersPOS

//nolint
headerCollector := etl.NewCollector(s.LogPrefix(), cfg.tmpdir, etl.NewSortableBuffer(etl.BufferOptimalSize))
Expand Down
1 change: 0 additions & 1 deletion turbo/engineapi/fork_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func (fv *ForkValidator) ValidatePayload(tx kv.RwTx, header *types.Header, body
// if the block is not in range of maxForkDepth from head then we do not validate it.
if abs64(int64(fv.currentHeight)-header.Number.Int64()) > maxForkDepth {
status = remote.EngineStatus_ACCEPTED
fmt.Println("not in range")
return
}
// Let's assemble the side fork backwards
Expand Down
2 changes: 1 addition & 1 deletion turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (hd *HeaderDownload) requestMoreHeadersForPOS(currentTime time.Time) (timeo
request = &HeaderRequest{
Anchor: anchor,
Hash: anchor.parentHash,
Number: 0, // Since posAnchor may be an estimate, do not specify it here
Number: anchor.blockHeight - 1,
Length: 192,
Skip: 0,
Reverse: true,
Expand Down