Browse Source

eth/downloader: enable unsync-protection for light client (#19496)

* eth/downloader: enable unsync-protection for light client

* eth/downloader: fix tests
gary rong 6 years ago
parent
commit
749ccab9a4
2 changed files with 3 additions and 3 deletions
  1. 1 1
      eth/downloader/downloader.go
  2. 2 2
      eth/downloader/downloader_test.go

+ 1 - 1
eth/downloader/downloader.go

@@ -580,7 +580,7 @@ func (d *Downloader) fetchHeight(p *peerConnection) (*types.Header, error) {
 				return nil, errBadPeer
 			}
 			head := headers[0]
-			if d.mode == FastSync && head.Number.Uint64() < d.checkpoint {
+			if (d.mode == FastSync || d.mode == LightSync) && head.Number.Uint64() < d.checkpoint {
 				p.log.Warn("Remote head below checkpoint", "number", head.Number, "hash", head.Hash())
 				return nil, errUnsyncedPeer
 			}

+ 2 - 2
eth/downloader/downloader_test.go

@@ -1594,13 +1594,13 @@ func testCheckpointEnforcement(t *testing.T, protocol int, mode SyncMode) {
 	tester.newPeer("peer", protocol, chain)
 
 	var expect error
-	if mode == FastSync {
+	if mode == FastSync || mode == LightSync {
 		expect = errUnsyncedPeer
 	}
 	if err := tester.sync("peer", nil, mode); err != expect {
 		t.Fatalf("block sync error mismatch: have %v, want %v", err, expect)
 	}
-	if mode == FastSync {
+	if mode == FastSync || mode == LightSync {
 		assertOwnChain(t, tester, 1)
 	} else {
 		assertOwnChain(t, tester, chain.len())