// Copyright 2025 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see id mappings are left in the database and wait // for overwriting. return int(ohead - nhead), nil } // truncateFromTail removes excess elements from the end of the freezer based // on the given parameters. It returns the number of items that were removed. func truncateFromTail(store ethdb.AncientStore, typ historyType, ntail uint64) (int, error) { ohead, err := store.Ancients() if err != nil { return 0, err } otail, err := store.Tail() if err != nil { return 0, err } // Ensure that the truncation target falls within the valid range. if otail > ntail || ntail > ohead { return 0, fmt.Errorf("%w, %s, tail: %d, head: %d, target: %d", errTailTruncationOutOfRange, typ, otail, ohead, ntail) } // Short circuit if nothing to truncate. if otail == ntail { return 0, nil } otail, err = store.TruncateTail(ntail) if err != nil { return 0, err } // Associated root->id mappings are left in the database. return int(ntail - otail), nil }