@@ -77,6 +77,13 @@ impl HeaderDownloader {
7777 if self . total_score < total_score {
7878 self . total_score = total_score;
7979 self . best_hash = best_hash;
80+
81+ if self . client . block_header ( & BlockId :: Hash ( best_hash) ) . is_some ( ) {
82+ self . pivot = Pivot {
83+ hash : best_hash,
84+ total_score,
85+ }
86+ }
8087 true
8188 } else {
8289 false
@@ -129,7 +136,11 @@ impl HeaderDownloader {
129136 /// Expects importing headers matches requested header
130137 pub fn import_headers ( & mut self , headers : & [ Header ] ) {
131138 let first_header_hash = headers. first ( ) . expect ( "First header must exist" ) . hash ( ) ;
132- if first_header_hash == self . pivot . hash {
139+
140+ // This happens when best_hash is imported by other peer.
141+ if self . best_hash == self . pivot . hash {
142+ ctrace ! ( SYNC , "Ignore received headers, pivot already reached the best hash" ) ;
143+ } else if first_header_hash == self . pivot . hash {
133144 for header in headers. iter ( ) {
134145 self . downloaded . insert ( header. hash ( ) , header. clone ( ) ) ;
135146 }
@@ -161,6 +172,13 @@ impl HeaderDownloader {
161172 pub fn mark_as_imported ( & mut self , hashes : Vec < H256 > ) {
162173 for hash in hashes {
163174 self . downloaded . remove ( & hash) ;
175+
176+ if self . best_hash == hash {
177+ self . pivot = Pivot {
178+ hash,
179+ total_score : self . total_score ,
180+ }
181+ }
164182 }
165183 }
166184}
0 commit comments