Skip to content

Commit 3a98c6f

Browse files
authored
Merge pull request #21537 from karalabe/les-reorg-fix
eth/downloader: only roll back light sync if not fully validating
2 parents d81c9d9 + 367f12f commit 3a98c6f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

eth/downloader/downloader.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,18 +1501,20 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
15011501
rollbackErr = err
15021502

15031503
// If some headers were inserted, track them as uncertain
1504-
if n > 0 && rollback == 0 {
1504+
if (mode == FastSync || frequency > 1) && n > 0 && rollback == 0 {
15051505
rollback = chunk[0].Number.Uint64()
15061506
}
1507-
log.Debug("Invalid header encountered", "number", chunk[n].Number, "hash", chunk[n].Hash(), "parent", chunk[n].ParentHash, "err", err)
1507+
log.Warn("Invalid header encountered", "number", chunk[n].Number, "hash", chunk[n].Hash(), "parent", chunk[n].ParentHash, "err", err)
15081508
return fmt.Errorf("%w: %v", errInvalidChain, err)
15091509
}
15101510
// All verifications passed, track all headers within the alloted limits
1511-
head := chunk[len(chunk)-1].Number.Uint64()
1512-
if head-rollback > uint64(fsHeaderSafetyNet) {
1513-
rollback = head - uint64(fsHeaderSafetyNet)
1514-
} else {
1515-
rollback = 1
1511+
if mode == FastSync {
1512+
head := chunk[len(chunk)-1].Number.Uint64()
1513+
if head-rollback > uint64(fsHeaderSafetyNet) {
1514+
rollback = head - uint64(fsHeaderSafetyNet)
1515+
} else {
1516+
rollback = 1
1517+
}
15161518
}
15171519
}
15181520
// Unless we're doing light chains, schedule the headers for associated content retrieval

eth/downloader/downloader_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,9 @@ func testShiftedHeaderAttack(t *testing.T, protocol int, mode SyncMode) {
10201020
// Tests that upon detecting an invalid header, the recent ones are rolled back
10211021
// for various failure scenarios. Afterwards a full sync is attempted to make
10221022
// sure no state was corrupted.
1023-
func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
1024-
func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
1025-
func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) }
1026-
func TestInvalidHeaderRollback65Light(t *testing.T) { testInvalidHeaderRollback(t, 65, LightSync) }
1023+
func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
1024+
func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
1025+
func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) }
10271026

10281027
func testInvalidHeaderRollback(t *testing.T, protocol int, mode SyncMode) {
10291028
t.Parallel()

0 commit comments

Comments
 (0)