Skip to content

Commit

Permalink
Refactor notification_root usage in ibd/flow.rs
Browse files Browse the repository at this point in the history
This commit removes a redundant `take().unwrap()` of the `notification_root` field and the subsequent reassignment of it. Now the field is directly accessed via `as_ref().unwrap()`. This change removes unnecessary operations, and might slightly improve performance.
  • Loading branch information
biryukovmaxim committed Aug 24, 2023
1 parent 78b26eb commit b0b48ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions protocol/flows/src/v5/ibd/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,14 @@ impl IbdFlow {
relay_block: &Block,
) -> Result<(), ProtocolError> {
let highest_shared_header_score = consensus.async_get_header(highest_known_syncer_chain_hash).await?.daa_score;
let notification_root = self.notification_root.take().unwrap();
let mut progress_reporter = ProgressReporter::new(
highest_shared_header_score,
relay_block.header.daa_score,
"block headers",
Some(|headers: usize, progress: i32| {
notification_root
self.notification_root
.as_ref()
.unwrap()
.notify(Notification::SyncStateChanged(SyncStateChangedNotification::new_headers(headers as u64, progress as i64)))
.expect("expecting an open unbounded channel")
}),
Expand Down Expand Up @@ -363,7 +364,6 @@ impl IbdFlow {
let prev_chunk_len = prev_jobs.len();
try_join_all(prev_jobs).await?;
progress_reporter.report_completion(prev_chunk_len);
self.notification_root = Some(notification_root);
}

self.sync_missing_relay_past_headers(consensus, syncer_virtual_selected_parent, relay_block.hash()).await?;
Expand Down

0 comments on commit b0b48ce

Please sign in to comment.