mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Do not remove headers when unwinding (#2122)
Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
parent
338fc0df26
commit
657a8b13df
@ -53,6 +53,7 @@ type ChainReader interface {
|
||||
|
||||
// GetBlock retrieves a block from the database by hash and number.
|
||||
GetBlock(hash common.Hash, number uint64) *types.Block
|
||||
GetHeader(hash common.Hash, number uint64) *types.Header
|
||||
|
||||
HasBlock(hash common.Hash, number uint64) bool
|
||||
}
|
||||
|
@ -211,15 +211,23 @@ func getUncles(chain consensus.ChainReader, header *types.Header) (mapset.Set, m
|
||||
|
||||
number, parent := header.Number.Uint64()-1, header.ParentHash
|
||||
for i := 0; i < 7; i++ {
|
||||
ancestor := chain.GetBlock(parent, number)
|
||||
if ancestor == nil {
|
||||
ancestorHeader := chain.GetHeader(parent, number)
|
||||
if ancestorHeader == nil {
|
||||
break
|
||||
}
|
||||
ancestors[ancestor.Hash()] = ancestor.Header()
|
||||
for _, uncle := range ancestor.Uncles() {
|
||||
uncles.Add(uncle.Hash())
|
||||
ancestors[parent] = ancestorHeader
|
||||
// If the ancestor doesn't have any uncles, we don't have to iterate them
|
||||
if ancestorHeader.UncleHash != types.EmptyUncleHash {
|
||||
// Need to add those uncles to the blacklist too
|
||||
ancestor := chain.GetBlock(parent, number)
|
||||
if ancestor == nil {
|
||||
break
|
||||
}
|
||||
for _, uncle := range ancestor.Uncles() {
|
||||
uncles.Add(uncle.Hash())
|
||||
}
|
||||
}
|
||||
parent, number = ancestor.ParentHash(), number-1
|
||||
parent, number = ancestorHeader.ParentHash, number-1
|
||||
}
|
||||
ancestors[header.Hash()] = header
|
||||
uncles.Add(header.Hash())
|
||||
|
@ -260,9 +260,7 @@ func HeadersUnwind(u *UnwindState, s *StageState, tx ethdb.RwTx, cfg HeadersCfg)
|
||||
if hash, err = rawdb.ReadCanonicalHash(tx, blockHeight); err != nil {
|
||||
return err
|
||||
}
|
||||
rawdb.DeleteHeader(tx, hash, blockHeight)
|
||||
rawdb.DeleteTd(tx, hash, blockHeight)
|
||||
rawdb.DeleteHeaderNumber(tx, hash)
|
||||
}
|
||||
if err = rawdb.DeleteCanonicalHash(tx, blockHeight); err != nil {
|
||||
return err
|
||||
|
@ -381,7 +381,9 @@ func (ms *MockSentry) InsertChain(chain *core.ChainPack) error {
|
||||
}
|
||||
}
|
||||
// Check if the latest header was imported or rolled back
|
||||
if rawdb.ReadHeader(ethdb.NewObjectDatabase(ms.DB), chain.TopBlock.Hash(), chain.TopBlock.NumberU64()) == nil {
|
||||
if td, tdErr := rawdb.ReadTd(ethdb.NewObjectDatabase(ms.DB), chain.TopBlock.Hash(), chain.TopBlock.NumberU64()); tdErr != nil {
|
||||
return tdErr
|
||||
} else if td == nil {
|
||||
return fmt.Errorf("did not import block %d %x", chain.TopBlock.NumberU64(), chain.TopBlock.Hash())
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user