From 2947cb7ac695e5602eeee110799d889c1dd4d217 Mon Sep 17 00:00:00 2001 From: Joel Liu <83172559+csdtowards@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:24:50 +0800 Subject: [PATCH] Optimizing recover perf by reducing sync progress events (#244) * Optimizing recover perf by reducing sync progress events * add log * add log --- .../src/sync_manager/log_entry_fetcher.rs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/node/log_entry_sync/src/sync_manager/log_entry_fetcher.rs b/node/log_entry_sync/src/sync_manager/log_entry_fetcher.rs index 2b4b0f8..29f8287 100644 --- a/node/log_entry_sync/src/sync_manager/log_entry_fetcher.rs +++ b/node/log_entry_sync/src/sync_manager/log_entry_fetcher.rs @@ -236,22 +236,29 @@ impl LogEntryFetcher { .filter; let mut stream = LogQuery::new(&provider, &filter, log_query_delay) .with_page_size(log_page_size); - debug!( + info!( "start_recover starts, start={} end={}", start_block_number, end_block_number ); + let (mut block_hash_sent, mut block_number_sent) = (None, None); while let Some(maybe_log) = stream.next().await { match maybe_log { Ok(log) => { let sync_progress = if log.block_hash.is_some() && log.block_number.is_some() { - let synced_block = LogFetchProgress::SyncedBlock(( - log.block_number.unwrap().as_u64(), - log.block_hash.unwrap(), - None, - )); - progress = log.block_number.unwrap().as_u64(); - Some(synced_block) + if block_hash_sent != log.block_hash + || block_number_sent != log.block_number + { + let synced_block = LogFetchProgress::SyncedBlock(( + log.block_number.unwrap().as_u64(), + log.block_hash.unwrap(), + None, + )); + progress = log.block_number.unwrap().as_u64(); + Some(synced_block) + } else { + None + } } else { None }; @@ -268,7 +275,12 @@ impl LogEntryFetcher { log.block_number.expect("block number exist").as_u64(), )) .and_then(|_| match sync_progress { - Some(b) => recover_tx.send(b), + Some(b) => { + recover_tx.send(b)?; + block_hash_sent = log.block_hash; + block_number_sent = log.block_number; + Ok(()) + } None => Ok(()), }) { @@ -290,6 +302,8 @@ impl LogEntryFetcher { } } } + + info!("log recover end"); }, "log recover", );