diff --git a/core/blockchain.go b/core/blockchain.go index 084e5368ad..db7144f2e7 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -720,10 +720,12 @@ func (bc *BlockChain) loadLastState() error { // initializeHistoryPruning sets bc.historyPrunePoint based on actual DB state. func (bc *BlockChain) initializeHistoryPruning(latest uint64) error { - freezerTail, _ := bc.db.Tail() - policy := bc.cfg.HistoryPolicy + var ( + freezerTail, _ = bc.db.Tail() + policy = bc.cfg.HistoryPolicy + target uint64 + ) // Compute the current prune target from the policy. - var target uint64 switch policy.Mode { case history.KeepAll: if freezerTail > 0 { @@ -739,8 +741,9 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error { case history.KeepRecent: head := bc.CurrentBlock() if head == nil || head.Number.Uint64() <= policy.Window { - // Chain too short for pruning. Record actual DB state. if freezerTail > 0 { + // Chain too short for pruning. Record actual DB state. + log.Warn("Chain too short for pruning", "tail", freezerTail, "window", policy.Window) bc.updateHistoryPrunePoint(freezerTail) } return nil diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index fb04dfaac3..72c2d3ed59 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -473,7 +473,7 @@ func (bc *BlockChain) StateIndexProgress() (uint64, error) { return bc.triedb.IndexProgress() } -// HistoryPruningCutoff returns the actual history pruning point based on DB state. +// HistoryPruningCutoff returns the history pruning point based on DB state. // Blocks before this are not available in the database. func (bc *BlockChain) HistoryPruningCutoff() (uint64, common.Hash) { pt := bc.historyPrunePoint.Load()