Skip to content

Commit

Permalink
Update Sync start for body. Test for sysinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Dec 1, 2024
1 parent db7a1e2 commit d2278b5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
81 changes: 79 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lazy_static = "1"
tokio = {version = "0.2", features = ["full"] }
num_cpus = "1"
crossbeam = "0.8"
sysinfo = "0.32"

mwc_core = { path = "../core", version = "5.3.6" }
mwc_keychain = { path = "../keychain", version = "5.3.6" }
Expand Down
28 changes: 28 additions & 0 deletions chain/src/pibd_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,31 @@ pub const BLOCKS_REQUEST_PER_PEER: usize = 30;

/// Maxumum number of blocks that can await into the DB as orphans
pub const BLOCKS_REQUEST_LIMIT: usize = 500;

#[cfg(test)]
mod tests {
use sysinfo::{
Components, CpuRefreshKind, Disks, MemoryRefreshKind, Networks, RefreshKind, System,
};

#[test]
fn check_sys_info() {
// Please note that we use "new_all" to ensure that all lists of
// CPUs and processes are filled!
let sys = System::new_with_specifics(
RefreshKind::new().with_memory(MemoryRefreshKind::everything()),
);

println!("=> system:");
// RAM and swap information:
println!("total memory: {} bytes", sys.total_memory());
println!("used memory : {} bytes", sys.used_memory());
println!("available memory : {} bytes", sys.available_memory());
println!("total swap : {} bytes", sys.total_swap());
println!("used swap : {} bytes", sys.used_swap());
println!("free swap : {} bytes", sys.free_swap());

let num_cores = num_cpus::get();
println!("CPU Cores : {} cores", num_cores);
}
}
3 changes: 2 additions & 1 deletion servers/src/mwc/sync/body_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl BodySync {
let head = self.chain.head()?;
let header_head = self.chain.header_head()?;

if head.last_block_h == header_head.last_block_h {
// Last few blocks no need to sync, new mined blocks will be synced regular way
if head.height > header_head.height.saturating_sub(3) {
// sync is done, we are ready.
return Ok(SyncRequestResponses::BodyReady);
}
Expand Down

0 comments on commit d2278b5

Please sign in to comment.