Skip to content

Commit

Permalink
Updated sync reporting for QT wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Dec 26, 2024
1 parent b5b2dd3 commit 835173d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
20 changes: 18 additions & 2 deletions chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
Expand Down
32 changes: 19 additions & 13 deletions servers/src/common/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 14 additions & 3 deletions servers/src/mwc/sync/orphans_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions servers/src/mwc/sync/syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 835173d

Please sign in to comment.