Skip to content

Commit 6c037c7

Browse files
committed
fix: lint
1 parent c986f4e commit 6c037c7

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

crates/networking/p2p/sync.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,19 @@ impl SyncManager {
278278
store.add_block_headers(block_hashes.clone(), block_headers.clone())?;
279279

280280
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+
}
291294
}
292295

293296
if sync_head_found {
@@ -346,18 +349,19 @@ impl SyncManager {
346349
Ok(())
347350
}
348351

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.
351357
async fn download_and_run_blocks(
352358
&mut self,
353359
block_hashes: &[BlockHash],
354360
block_headers: &[BlockHeader],
355361
sync_head: BlockHash,
356-
current_head: &mut BlockHash,
357-
search_head: &mut BlockHash,
358362
sync_head_found: bool,
359363
store: Store,
360-
) -> Result<(), SyncError> {
364+
) -> Result<Option<H256>, SyncError> {
361365
let mut current_chunk_idx = 0;
362366
let block_hashes_chunks: Vec<Vec<BlockHash>> = block_hashes
363367
.chunks(MAX_BLOCK_BODIES_TO_REQUEST)
@@ -366,7 +370,7 @@ impl SyncManager {
366370

367371
let mut current_block_hashes_chunk = match block_hashes_chunks.get(current_chunk_idx) {
368372
Some(res) => res.clone(),
369-
None => return Ok(()),
373+
None => return Ok(None),
370374
};
371375
let mut headers_iter = block_headers.iter();
372376
let mut blocks: Vec<Block> = vec![];
@@ -453,8 +457,6 @@ impl SyncManager {
453457
return Err(error.into());
454458
}
455459

456-
*current_head = last_block.hash();
457-
*search_head = last_block.hash();
458460
store.update_latest_block_number(last_block.header.number)?;
459461

460462
let elapsed_secs: f64 = since.elapsed().as_millis() as f64 / 1000.0;
@@ -474,7 +476,7 @@ impl SyncManager {
474476
blocks_per_second
475477
);
476478

477-
Ok(())
479+
Ok(Some(last_block.hash()))
478480
}
479481

480482
fn add_blocks(

0 commit comments

Comments
 (0)