Skip to content

Commit

Permalink
Optimized backend pre-checks and fixed FCU deadlock (#5124)
Browse files Browse the repository at this point in the history
* Optimized backend pre-checks and fixed FCU deadlock

* fixed tests

Co-authored-by: giuliorebuffo <[email protected]>
  • Loading branch information
Giulio2002 and giuliorebuffo authored Aug 20, 2022
1 parent 18f9313 commit 1303023
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ func HeadersPOS(
return nil
}

cfg.hd.SetPOSSync(true)
log.Info(fmt.Sprintf("[%s] Waiting for Beacon Chain...", s.LogPrefix()))

onlyNewRequests := cfg.hd.PosStatus() == headerdownload.Syncing
interrupt, requestId, requestWithStatus := cfg.hd.BeaconRequestList.WaitForRequest(onlyNewRequests, test)

cfg.hd.SetPOSSync(true)
cfg.hd.SetHeaderReader(&chainReader{config: &cfg.chainConfig, tx: tx, blockReader: cfg.blockReader})
headerInserter := headerdownload.NewHeaderInserter(s.LogPrefix(), nil, s.BlockNumber, cfg.blockReader)

Expand Down
4 changes: 3 additions & 1 deletion ethdb/privateapi/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestMockDownloadRequest(t *testing.T) {

makeTestDb(ctx, db)
hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)

hd.SetPOSSync(true)
events := NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &params.ChainConfig{TerminalTotalDifficulty: common.Big1}, nil, hd, false)

Expand Down Expand Up @@ -149,6 +149,7 @@ func TestMockValidExecution(t *testing.T) {
makeTestDb(ctx, db)

hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
hd.SetPOSSync(true)

events := NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &params.ChainConfig{TerminalTotalDifficulty: common.Big1}, nil, hd, false)
Expand Down Expand Up @@ -184,6 +185,7 @@ func TestMockInvalidExecution(t *testing.T) {
makeTestDb(ctx, db)

hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
hd.SetPOSSync(true)

events := NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &params.ChainConfig{TerminalTotalDifficulty: common.Big1}, nil, hd, false)
Expand Down
12 changes: 3 additions & 9 deletions ethdb/privateapi/ethbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,24 +397,18 @@ func (s *EthBackendServer) getPayloadStatusFromHashIfPossible(blockHash common.H
}
// Retrieve parent and total difficulty.
var parent *types.Header
var td *big.Int
if newPayload {
// Obtain TD
parent, err = rawdb.ReadHeaderByHash(tx, parentHash)
if err != nil {
return nil, err
}
td, err = rawdb.ReadTdByHash(tx, parentHash)
} else {
td, err = rawdb.ReadTdByHash(tx, blockHash)
}
if err != nil {
return nil, err
}

// Check if we already reached TTD.
if td != nil && td.Cmp(s.config.TerminalTotalDifficulty) < 0 {
if !s.hd.POSSync() {
log.Warn(fmt.Sprintf("[%s] TTD not reached yet", prefix), "hash", blockHash)
return &engineapi.PayloadStatus{Status: remote.EngineStatus_INVALID, LatestValidHash: common.Hash{}}, nil
return &engineapi.PayloadStatus{Status: remote.EngineStatus_SYNCING, LatestValidHash: common.Hash{}}, nil
}

var canonicalHash common.Hash
Expand Down

0 comments on commit 1303023

Please sign in to comment.