@@ -173,8 +173,8 @@ type LightChain interface {
173173type BlockChain interface {
174174 LightChain
175175
176- // HasBlockAndState verifies block and associated states' presence in the local chain.
177- HasBlockAndState (common.Hash , uint64 ) bool
176+ // HasBlock verifies a block's presence in the local chain.
177+ HasBlock (common.Hash , uint64 ) bool
178178
179179 // GetBlockByHash retrieves a block from the local chain.
180180 GetBlockByHash (common.Hash ) * types.Block
@@ -582,7 +582,6 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
582582 // Figure out the valid ancestor range to prevent rewrite attacks
583583 floor , ceil := int64 (- 1 ), d .lightchain .CurrentHeader ().Number .Uint64 ()
584584
585- p .log .Debug ("Looking for common ancestor" , "local" , ceil , "remote" , height )
586585 if d .mode == FullSync {
587586 ceil = d .blockchain .CurrentBlock ().NumberU64 ()
588587 } else if d .mode == FastSync {
@@ -591,6 +590,8 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
591590 if ceil >= MaxForkAncestry {
592591 floor = int64 (ceil - MaxForkAncestry )
593592 }
593+ p .log .Debug ("Looking for common ancestor" , "local" , ceil , "remote" , height )
594+
594595 // Request the topmost blocks to short circuit binary ancestor lookup
595596 head := ceil
596597 if head > height {
@@ -646,7 +647,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
646647 continue
647648 }
648649 // Otherwise check if we already know the header or not
649- if (d .mode == FullSync && d .blockchain .HasBlockAndState (headers [i ].Hash (), headers [i ].Number .Uint64 ())) || (d .mode != FullSync && d .lightchain .HasHeader (headers [i ].Hash (), headers [i ].Number .Uint64 ())) {
650+ if (d .mode == FullSync && d .blockchain .HasBlock (headers [i ].Hash (), headers [i ].Number .Uint64 ())) || (d .mode != FullSync && d .lightchain .HasHeader (headers [i ].Hash (), headers [i ].Number .Uint64 ())) {
650651 number , hash = headers [i ].Number .Uint64 (), headers [i ].Hash ()
651652
652653 // If every header is known, even future ones, the peer straight out lied about its head
@@ -711,7 +712,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
711712 arrived = true
712713
713714 // Modify the search interval based on the response
714- if (d .mode == FullSync && ! d .blockchain .HasBlockAndState (headers [0 ].Hash (), headers [0 ].Number .Uint64 ())) || (d .mode != FullSync && ! d .lightchain .HasHeader (headers [0 ].Hash (), headers [0 ].Number .Uint64 ())) {
715+ if (d .mode == FullSync && ! d .blockchain .HasBlock (headers [0 ].Hash (), headers [0 ].Number .Uint64 ())) || (d .mode != FullSync && ! d .lightchain .HasHeader (headers [0 ].Hash (), headers [0 ].Number .Uint64 ())) {
715716 end = check
716717 break
717718 }
0 commit comments