Skip to content

Commit

Permalink
Fixed EL integration spectest (#7975)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 committed Aug 6, 2023
1 parent d69b20b commit e3d642d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
10 changes: 6 additions & 4 deletions turbo/engineapi/engine_block_downloader/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func (e *EngineBlockDownloader) download(hashToDownload libcommon.Hash, download
e.status.Store(headerdownload.Idle)
return
}
if block != nil {
// Can fail, not an issue in this case.
e.chainRW.InsertHeaderAndBodyAndWait(block.Header(), block.RawBody())
}
e.logger.Info("[EngineBlockDownloader] Finished downloading blocks", "from", startBlock-1, "to", endBlock)
if block == nil {
e.status.Store(headerdownload.Idle)
return
}
// Can fail, not an issue in this case.
e.chainRW.InsertHeaderAndBodyAndWait(block.Header(), block.RawBody())
// Lastly attempt verification
status, latestValidHash, err := e.chainRW.ValidateChain(block.Hash(), block.NumberU64())
if err != nil {
Expand Down
35 changes: 31 additions & 4 deletions turbo/stages/mock/mock_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,22 @@ func (ms *MockSentry) insertPoSBlocks(chain *core.ChainPack, tx kv.RwTx) error {
return nil
}

firstHeight := int64(-1)
var bottomBlock *types.Block

for i := n; i < chain.Length(); i++ {
if err := chain.Blocks[i].HashCheck(); err != nil {
return err
}
if firstHeight == -1 {
firstHeight = int64(chain.Blocks[i].NumberU64())
if bottomBlock == nil {
bottomBlock = chain.Blocks[i]
}
cr := stagedsync.ChainReader{Cfg: *ms.ChainConfig, Db: tx, BlockReader: ms.BlockReader}
if err := ms.Engine.VerifyHeader(cr, chain.Blocks[i].Header(), true); err != nil {
return err
}

if err := ms.Engine.VerifyUncles(cr, chain.Blocks[i].Header(), chain.Blocks[i].Uncles()); err != nil {
return err
}
rawdb.WriteHeader(tx, chain.Blocks[i].Header())
if _, err := rawdb.WriteRawBodyIfNotExists(tx, chain.Blocks[i].Hash(), chain.Blocks[i].NumberU64(), chain.Blocks[i].RawBody()); err != nil {
Expand All @@ -648,10 +656,29 @@ func (ms *MockSentry) insertPoSBlocks(chain *core.ChainPack, tx kv.RwTx) error {
}
rawdb.WriteCanonicalHash(tx, chain.Blocks[i].Hash(), chain.Blocks[i].NumberU64())
}
if firstHeight == -1 {
if bottomBlock == nil {
return nil
}
currentHash := bottomBlock.ParentHash()
currentNumber := bottomBlock.NumberU64() - 1
for canonical, err := rawdb.IsCanonicalHash(tx, currentHash, currentNumber); !canonical; canonical, err = rawdb.IsCanonicalHash(tx, currentHash, currentNumber) {
if err != nil {
return err
}
currentHeader := rawdb.ReadHeader(tx, currentHash, currentNumber)
if currentHeader == nil {
return fmt.Errorf("missing header")
}
if err := rawdb.WriteCanonicalHash(tx, currentHash, currentNumber); err != nil {
return err
}

currentHash = currentHeader.ParentHash
currentNumber--
}

ms.posStagedSync.UnwindTo(currentNumber, libcommon.Hash{})
ms.posStagedSync.RunUnwind(ms.DB, tx)
hook := stages2.NewHook(ms.Ctx, ms.Notifications, ms.Sync, ms.BlockReader, ms.ChainConfig, ms.Log, ms.UpdateHead)

if err := stages.SaveStageProgress(tx, stages.Headers, chain.TopBlock.NumberU64()); err != nil {
Expand Down

0 comments on commit e3d642d

Please sign in to comment.