From 55a4fa75b46d701b9f7e271cb481159684910756 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Tue, 17 May 2022 17:42:34 +0700 Subject: [PATCH] HeadersPOS: to use snapshots (#4178) --- eth/stagedsync/stage_headers.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index 637f02e79..bd67471e4 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -179,7 +179,7 @@ func HeadersPOS( cfg.hd.ClearPendingPayloadStatus() if forkChoiceInsteadOfNewPayload { - if err := startHandlingForkChoice(forkChoiceMessage, status, requestId, s, u, ctx, tx, cfg, headerInserter); err != nil { + if err := startHandlingForkChoice(forkChoiceMessage, status, requestId, s, u, ctx, tx, cfg, headerInserter, cfg.blockReader); err != nil { return err } } else { @@ -242,6 +242,7 @@ func startHandlingForkChoice( tx kv.RwTx, cfg HeadersCfg, headerInserter *headerdownload.HeaderInserter, + headerReader interfaces.HeaderReader, ) error { headerHash := forkChoice.HeadBlockHash log.Info(fmt.Sprintf("[%s] Handling fork choice", s.LogPrefix()), "headerHash", headerHash) @@ -307,7 +308,10 @@ func startHandlingForkChoice( forkingPoint := uint64(0) if headerNumber > 0 { - parent := rawdb.ReadHeader(tx, header.ParentHash, headerNumber-1) + parent, err := headerReader.Header(ctx, tx, header.ParentHash, headerNumber-1) + if err != nil { + return err + } forkingPoint, err = headerInserter.ForkingPoint(tx, header, parent) if err != nil { if requestStatus == engineapi.New { @@ -439,7 +443,10 @@ func handleNewPayload( return nil } - parent := rawdb.ReadHeader(tx, header.ParentHash, headerNumber-1) + parent, err := cfg.blockReader.Header(ctx, tx, header.ParentHash, headerNumber-1) + if err != nil { + return err + } if parent == nil { log.Info(fmt.Sprintf("[%s] New payload missing parent", s.LogPrefix())) hashToDownload := header.ParentHash