@@ -358,6 +358,7 @@ func (s *skeleton) sync(head *types.Header) (*types.Header, error) {
358358 // If the sync is already done, resume the backfiller. When the loop stops,
359359 // terminate the backfiller too.
360360 linked := len (s .progress .Subchains ) == 1 &&
361+ rawdb .HasHeader (s .db , s .progress .Subchains [0 ].Next , s .scratchHead ) &&
361362 rawdb .HasBody (s .db , s .progress .Subchains [0 ].Next , s .scratchHead ) &&
362363 rawdb .HasReceipts (s .db , s .progress .Subchains [0 ].Next , s .scratchHead )
363364 if linked {
@@ -946,12 +947,12 @@ func (s *skeleton) processResponse(res *headerResponse) (linked bool, merged boo
946947 // In the case of full sync it would be enough to check for the body,
947948 // but even a full syncing node will generate a receipt once block
948949 // 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 {
955956 break
956957 }
957958 }
0 commit comments