Fix snapshot merge and anchor removal (#4228)

* Print retire

* Print

* Print

* Print

* Print

* Not fail when block is not found

* Remove prints

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-05-22 11:08:03 +01:00 committed by GitHub
parent 2ec9733cee
commit 9dc7067e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -1126,17 +1126,18 @@ func DeleteAncientBlocks(db kv.RwTx, blockTo uint64, blocksDeleteLimit int) erro
return err
}
if b == nil {
return fmt.Errorf("DeleteAncientBlocks: block body not found for block %d", n)
}
txIDBytes := make([]byte, 8)
for txID := b.BaseTxId; txID < b.BaseTxId+uint64(b.TxAmount); txID++ {
binary.BigEndian.PutUint64(txIDBytes, txID)
bucket := kv.EthTx
if !isCanonical {
bucket = kv.NonCanonicalTxs
}
if err := db.Delete(bucket, txIDBytes, nil); err != nil {
return err
log.Warn("DeleteAncientBlocks: block body not found", "height", n)
} else {
txIDBytes := make([]byte, 8)
for txID := b.BaseTxId; txID < b.BaseTxId+uint64(b.TxAmount); txID++ {
binary.BigEndian.PutUint64(txIDBytes, txID)
bucket := kv.EthTx
if !isCanonical {
bucket = kv.NonCanonicalTxs
}
if err := db.Delete(bucket, txIDBytes, nil); err != nil {
return err
}
}
}
if err := db.Delete(kv.Headers, k, nil); err != nil {

View File

@ -195,8 +195,6 @@ func (hd *HeaderDownload) removeAnchor(anchor *Anchor) {
// Anchor is removed from the map, and from the priority queue
delete(hd.anchors, anchor.parentHash)
heap.Remove(hd.anchorQueue, anchor.idx)
for child := anchor.fLink; child != nil; child, child.next = child.next, nil {
}
anchor.idx = -1
}
@ -375,6 +373,8 @@ func (hd *HeaderDownload) ReadProgressFromDb(tx kv.RwTx) (err error) {
func (hd *HeaderDownload) invalidateAnchor(anchor *Anchor, reason string) {
log.Debug("Invalidating anchor", "height", anchor.blockHeight, "hash", anchor.parentHash, "reason", reason)
hd.removeAnchor(anchor)
for child := anchor.fLink; child != nil; child, child.next = child.next, nil {
}
hd.removeUpwards(anchor.fLink)
}
@ -937,7 +937,6 @@ func (hd *HeaderDownload) ProcessHeader(sh ChainSegmentHeader, newBlock bool, pe
peerID: peerID,
blockHeight: sh.Number,
}
link.next = anchor.fLink
anchor.fLink = link
hd.anchors[anchor.parentHash] = anchor
heap.Push(hd.anchorQueue, anchor)