From 835173d31243a449ecb2956fe61af483084b3040 Mon Sep 17 00:00:00 2001 From: bayk Date: Thu, 26 Dec 2024 14:59:04 -0800 Subject: [PATCH] Updated sync reporting for QT wallet --- chain/src/types.rs | 20 +++++++++++++++-- servers/src/common/adapters.rs | 32 +++++++++++++++++----------- servers/src/mwc/sync/orphans_sync.rs | 17 ++++++++++++--- servers/src/mwc/sync/syncer.rs | 6 +----- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/chain/src/types.rs b/chain/src/types.rs index 41dd92004..f204dbeea 100644 --- a/chain/src/types.rs +++ b/chain/src/types.rs @@ -179,6 +179,22 @@ impl SyncState { } } + /// Check if headers download process is done. In this case it make sense to request more top headers + pub fn are_headers_done(&self) -> bool { + match *self.current.read() { + SyncStatus::Initial => false, + SyncStatus::HeaderHashSync { + completed_blocks: _, + total_blocks: _, + } => false, + SyncStatus::HeaderSync { + current_height: _, + archive_height: _, + } => false, + _ => true, + } + } + /// Current syncing status pub fn status(&self) -> SyncStatus { *self.current.read() @@ -198,8 +214,8 @@ impl SyncState { if *status == new_status { return false; } - - debug!("sync_state: sync_status: {:?} -> {:?}", *status, new_status,); + // Sync status is needed for QT wallet sync tracking. Please keep this message as info + info!("mwc-node sync status: {:?}", new_status); *status = new_status; true } diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index 010ac0467..976bfbdc2 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -382,19 +382,25 @@ where if e.is_bad_data() { return Ok(false); } else { - // we got an error when trying to process the block header - // but nothing serious enough to need to ban the peer upstream - // Probably child block doesn't exist, let's request them - if let Some(peer) = self.peers().get_connected_peer(&peer_info.addr) { - let head = chain.head()?; - debug!( - "Got unknown header, requesting headers from the peer {} at height {}", - peer_info.addr, head.height - ); - let heights = get_locator_heights(head.height); - let locator = chain.get_locator_hashes(head, &heights)?; - let _ = peer.send_header_request(locator); - let _ = peer.send_block_request(bh.hash(), chain::Options::NONE); + if self.sync_state.are_headers_done() { + // we got an error when trying to process the block header + // but nothing serious enough to need to ban the peer upstream + // Probably child block doesn't exist, let's request them + if let Some(peer) = self.peers().get_connected_peer(&peer_info.addr) { + let head = chain.head()?; + debug!("Got unknown header, requesting headers from the peer {} at height {}",peer_info.addr, head.height); + let heights = get_locator_heights(head.height); + let locator = chain.get_locator_hashes(head, &heights)?; + let _ = peer.send_header_request(locator); + + if let Ok(tip) = chain.head() { + // Requesting of orphans buffer is large enough to finish the job with request + if bh.height.saturating_sub(tip.height) < chain.get_pibd_params().get_orphans_num_limit() as u64 { + let _ = peer.send_block_request(bh.hash(), chain::Options::NONE); + }` + } + + } } return Err(e); } diff --git a/servers/src/mwc/sync/orphans_sync.rs b/servers/src/mwc/sync/orphans_sync.rs index 448d0db44..e37e86ec1 100644 --- a/servers/src/mwc/sync/orphans_sync.rs +++ b/servers/src/mwc/sync/orphans_sync.rs @@ -48,7 +48,7 @@ impl OrphansSync { /// Process and keep a new block if it was rejected by the chain. Return true if prev block is needed pub fn recieve_block_reporting(&self, block: Block) -> bool { let bhash = block.hash(); - let need_prev_block = self.need_prev_block(&block.header.prev_hash); + let need_prev_block = self.need_prev_block(&block.header.prev_hash, block.header.height); if self.unknown_blocks.read().contains_key(&bhash) { return need_prev_block; } @@ -143,7 +143,7 @@ impl OrphansSync { }; if let Some((prev_block_hash, bl_height)) = block_hash_height { - if self.need_prev_block(&prev_block_hash) { + if self.need_prev_block(&prev_block_hash, bl_height) { // We need to request the child for that block let mut orphans_requests = self.orphans_requests.write(); if self.send_hash_requests( @@ -214,7 +214,18 @@ impl OrphansSync { resuqest_was_sent } - fn need_prev_block(&self, prev_block_hash: &Hash) -> bool { + fn need_prev_block(&self, prev_block_hash: &Hash, height: u64) -> bool { + match self.chain.head() { + Ok(tip) => { + if height.saturating_sub(tip.height) + >= self.pibd_params.get_orphans_num_limit() as u64 + { + return false; + } + } + Err(_) => return false, + } + if self.unknown_blocks.read().contains_key(prev_block_hash) { return false; } diff --git a/servers/src/mwc/sync/syncer.rs b/servers/src/mwc/sync/syncer.rs index d4452c55a..1bf99f4c5 100644 --- a/servers/src/mwc/sync/syncer.rs +++ b/servers/src/mwc/sync/syncer.rs @@ -146,11 +146,7 @@ impl SyncRunner { // run each sync stage, each of them deciding whether they're needed // except for state sync that only runs if body sync return true (means txhashset is needed) let sync_reponse = self.sync_manager.request(&self.peers); - if sync_reponse.response == SyncRequestResponses::SyncDone { - debug!("sync_manager responsed with {:?}", sync_reponse); - } else { - info!("sync_manager responsed with {:?}", sync_reponse); - } + debug!("sync_manager responsed with {:?}", sync_reponse); let prev_state = self.sync_state.status(); sleep_time = 1000;