minor improvements

This commit is contained in:
Sina Mahmoodi 2026-04-01 20:50:58 +02:00
parent bfd03b86ae
commit 91b40ed46f
2 changed files with 8 additions and 5 deletions

View file

@ -720,10 +720,12 @@ func (bc *BlockChain) loadLastState() error {
// initializeHistoryPruning sets bc.historyPrunePoint based on actual DB state. // initializeHistoryPruning sets bc.historyPrunePoint based on actual DB state.
func (bc *BlockChain) initializeHistoryPruning(latest uint64) error { func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
freezerTail, _ := bc.db.Tail() var (
policy := bc.cfg.HistoryPolicy freezerTail, _ = bc.db.Tail()
policy = bc.cfg.HistoryPolicy
target uint64
)
// Compute the current prune target from the policy. // Compute the current prune target from the policy.
var target uint64
switch policy.Mode { switch policy.Mode {
case history.KeepAll: case history.KeepAll:
if freezerTail > 0 { if freezerTail > 0 {
@ -739,8 +741,9 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
case history.KeepRecent: case history.KeepRecent:
head := bc.CurrentBlock() head := bc.CurrentBlock()
if head == nil || head.Number.Uint64() <= policy.Window { if head == nil || head.Number.Uint64() <= policy.Window {
// Chain too short for pruning. Record actual DB state.
if freezerTail > 0 { 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) bc.updateHistoryPrunePoint(freezerTail)
} }
return nil return nil

View file

@ -473,7 +473,7 @@ func (bc *BlockChain) StateIndexProgress() (uint64, error) {
return bc.triedb.IndexProgress() 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. // Blocks before this are not available in the database.
func (bc *BlockChain) HistoryPruningCutoff() (uint64, common.Hash) { func (bc *BlockChain) HistoryPruningCutoff() (uint64, common.Hash) {
pt := bc.historyPrunePoint.Load() pt := bc.historyPrunePoint.Load()