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

Small Merge-related clarifications & improvements #3785

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/sentry/sentry/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
34 changes: 16 additions & 18 deletions eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion turbo/stages/headerdownload/header_data_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down