Skip to content
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
41 changes: 11 additions & 30 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d
var (
parentHash common.Hash
batch = hc.chainDb.NewBatch()
origin = true
)
for hdr := hc.CurrentHeader(); hdr != nil && hdr.Number.Uint64() > head; hdr = hc.CurrentHeader() {
num := hdr.Number.Uint64()
Expand Down Expand Up @@ -594,37 +593,19 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d
hc.currentHeaderHash = parentHash
//headHeaderGauge.Update(parent.Number.Int64())

// If this is the first iteration, wipe any leftover data upwards too so
// we don't end up with dangling daps in the database
var nums []uint64
if origin {
for n := num + 1; len(rawdb.ReadAllHashes(hc.chainDb, n)) > 0; n++ {
nums = append([]uint64{n}, nums...) // suboptimal, but we don't really expect this path
}
origin = false
// Remove the related data from the database on all sidechains
// Gather all the side fork hashes
hash := hdr.Hash()
if delFn != nil {
delFn(batch, hash, num)
}
rawdb.DeleteHeader(batch, hash, num)
if err := rawdb.DeleteTd(batch, hash, num); err != nil {
panic(err)
}
nums = append(nums, num)

// Remove the related data from the database on all sidechains
for _, num := range nums {
// Gather all the side fork hashes
hashes := rawdb.ReadAllHashes(hc.chainDb, num)
if len(hashes) == 0 {
// No hashes in the database whatsoever, probably frozen already
hashes = append(hashes, hdr.Hash())
}
for _, hash := range hashes {
if delFn != nil {
delFn(batch, hash, num)
}
rawdb.DeleteHeader(batch, hash, num)
if err := rawdb.DeleteTd(batch, hash, num); err != nil {
panic(err)
}
}
if err := rawdb.DeleteCanonicalHash(batch, num); err != nil {
panic(err)
}
if err := rawdb.DeleteCanonicalHash(batch, num); err != nil {
panic(err)
}
}
if err := batch.Commit(); err != nil {
Expand Down
19 changes: 0 additions & 19 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ func DeleteCanonicalHash(db DatabaseDeleter, number uint64) error {
return nil
}

// ReadAllHashes retrieves all the hashes assigned to blocks at a certain heights,
// both canonical and reorged forks included.
func ReadAllHashes(db databaseReader, number uint64) []common.Hash {
//prefix := headerKeyPrefix(number)

hashes := make([]common.Hash, 0, 1)
/*
it := db.NewIteratorWithPrefix(prefix)
defer it.Release()

for it.Next() {
if key := it.Key(); len(key) == len(prefix)+32 {
hashes = append(hashes, common.BytesToHash(key[len(key)-32:]))
}
}
*/
return hashes
}

// ReadHeaderNumber returns the header number assigned to a hash.
func ReadHeaderNumber(db databaseReader, hash common.Hash) *uint64 {
data, err := db.Get(dbutils.HeaderNumberBucket, hash.Bytes())
Expand Down