@@ -278,16 +278,19 @@ impl SyncManager {
278
278
store. add_block_headers ( block_hashes. clone ( ) , block_headers. clone ( ) ) ?;
279
279
280
280
if self . sync_mode == SyncMode :: Full {
281
- self . download_and_run_blocks (
282
- & block_hashes,
283
- & block_headers,
284
- sync_head,
285
- & mut current_head,
286
- & mut search_head,
287
- sync_head_found,
288
- store. clone ( ) ,
289
- )
290
- . await ?;
281
+ let last_block_hash = self
282
+ . download_and_run_blocks (
283
+ & block_hashes,
284
+ & block_headers,
285
+ sync_head,
286
+ sync_head_found,
287
+ store. clone ( ) ,
288
+ )
289
+ . await ?;
290
+ if let Some ( last_block_hash) = last_block_hash {
291
+ current_head = last_block_hash;
292
+ search_head = current_head;
293
+ }
291
294
}
292
295
293
296
if sync_head_found {
@@ -346,18 +349,19 @@ impl SyncManager {
346
349
Ok ( ( ) )
347
350
}
348
351
349
- /// Requests block bodies from peers via p2p, executes and stores them
350
- /// Returns an error if there was a problem while executing or validating the blocks
352
+ /// Attempts to fetch up to 1024 block bodies from peers via P2P, starting from the sync head.
353
+ /// Executes and stores the retrieved blocks.
354
+ ///
355
+ /// Returns an error if execution or validation fails.
356
+ /// On success, returns the hash of the last successfully executed block body.
351
357
async fn download_and_run_blocks (
352
358
& mut self ,
353
359
block_hashes : & [ BlockHash ] ,
354
360
block_headers : & [ BlockHeader ] ,
355
361
sync_head : BlockHash ,
356
- current_head : & mut BlockHash ,
357
- search_head : & mut BlockHash ,
358
362
sync_head_found : bool ,
359
363
store : Store ,
360
- ) -> Result < ( ) , SyncError > {
364
+ ) -> Result < Option < H256 > , SyncError > {
361
365
let mut current_chunk_idx = 0 ;
362
366
let block_hashes_chunks: Vec < Vec < BlockHash > > = block_hashes
363
367
. chunks ( MAX_BLOCK_BODIES_TO_REQUEST )
@@ -366,7 +370,7 @@ impl SyncManager {
366
370
367
371
let mut current_block_hashes_chunk = match block_hashes_chunks. get ( current_chunk_idx) {
368
372
Some ( res) => res. clone ( ) ,
369
- None => return Ok ( ( ) ) ,
373
+ None => return Ok ( None ) ,
370
374
} ;
371
375
let mut headers_iter = block_headers. iter ( ) ;
372
376
let mut blocks: Vec < Block > = vec ! [ ] ;
@@ -453,8 +457,6 @@ impl SyncManager {
453
457
return Err ( error. into ( ) ) ;
454
458
}
455
459
456
- * current_head = last_block. hash ( ) ;
457
- * search_head = last_block. hash ( ) ;
458
460
store. update_latest_block_number ( last_block. header . number ) ?;
459
461
460
462
let elapsed_secs: f64 = since. elapsed ( ) . as_millis ( ) as f64 / 1000.0 ;
@@ -474,7 +476,7 @@ impl SyncManager {
474
476
blocks_per_second
475
477
) ;
476
478
477
- Ok ( ( ) )
479
+ Ok ( Some ( last_block . hash ( ) ) )
478
480
}
479
481
480
482
fn add_blocks (
0 commit comments