diff --git a/cmd/sentry/sentry/downloader.go b/cmd/sentry/sentry/downloader.go index 13b40415745197722a920a3c5123e1e0db02acd5..78d9f0f49609e65ef88c4576e1011e48a02c61ab 100644 --- a/cmd/sentry/sentry/downloader.go +++ b/cmd/sentry/sentry/downloader.go @@ -383,7 +383,7 @@ func NewControlServer(db kv.RwDB, nodeName string, chainConfig *params.ChainConf } func (cs *ControlServerImpl) newBlockHashes66(ctx context.Context, req *proto_sentry.InboundMessage, sentry direct.SentryClient) error { - if !cs.Hd.RequestChaining() && !cs.Hd.Fetching() { + if !cs.Hd.RequestChaining() && !cs.Hd.FetchingNew() { return nil } //log.Info(fmt.Sprintf("NewBlockHashes from [%s]", ConvertH256ToPeerID(req.PeerId))) diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index f12060b95df6dd4de35a4d313b80d130e3959d8d..42533304259e2f468368964d4cd436041c0ac1c9 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -340,32 +340,30 @@ func handleNewPayload( return nil } + parent := rawdb.ReadHeader(tx, header.ParentHash, headerNumber-1) + if parent == nil { + log.Info(fmt.Sprintf("[%s] New payload missing parent", s.LogPrefix())) + hashToDownload := header.ParentHash + heightToDownload := headerNumber - 1 + schedulePoSDownload(requestStatus, requestId, hashToDownload, heightToDownload, s, cfg) + return nil + } + + cfg.hd.BeaconRequestList.Remove(requestId) + transactions, err := types.DecodeTransactions(payloadMessage.Body.Transactions) if err != nil { log.Warn("Error during Beacon transaction decoding", "err", err.Error()) - cfg.hd.BeaconRequestList.Remove(requestId) if requestStatus == engineapi.New { cfg.hd.PayloadStatusCh <- privateapi.PayloadStatus{ Status: remote.EngineStatus_INVALID, - LatestValidHash: header.ParentHash, // TODO(yperbasis): potentially wrong when parent is nil + LatestValidHash: header.ParentHash, ValidationError: err, } } return nil } - parent := rawdb.ReadHeader(tx, header.ParentHash, headerNumber-1) - - if parent == nil { - log.Info(fmt.Sprintf("[%s] New payload missing parent", s.LogPrefix())) - hashToDownload := header.ParentHash - heightToDownload := headerNumber - 1 - schedulePoSDownload(requestStatus, requestId, hashToDownload, heightToDownload, s, cfg) - return nil - } - - cfg.hd.BeaconRequestList.Remove(requestId) - log.Trace(fmt.Sprintf("[%s] New payload begin verification", s.LogPrefix())) success, err := verifyAndSaveNewPoSHeader(requestStatus, s, tx, cfg, header, headerInserter) log.Trace(fmt.Sprintf("[%s] New payload verification ended", s.LogPrefix()), "success", success, "err", err) @@ -412,8 +410,8 @@ func verifyAndSaveNewPoSHeader( return } - headBlockHash := rawdb.ReadHeadBlockHash(tx) - if headBlockHash == header.ParentHash { + currentHeadHash := rawdb.ReadHeadHeaderHash(tx) + if currentHeadHash == header.ParentHash { // OK, we're on the canonical chain if requestStatus == engineapi.New { cfg.hd.SetPendingPayloadStatus(headerHash) @@ -539,8 +537,8 @@ func HeadersPOW( return err } cfg.hd.SetPOSSync(false) - cfg.hd.SetFetching(true) - defer cfg.hd.SetFetching(false) + cfg.hd.SetFetchingNew(true) + defer cfg.hd.SetFetchingNew(false) headerProgress = cfg.hd.Progress() logPrefix := s.LogPrefix() // Check if this is called straight after the unwinds, which means we need to create new canonical markings diff --git a/turbo/stages/headerdownload/header_algos.go b/turbo/stages/headerdownload/header_algos.go index 87e15b6432af498701f0b5f91e33e5832689d0f7..ff7178dbbf9a60f7824d945a496e96fde1f96c9a 100644 --- a/turbo/stages/headerdownload/header_algos.go +++ b/turbo/stages/headerdownload/header_algos.go @@ -1217,10 +1217,10 @@ func (hd *HeaderDownload) EnableRequestChaining() { hd.requestChaining = true } -func (hd *HeaderDownload) SetFetching(fetching bool) { +func (hd *HeaderDownload) SetFetchingNew(fetching bool) { hd.lock.Lock() defer hd.lock.Unlock() - hd.fetching = fetching + hd.fetchingNew = fetching } func (hd *HeaderDownload) SetPosStatus(status SyncStatus) { @@ -1265,10 +1265,10 @@ func (hd *HeaderDownload) RequestChaining() bool { return hd.requestChaining } -func (hd *HeaderDownload) Fetching() bool { +func (hd *HeaderDownload) FetchingNew() bool { hd.lock.RLock() defer hd.lock.RUnlock() - return hd.fetching + return hd.fetchingNew } func (hd *HeaderDownload) GetPendingPayloadStatus() common.Hash { diff --git a/turbo/stages/headerdownload/header_data_struct.go b/turbo/stages/headerdownload/header_data_struct.go index 4fed6e9d60553971f38ef600287666ad6e2b9054..c3dd582378e4b3aebc05b51f179fc9344b6f4e46 100644 --- a/turbo/stages/headerdownload/header_data_struct.go +++ b/turbo/stages/headerdownload/header_data_struct.go @@ -277,7 +277,7 @@ type HeaderDownload struct { anchorLimit int // Maximum allowed number of anchors highestInDb uint64 // Height of the highest block header in the database requestChaining bool // Whether the downloader is allowed to issue more requests when previous responses created or moved an anchor - fetching bool // Set when the stage that is actively fetching the headers is in progress + fetchingNew bool // Set when the stage that is actively fetching the headers is in progress topSeenHeightPoW uint64 consensusHeaderReader consensus.ChainHeaderReader