From 030f628ca7e1f5b56655bf2439963c6eb438a3ee Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Sun, 16 Nov 2025 13:13:42 +0200 Subject: [PATCH 1/6] core/rawdb: fix underflow in freezer inspect for empty ancients --- core/rawdb/ancient_utils.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index b940d910402c..b576de37a5a0 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -31,15 +31,19 @@ type tableSize struct { // freezerInfo contains the basic information of the freezer. type freezerInfo struct { - name string // The identifier of freezer - head uint64 // The number of last stored item in the freezer - tail uint64 // The number of first stored item in the freezer - sizes []tableSize // The storage size per table + name string // The identifier of freezer + ancients uint64 // The total number of stored items in the freezer + head uint64 // The number of last stored item in the freezer, valid only if ancients > 0 + tail uint64 // The number of first stored item in the freezer + sizes []tableSize // The storage size per table } // count returns the number of stored items in the freezer. func (info *freezerInfo) count() uint64 { - return info.head - info.tail + 1 + if info.ancients <= info.tail { + return 0 + } + return info.ancients - info.tail } // size returns the storage size of the entire freezer. @@ -65,7 +69,12 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci if err != nil { return freezerInfo{}, err } - info.head = ancients - 1 + info.ancients = ancients + if ancients > 0 { + info.head = ancients - 1 + } else { + info.head = 0 + } // Retrieve the number of first stored item tail, err := reader.Tail() From 15e5fd81c7fd458928d61886755a200371d6bac1 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Mon, 17 Nov 2025 12:20:38 +0000 Subject: [PATCH 2/6] accept changes --- core/rawdb/ancient_utils.go | 14 ++++++-------- core/rawdb/database.go | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index b576de37a5a0..c38124da8bda 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -35,17 +35,10 @@ type freezerInfo struct { ancients uint64 // The total number of stored items in the freezer head uint64 // The number of last stored item in the freezer, valid only if ancients > 0 tail uint64 // The number of first stored item in the freezer + count uint64 // The number of stored items in the freezer sizes []tableSize // The storage size per table } -// count returns the number of stored items in the freezer. -func (info *freezerInfo) count() uint64 { - if info.ancients <= info.tail { - return 0 - } - return info.ancients - info.tail -} - // size returns the storage size of the entire freezer. func (info *freezerInfo) size() common.StorageSize { var total common.StorageSize @@ -82,6 +75,11 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci return freezerInfo{}, err } info.tail = tail + if ancients == 0 { + info.count = 0 + } else { + info.count = info.head - info.tail + 1 + } return info, nil } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index d5c0f0aab295..448922d9bd79 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -644,7 +644,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)), strings.Title(table.name), table.size.String(), - fmt.Sprintf("%d", ancient.count()), + fmt.Sprintf("%d", ancient.count), }) } total.Add(uint64(ancient.size())) From 182d798c5f095289ff15cc6a8a4826d8c938df34 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Tue, 18 Nov 2025 21:29:20 +0200 Subject: [PATCH 3/6] remove unnecessary field --- core/rawdb/ancient_utils.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index c38124da8bda..9e00bae4f16d 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -32,7 +32,6 @@ type tableSize struct { // freezerInfo contains the basic information of the freezer. type freezerInfo struct { name string // The identifier of freezer - ancients uint64 // The total number of stored items in the freezer head uint64 // The number of last stored item in the freezer, valid only if ancients > 0 tail uint64 // The number of first stored item in the freezer count uint64 // The number of stored items in the freezer From 8d4dd2ae93630a144e0842f686980f5134553e38 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 24 Nov 2025 21:03:04 +0800 Subject: [PATCH 4/6] Refactor freezerInfo head assignment logic Removed unnecessary condition for setting head in freezerInfo. --- core/rawdb/ancient_utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index 9e00bae4f16d..26a86648e50f 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -32,7 +32,7 @@ type tableSize struct { // freezerInfo contains the basic information of the freezer. type freezerInfo struct { name string // The identifier of freezer - head uint64 // The number of last stored item in the freezer, valid only if ancients > 0 + head uint64 // The number of last stored item in the freezer tail uint64 // The number of first stored item in the freezer count uint64 // The number of stored items in the freezer sizes []tableSize // The storage size per table @@ -61,7 +61,6 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci if err != nil { return freezerInfo{}, err } - info.ancients = ancients if ancients > 0 { info.head = ancients - 1 } else { @@ -74,6 +73,7 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci return freezerInfo{}, err } info.tail = tail + if ancients == 0 { info.count = 0 } else { From b0efa6d15d5ceea56c2268d93c8f2d69e5cd3cd6 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 24 Nov 2025 21:08:04 +0800 Subject: [PATCH 5/6] Format freezerInfo struct field alignment --- core/rawdb/ancient_utils.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index 26a86648e50f..b374449ca8b9 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -31,11 +31,11 @@ type tableSize struct { // freezerInfo contains the basic information of the freezer. type freezerInfo struct { - name string // The identifier of freezer - head uint64 // The number of last stored item in the freezer - tail uint64 // The number of first stored item in the freezer - count uint64 // The number of stored items in the freezer - sizes []tableSize // The storage size per table + name string // The identifier of freezer + head uint64 // The number of last stored item in the freezer + tail uint64 // The number of first stored item in the freezer + count uint64 // The number of stored items in the freezer + sizes []tableSize // The storage size per table } // size returns the storage size of the entire freezer. From 515a3d9890416c2f5b5fc34d92b8686ee1a9732d Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 24 Nov 2025 22:29:37 +0800 Subject: [PATCH 6/6] Remove unnecessary blank line in ancient_utils.go --- core/rawdb/ancient_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index b374449ca8b9..7af3d2e19762 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -73,7 +73,7 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci return freezerInfo{}, err } info.tail = tail - + if ancients == 0 { info.count = 0 } else {