mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-10 08:51:38 +00:00
strict recent rule on init
This commit is contained in:
parent
43cc92e68a
commit
f871e1785c
2 changed files with 14 additions and 24 deletions
|
|
@ -764,21 +764,10 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
|
||||||
log.Error("Database pruned beyond configured history mode", "tail", freezerTail, "target", target, "mode", policy.Mode)
|
log.Error("Database pruned beyond configured history mode", "tail", freezerTail, "target", target, "mode", policy.Mode)
|
||||||
return fmt.Errorf("database pruned beyond requested history (tail=%d, target=%d)", freezerTail, target)
|
return fmt.Errorf("database pruned beyond requested history (tail=%d, target=%d)", freezerTail, target)
|
||||||
}
|
}
|
||||||
// Need to prune (freezerTail < target).
|
// Need to prune (freezerTail < target). Large-scale pruning is not
|
||||||
switch policy.Mode {
|
// performed at startup to avoid blocking the node for hours (tx index
|
||||||
case history.KeepPostMerge, history.KeepPostPrague:
|
// pruning is particularly slow). Use 'geth prune-history' instead.
|
||||||
// Static modes require the user to run 'geth prune-history' offline
|
return fmt.Errorf("history not pruned to target block %d (current tail %d), run 'geth prune-history' first", target, freezerTail)
|
||||||
// rather than blocking startup for hours (tx index pruning is slow).
|
|
||||||
return fmt.Errorf("history not pruned to target block %d (current tail %d), run 'geth prune-history --history.chain=%s' first", target, freezerTail, policy.Mode)
|
|
||||||
|
|
||||||
case history.KeepRecent:
|
|
||||||
// The rolling pruner will gradually catch up in the background.
|
|
||||||
if freezerTail > 0 {
|
|
||||||
bc.updateHistoryPrunePoint(freezerTail)
|
|
||||||
}
|
|
||||||
log.Warn("Chain history is behind pruning target, rolling pruner will catch up", "tail", freezerTail, "target", target)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHead rewinds the local chain to a new head. Depending on whether the node
|
// SetHead rewinds the local chain to a new head. Depending on whether the node
|
||||||
|
|
|
||||||
|
|
@ -182,19 +182,20 @@ func TestInitHistoryPruningStaticModeRequiresPruneHistory(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitHistoryPruningKeepRecentAllowsStartup(t *testing.T) {
|
func TestInitHistoryPruningKeepRecentRequiresPruneHistory(t *testing.T) {
|
||||||
db, gspec, _ := newTestChain(t, 200)
|
db, gspec, blocks := newTestChain(t, 200)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
// Reopen with KeepRecent and a small window. The tail (0) is behind the
|
// Set the head block so CurrentBlock() returns block 200 on reopen.
|
||||||
// target but KeepRecent should still allow startup — the rolling pruner
|
rawdb.WriteHeadBlockHash(db, blocks[len(blocks)-1].Hash())
|
||||||
// handles catch-up in the background.
|
|
||||||
|
// Reopen with KeepRecent and a small window. The tail (0) is behind
|
||||||
|
// the target (200-50=150), so startup should fail.
|
||||||
policy := history.HistoryPolicy{Mode: history.KeepRecent, Window: 50}
|
policy := history.HistoryPolicy{Mode: history.KeepRecent, Window: 50}
|
||||||
chain, err := reopenChain(db, gspec, policy)
|
_, err := reopenChain(db, gspec, policy)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatal("expected error when history not pruned to target, got nil")
|
||||||
}
|
}
|
||||||
defer chain.Stop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitHistoryPruningStaticModeBeyondTarget(t *testing.T) {
|
func TestInitHistoryPruningStaticModeBeyondTarget(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue