@@ -358,6 +358,7 @@ func (s *skeleton) sync(head *types.Header) (*types.Header, error) {
358
358
// If the sync is already done, resume the backfiller. When the loop stops,
359
359
// terminate the backfiller too.
360
360
linked := len (s .progress .Subchains ) == 1 &&
361
+ rawdb .HasHeader (s .db , s .progress .Subchains [0 ].Next , s .scratchHead ) &&
361
362
rawdb .HasBody (s .db , s .progress .Subchains [0 ].Next , s .scratchHead ) &&
362
363
rawdb .HasReceipts (s .db , s .progress .Subchains [0 ].Next , s .scratchHead )
363
364
if linked {
@@ -946,12 +947,12 @@ func (s *skeleton) processResponse(res *headerResponse) (linked bool, merged boo
946
947
// In the case of full sync it would be enough to check for the body,
947
948
// but even a full syncing node will generate a receipt once block
948
949
// processing is done, so it's just one more "needless" check.
949
- var (
950
- hasBody = rawdb . HasBody ( s . db , header . ParentHash , header . Number . Uint64 () - 1 )
951
- hasReceipt = rawdb .HasReceipts (s .db , header .ParentHash , header .Number .Uint64 ()- 1 )
952
- )
953
- if hasBody && hasReceipt {
954
- linked = true
950
+ //
951
+ // The weird cascading checks are done to minimize the database reads.
952
+ linked = rawdb .HasHeader (s .db , header .ParentHash , header .Number .Uint64 ()- 1 ) &&
953
+ rawdb . HasBody ( s . db , header . ParentHash , header . Number . Uint64 () - 1 ) &&
954
+ rawdb . HasReceipts ( s . db , header . ParentHash , header . Number . Uint64 () - 1 )
955
+ if linked {
955
956
break
956
957
}
957
958
}
0 commit comments