Skip to content

Commit

Permalink
default side fork support (#4611)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Jul 2, 2022
1 parent 8599dce commit 3de3baf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
36 changes: 18 additions & 18 deletions eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ func verifyAndSaveNewPoSHeader(
return nil, false, err
}

err = headerInserter.FeedHeaderPoS(tx, header, headerHash)
if err != nil {
if err := headerInserter.FeedHeaderPoS(tx, header, headerHash); err != nil {
return nil, false, err
}

if err := cfg.hd.StorePayloadFork(tx, header, body); err != nil {
return nil, false, err
}

Expand All @@ -596,23 +599,20 @@ func verifyAndSaveNewPoSHeader(
// Side chain or something weird
// TODO(yperbasis): considered non-canonical because some missing headers were downloaded but not canonized
// Or it's not a problem because forkChoice is updated frequently?
if cfg.memoryOverlay {
status, latestValidHash, validationError, criticalError := cfg.hd.ValidatePayload(tx, header, body, cfg.chainConfig.TerminalTotalDifficulty, false, cfg.execPayload)
if criticalError != nil {
return &privateapi.PayloadStatus{CriticalError: criticalError}, false, criticalError
}
if validationError != nil {
cfg.hd.ReportBadHeaderPoS(headerHash, latestValidHash)
}
success = status == remote.EngineStatus_VALID || status == remote.EngineStatus_ACCEPTED
return &privateapi.PayloadStatus{
Status: status,
LatestValidHash: latestValidHash,
ValidationError: validationError,
}, success, nil
status, latestValidHash, validationError, criticalError := cfg.hd.ValidatePayload(tx, header, body, cfg.chainConfig.TerminalTotalDifficulty, false, cfg.execPayload)
if criticalError != nil {
return &privateapi.PayloadStatus{CriticalError: criticalError}, false, criticalError
}
// No canonization, HeadHeaderHash & StageProgress are not updated
return &privateapi.PayloadStatus{Status: remote.EngineStatus_ACCEPTED}, true, nil
if validationError != nil {
cfg.hd.ReportBadHeaderPoS(headerHash, latestValidHash)
}
success = status == remote.EngineStatus_VALID || status == remote.EngineStatus_ACCEPTED
return &privateapi.PayloadStatus{
Status: status,
LatestValidHash: latestValidHash,
ValidationError: validationError,
}, success, nil

}

if cfg.memoryOverlay && (cfg.hd.GetNextForkHash() == (common.Hash{}) || header.ParentHash == cfg.hd.GetNextForkHash()) {
Expand Down
13 changes: 13 additions & 0 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,19 @@ func abs64(n int64) uint64 {
return uint64(n)
}

func (hd *HeaderDownload) StorePayloadFork(tx kv.RwTx, header *types.Header, body *types.RawBody) error {
hd.lock.Lock()
defer hd.lock.Unlock()
maxDepth := uint64(16)
height := rawdb.ReadCurrentBlockNumber(tx)
if height == nil {
return fmt.Errorf("could not read block number.")
}
hd.sideForksBlock[header.Hash()] = sideForkBlock{header, body}
hd.cleanupOutdateSideForks(*height, maxDepth)
return nil
}

func (hd *HeaderDownload) ValidatePayload(tx kv.RwTx, header *types.Header, body *types.RawBody, terminalTotalDifficulty *big.Int, store bool, execPayload func(kv.RwTx, *types.Header, *types.RawBody, uint64, []*types.Header, []*types.RawBody) error) (status remote.EngineStatus, latestValidHash common.Hash, validationError error, criticalError error) {
hd.lock.Lock()
defer hd.lock.Unlock()
Expand Down

0 comments on commit 3de3baf

Please sign in to comment.