@@ -1102,6 +1102,7 @@ func (s *skeleton) cleanStales(filled *types.Header) error {
1102
1102
var (
1103
1103
start = s .progress .Subchains [0 ].Tail // start deleting from the first known header
1104
1104
end = number // delete until the requested threshold
1105
+ batch = s .db .NewBatch ()
1105
1106
)
1106
1107
s .progress .Subchains [0 ].Tail = number
1107
1108
s .progress .Subchains [0 ].Next = filled .ParentHash
@@ -1111,16 +1112,13 @@ func (s *skeleton) cleanStales(filled *types.Header) error {
1111
1112
// subchain forward to keep tracking the node's block imports
1112
1113
end = s .progress .Subchains [0 ].Head + 1 // delete the entire original range, including the head
1113
1114
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 ()
1117
1115
1118
- if end != number {
1119
1116
// The entire original skeleton chain was deleted and a new one
1120
1117
// defined. Make sure the new single-header chain gets pushed to
1121
1118
// disk to keep internal state consistent.
1122
1119
rawdb .WriteSkeletonHeader (batch , filled )
1123
1120
}
1121
+ // Execute the trimming and the potential rewiring of the progress
1124
1122
s .saveSyncStatus (batch )
1125
1123
for n := start ; n < end ; n ++ {
1126
1124
// 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)
1176
1174
return nil , nil , err
1177
1175
}
1178
1176
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
+ }
1179
1180
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
+ }
1181
1184
return head , tail , nil
1182
1185
}
1183
1186
0 commit comments