Bug fix: Perf counters

This commit is contained in:
Hanh 2022-08-30 22:00:15 +08:00
parent 1336839255
commit deb75ba3c7
6 changed files with 39 additions and 24 deletions

View File

@ -191,13 +191,13 @@ pub unsafe extern "C" fn import_transparent_secret_key(
lazy_static! {
static ref SYNC_LOCK: Semaphore = Semaphore::new(1);
static ref SYNC_CANCELED: AtomicBool = AtomicBool::new(false);
static ref SYNC_CANCELED: Mutex<bool> = Mutex::new(false);
}
#[no_mangle]
pub unsafe extern "C" fn cancel_warp() {
log::info!("Sync canceled");
SYNC_CANCELED.store(true, Ordering::Release);
*SYNC_CANCELED.lock().unwrap() = true;
}
#[tokio::main]
@ -248,7 +248,7 @@ pub async unsafe extern "C" fn warp(
}
};
let r = res.await;
SYNC_CANCELED.store(false, Ordering::Release);
*SYNC_CANCELED.lock().unwrap() = false;
log_result(r)
}
@ -647,12 +647,12 @@ pub unsafe extern "C" fn derive_zip32(
#[no_mangle]
pub unsafe extern "C" fn get_downloaded_size() -> usize {
DOWNLOADED_BYTES.load(Ordering::Acquire)
*DOWNLOADED_BYTES.lock().unwrap()
}
#[no_mangle]
pub unsafe extern "C" fn get_trial_decryptions_count() -> usize {
TRIAL_DECRYPTIONS.load(Ordering::Acquire)
*TRIAL_DECRYPTIONS.lock().unwrap()
}
#[no_mangle]

View File

@ -3,7 +3,6 @@
use crate::coinconfig::CoinConfig;
use crate::scan::AMProgressCallback;
use crate::{BlockId, CTree, CompactTxStreamerClient, DbAdapter};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tokio::sync::Mutex;
use tonic::transport::Channel;
@ -17,7 +16,7 @@ pub async fn coin_sync(
anchor_offset: u32,
max_cost: u32,
progress_callback: impl Fn(u32) + Send + 'static,
cancel: &'static AtomicBool,
cancel: &'static std::sync::Mutex<bool>,
) -> anyhow::Result<()> {
let cb = Arc::new(Mutex::new(progress_callback));
coin_sync_impl(
@ -50,7 +49,7 @@ async fn coin_sync_impl(
target_height_offset: u32,
max_cost: u32,
progress_callback: AMProgressCallback,
cancel: &'static AtomicBool,
cancel: &'static std::sync::Mutex<bool>,
) -> anyhow::Result<()> {
let c = CoinConfig::get(coin);
crate::scan::sync_async(

View File

@ -6,6 +6,7 @@ use crate::scan::Blocks;
use crate::{advance_tree, has_cuda};
use ff::PrimeField;
use futures::{future, FutureExt};
use lazy_static::lazy_static;
use log::info;
use rand::prelude::SliceRandom;
use rand::rngs::OsRng;
@ -14,7 +15,7 @@ use std::collections::HashMap;
use std::convert::TryInto;
use std::marker::PhantomData;
use std::path::Path;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::Mutex;
use std::time::Duration;
use std::time::Instant;
use sysinfo::{System, SystemExt};
@ -38,8 +39,10 @@ use crate::gpu::cuda::{CudaProcessor, CUDA_CONTEXT};
use crate::gpu::metal::MetalProcessor;
use crate::gpu::{trial_decrypt, USE_GPU};
pub static DOWNLOADED_BYTES: AtomicUsize = AtomicUsize::new(0);
pub static TRIAL_DECRYPTIONS: AtomicUsize = AtomicUsize::new(0);
lazy_static! {
pub static ref DOWNLOADED_BYTES: Mutex<usize> = Mutex::new(0);
pub static ref TRIAL_DECRYPTIONS: Mutex<usize> = Mutex::new(0);
}
pub async fn get_latest_height(
client: &mut CompactTxStreamerClient<Channel>,
@ -150,7 +153,7 @@ pub async fn download_chain(
end_height: u32,
mut prev_hash: Option<[u8; 32]>,
blocks_tx: Sender<Blocks>,
cancel: &'static AtomicBool,
cancel: &'static Mutex<bool>,
) -> anyhow::Result<()> {
let outputs_per_chunk = get_available_memory()? / get_mem_per_output();
let outputs_per_chunk = outputs_per_chunk.min(MAX_OUTPUTS_PER_CHUNKS);
@ -168,16 +171,20 @@ pub async fn download_chain(
hash: vec![],
}),
};
DOWNLOADED_BYTES.store(0, Ordering::Release);
TRIAL_DECRYPTIONS.store(0, Ordering::Release);
*DOWNLOADED_BYTES.lock().unwrap() = 0;
*TRIAL_DECRYPTIONS.lock().unwrap() = 0;
let mut block_stream = client
.get_block_range(Request::new(range))
.await?
.into_inner();
while let Some(mut block) = block_stream.message().await? {
let block_size = get_block_size(&block);
DOWNLOADED_BYTES.fetch_add(block_size, Ordering::Release);
if cancel.load(Ordering::Acquire) {
{
let mut downloaded = DOWNLOADED_BYTES.lock().unwrap();
*downloaded += block_size;
}
let c = *cancel.lock().unwrap();
if c {
log::info!("Canceling download");
break;
}
@ -194,6 +201,14 @@ pub async fn download_chain(
prev_hash = Some(ph);
for b in block.vtx.iter_mut() {
b.actions.clear(); // don't need Orchard actions
for co in b.outputs.iter_mut() {
if co.epk.is_empty() {
co.epk = vec![0; 32];
}
if co.ciphertext.is_empty() {
co.ciphertext = vec![0; 52];
}
}
}
let block_output_count: usize = block.vtx.iter().map(|tx| tx.outputs.len()).sum();
@ -419,7 +434,7 @@ impl DecryptNode {
network: &Network,
blocks: Vec<CompactBlock>,
) -> Vec<DecryptedBlock> {
let use_gpu = USE_GPU.load(Ordering::Acquire);
let use_gpu = { *USE_GPU.lock().unwrap() };
log::info!("use gpu = {}", use_gpu);
if use_gpu {
#[cfg(feature = "cuda")]

View File

@ -3,7 +3,7 @@ use crate::db::AccountViewKey;
use crate::CompactBlock;
use anyhow::Result;
use lazy_static::lazy_static;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
use zcash_note_encryption::Domain;
use zcash_primitives::consensus::{BlockHeight, Network};
use zcash_primitives::sapling::note_encryption::SaplingDomain;
@ -11,7 +11,7 @@ use zcash_primitives::sapling::SaplingIvk;
use zcash_primitives::zip32::ExtendedFullViewingKey;
lazy_static! {
pub static ref USE_GPU: AtomicBool = AtomicBool::new(true);
pub static ref USE_GPU: Mutex<bool> = Mutex::new(true);
}
#[cfg(feature = "cuda")]
@ -34,7 +34,7 @@ pub fn has_gpu() -> bool {
}
pub fn use_gpu(v: bool) {
USE_GPU.store(v, Ordering::Release);
*USE_GPU.lock().unwrap() = v;
}
#[cfg(feature = "cuda")]

View File

@ -3,7 +3,6 @@
#[path = "generated/cash.z.wallet.sdk.rpc.rs"]
pub mod lw_rpc;
use std::sync::atomic::Ordering;
pub use zcash_params::coin::{get_branch, get_coin_type, CoinType};
// Mainnet

View File

@ -12,7 +12,6 @@ use ff::PrimeField;
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::panic;
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use std::sync::Arc;
use std::time::Instant;
use tokio::runtime::{Builder, Runtime};
@ -55,7 +54,7 @@ pub async fn sync_async(
target_height_offset: u32,
max_cost: u32,
progress_callback: AMProgressCallback,
cancel: &'static AtomicBool,
cancel: &'static std::sync::Mutex<bool>,
ld_url: &str,
) -> anyhow::Result<()> {
let ld_url = ld_url.to_owned();
@ -140,7 +139,10 @@ pub async fn sync_async(
.iter()
.map(|db| db.count_outputs as usize)
.sum::<usize>();
TRIAL_DECRYPTIONS.fetch_add(n_ivks * outputs, AtomicOrdering::Release);
{
let mut dc = TRIAL_DECRYPTIONS.lock().unwrap();
*dc += n_ivks * outputs;
}
for b in dec_blocks.iter() {
let mut my_nfs: Vec<Nf> = vec![];
for nf in b.spends.iter() {