@@ -22,9 +22,9 @@ const (
22
22
defaultWriteBatchSizePerRegion = 16384
23
23
)
24
24
25
- // processingRegions currently contains regions to process. Those regions
26
- // overlap, divergence, and new headers region are all detected but only new
27
- // headers region is processed.
25
+ // ProcessingRegions contains the different processing regions for a header
26
+ // import. The full range of headers is partitioned into divergence, overlap,
27
+ // and new headers regions, which are all processed during an import .
28
28
type processingRegions struct {
29
29
// importStartHeight defines the starting block height for the import
30
30
// process.
@@ -260,9 +260,14 @@ func (h *headersImport) Import(ctx context.Context) (*ImportResult, error) {
260
260
"headers processing failed: %w" , err )
261
261
}
262
262
263
- // TODO(mohamedawnallah): process the overlap region. This mainly
264
- // includes a validation strategy for the overlap region between headers
265
- // from import and target sources.
263
+ // Process overlap headers region.
264
+ // Process headers in the overlap region by verifying the headers using
265
+ // a sampling approach to efficiently validate consistency.
266
+ err = h .processOverlapHeadersRegion (ctx , regions .overlap , result )
267
+ if err != nil {
268
+ return nil , fmt .Errorf ("headers import failed: overlap " +
269
+ "headers processing failed: %w" , err )
270
+ }
266
271
267
272
// Process new headers region.
268
273
// Add headers from the import source to the target stores, extending
@@ -347,41 +352,10 @@ func (h *headersImport) validateChainContinuity() error {
347
352
348
353
default :
349
354
// Import data starts before or at the target tip height. This
350
- // means there is an overlap, so we need to verify compatibility
351
- // using sampling approach for minimal processing time.
352
-
353
- // First we need to determine the overlap range.
354
- overlapStart := importStartHeight
355
+ // means there is an overlap, and we just need to validate the
356
+ // headers connection.
355
357
overlapEnd := min (effectiveTipHeight , importEndHeight )
356
358
357
- // Now we can verify headers at the start of the overlap range.
358
- if err = h .verifyHeadersAtTargetHeight (
359
- overlapStart , verifyBlockAndFilter ,
360
- ); err != nil {
361
- return err
362
- }
363
-
364
- // If overlap range is more than 1 header, we can also verify at
365
- // the end.
366
- if overlapEnd > overlapStart {
367
- if err = h .verifyHeadersAtTargetHeight (
368
- overlapEnd , verifyBlockAndFilter ,
369
- ); err != nil {
370
- return err
371
- }
372
- }
373
-
374
- // If the overlap range is more than 2 headers, also verify at
375
- // the middle point.
376
- if overlapEnd - overlapStart > 2 {
377
- middleHeight := (overlapStart + overlapEnd ) / 2
378
- if err = h .verifyHeadersAtTargetHeight (
379
- middleHeight , verifyBlockAndFilter ,
380
- ); err != nil {
381
- return err
382
- }
383
- }
384
-
385
359
// Validate headers beyond the overlap region if there are any
386
360
// remaining headers to import.
387
361
if overlapEnd < importEndHeight {
@@ -714,6 +688,30 @@ func (h *headersImport) validateLeadAndSyncLag(ctx context.Context,
714
688
return nil
715
689
}
716
690
691
+ // processOverlapHeadersRegion processes overlap headers by verifying the
692
+ // headers using a sampling approach to efficiently validate consistency.
693
+ func (h * headersImport ) processOverlapHeadersRegion (ctx context.Context ,
694
+ region headerRegion , result * ImportResult ) error {
695
+
696
+ if ! region .exists {
697
+ return nil
698
+ }
699
+
700
+ log .Infof ("Verifying %d overlap headers from heights %d to %d" ,
701
+ region .end - region .start + 1 , region .start , region .end )
702
+
703
+ if err := h .validateHeadersSampling (
704
+ ctx , region .start , region .end , region .syncModes .verify ,
705
+ ); err != nil {
706
+ return fmt .Errorf ("failed to validate headers via " +
707
+ "sampling: %w" , err )
708
+ }
709
+
710
+ result .SkippedCount += int (region .end - region .start + 1 )
711
+
712
+ return nil
713
+ }
714
+
717
715
// processNewHeadersRegion imports headers from the specified region into the
718
716
// target stores. This method handles the case where headers exist in the import
719
717
// source but not in the target stores.
0 commit comments