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

Commit

Permalink
Optimized PoS header downloader (ledgerwatch#4775)
Browse files Browse the repository at this point in the history
* optimized PoS header downloader

* removed println

* comments

* ops

* Restore schedulePoSDownload params + simplify

Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
Co-authored-by: yperbasis <andrey.ashikhmin@gmail.com>
  • Loading branch information
3 people committed Jul 22, 2022
1 parent a1777ac commit 46a8c53
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
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 @@ -629,7 +626,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

0 comments on commit 46a8c53

Please sign in to comment.