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

Optimized backend pre-checks and fixed FCU deadlock #5124

Merged
merged 2 commits into from
Aug 20, 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 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