Skip to content

Commit

Permalink
Merge pull request #79 from kcalvinalvin/2023-09-07-fix-bugs-with-pru…
Browse files Browse the repository at this point in the history
…ning

blockchain: Fix prune bug
  • Loading branch information
kcalvinalvin committed Sep 8, 2023
2 parents a2c974b + 64da5aa commit affee16
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,23 +637,26 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
}

// Only attempt to prune blocks from the index if there have been blocks pruned.
if earliestKeptBlockHeight != -1 {
if b.indexManager != nil && earliestKeptBlockHeight != -1 {
err = b.indexManager.PruneBlocks(
dbTx, earliestKeptBlockHeight, b.BlockHashByHeight)
if err != nil {
log.Warnf("Prune failed on block height %d, hash %s. Error %v",
node.height, node.hash.String(), err)
}
}
flushNeeded, err := b.flushNeededAfterPrune(earliestKeptBlockHeight)
if err != nil {
return err
}
if b.utreexoView == nil && flushNeeded {
err = b.utxoCache.flush(FlushRequired, state)
if b.utreexoView == nil {
flushNeeded, err := b.flushNeededAfterPrune(earliestKeptBlockHeight)
if err != nil {
return err
}

if flushNeeded {
err = b.utxoCache.flush(FlushRequired, state)
if err != nil {
return err
}
}
}
}

Expand Down

0 comments on commit affee16

Please sign in to comment.