Skip to content

Commit 74e2da9

Browse files
rjl493456442shekhirin
authored andcommitted
eth/downloader: fix cornercase when clean stale beacon headers (ethereum#26441)
1 parent 8c4b120 commit 74e2da9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

eth/downloader/skeleton.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ func (s *skeleton) cleanStales(filled *types.Header) error {
11021102
var (
11031103
start = s.progress.Subchains[0].Tail // start deleting from the first known header
11041104
end = number // delete until the requested threshold
1105+
batch = s.db.NewBatch()
11051106
)
11061107
s.progress.Subchains[0].Tail = number
11071108
s.progress.Subchains[0].Next = filled.ParentHash
@@ -1111,16 +1112,13 @@ func (s *skeleton) cleanStales(filled *types.Header) error {
11111112
// subchain forward to keep tracking the node's block imports
11121113
end = s.progress.Subchains[0].Head + 1 // delete the entire original range, including the head
11131114
s.progress.Subchains[0].Head = number // assign a new head (tail is already assigned to this)
1114-
}
1115-
// Execute the trimming and the potential rewiring of the progress
1116-
batch := s.db.NewBatch()
11171115

1118-
if end != number {
11191116
// The entire original skeleton chain was deleted and a new one
11201117
// defined. Make sure the new single-header chain gets pushed to
11211118
// disk to keep internal state consistent.
11221119
rawdb.WriteSkeletonHeader(batch, filled)
11231120
}
1121+
// Execute the trimming and the potential rewiring of the progress
11241122
s.saveSyncStatus(batch)
11251123
for n := start; n < end; n++ {
11261124
// If the batch grew too big, flush it and continue with a new batch.
@@ -1176,8 +1174,13 @@ func (s *skeleton) Bounds() (head *types.Header, tail *types.Header, err error)
11761174
return nil, nil, err
11771175
}
11781176
head = rawdb.ReadSkeletonHeader(s.db, progress.Subchains[0].Head)
1177+
if head == nil {
1178+
return nil, nil, fmt.Errorf("head skeleton header %d is missing", progress.Subchains[0].Head)
1179+
}
11791180
tail = rawdb.ReadSkeletonHeader(s.db, progress.Subchains[0].Tail)
1180-
1181+
if tail == nil {
1182+
return nil, nil, fmt.Errorf("tail skeleton header %d is missing", progress.Subchains[0].Tail)
1183+
}
11811184
return head, tail, nil
11821185
}
11831186

0 commit comments

Comments
 (0)