Update instead of SaveStageProgress for stages.Header (#3456)

* Update instead of SaveStageProgress for stages.Header

* Call WriteHeadHeaderHash/stage.Update after the loop
This commit is contained in:
Andrew Ashikhmin 2022-02-10 14:18:51 +01:00 committed by GitHub
parent 2e0602b8dd
commit d6525b342d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -271,7 +271,7 @@ func handleForkChoice(
return err
}
return stages.SaveStageProgress(tx, stages.Headers, headerNumber)
return s.Update(tx, headerNumber)
}
func handleNewPayload(
@ -386,7 +386,7 @@ func verifyAndSaveNewPoSHeader(
return
}
err = stages.SaveStageProgress(tx, stages.Headers, headerNumber)
err = s.Update(tx, headerNumber)
if err != nil {
return
}
@ -661,9 +661,18 @@ Loop:
}
if headerInserter.Unwind() {
u.UnwindTo(headerInserter.UnwindPoint(), common.Hash{})
} else if headerInserter.GetHighest() != 0 {
if err := fixCanonicalChain(logPrefix, logEvery, headerInserter.GetHighest(), headerInserter.GetHighestHash(), tx, cfg.blockReader); err != nil {
return fmt.Errorf("fix canonical chain: %w", err)
}
if headerInserter.GetHighest() != 0 {
if !headerInserter.Unwind() {
if err := fixCanonicalChain(logPrefix, logEvery, headerInserter.GetHighest(), headerInserter.GetHighestHash(), tx, cfg.blockReader); err != nil {
return fmt.Errorf("fix canonical chain: %w", err)
}
}
if err = rawdb.WriteHeadHeaderHash(tx, headerInserter.GetHighestHash()); err != nil {
return fmt.Errorf("[%s] marking head header hash as %x: %w", logPrefix, headerInserter.GetHighestHash(), err)
}
if err = s.Update(tx, headerInserter.GetHighest()); err != nil {
return fmt.Errorf("[%s] saving Headers progress: %w", logPrefix, err)
}
}
if !useExternalTx {

View File

@ -902,12 +902,6 @@ func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader interf
if err != nil {
return nil, err
}
if err = rawdb.WriteHeadHeaderHash(db, hash); err != nil {
return nil, fmt.Errorf("[%s] marking head header hash as %x: %w", hi.logPrefix, hash, err)
}
if err = stages.SaveStageProgress(db, stages.Headers, blockHeight); err != nil {
return nil, fmt.Errorf("[%s] saving Headers progress: %w", hi.logPrefix, err)
}
hi.highest = blockHeight
hi.highestHash = hash
hi.highestTimestamp = header.Time