Shuffle server at same heights

This commit is contained in:
Hanh 2022-08-22 14:36:29 +08:00
parent de506ba074
commit c51cb51818
4 changed files with 11 additions and 8 deletions

View File

@ -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::SeqCst)
DOWNLOADED_BYTES.load(Ordering::Acquire)
}
#[no_mangle]
pub unsafe extern "C" fn get_trial_decryptions_count() -> usize {
TRIAL_DECRYPTIONS.load(Ordering::SeqCst)
TRIAL_DECRYPTIONS.load(Ordering::Acquire)
}
#[no_mangle]

View File

@ -7,6 +7,8 @@ use crate::{advance_tree, has_cuda};
use ff::PrimeField;
use futures::{future, FutureExt};
use log::info;
use rand::prelude::SliceRandom;
use rand::rngs::OsRng;
use rayon::prelude::*;
use std::collections::HashMap;
use std::convert::TryInto;
@ -166,15 +168,15 @@ pub async fn download_chain(
hash: vec![],
}),
};
DOWNLOADED_BYTES.store(0, Ordering::SeqCst);
TRIAL_DECRYPTIONS.store(0, Ordering::SeqCst);
DOWNLOADED_BYTES.store(0, Ordering::Release);
TRIAL_DECRYPTIONS.store(0, Ordering::Release);
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::SeqCst);
DOWNLOADED_BYTES.fetch_add(block_size, Ordering::Release);
if cancel.load(Ordering::Acquire) {
log::info!("Canceling download");
break;
@ -606,7 +608,8 @@ pub async fn get_best_server(servers: &[String]) -> Option<String> {
tokio::spawn(timeout(Duration::from_secs(1), get_height(s.to_string()))).boxed();
server_heights.push(server_height);
}
let server_heights = future::try_join_all(server_heights).await.ok()?;
let mut server_heights = future::try_join_all(server_heights).await.ok()?;
server_heights.shuffle(&mut OsRng);
server_heights
.into_iter()

View File

@ -125,7 +125,7 @@ fn collect_decrypted_notes(
for (output_index, co) in tx.outputs.iter().enumerate() {
let plaintext = &output_buffer[i * buffer_stride + 64..i * buffer_stride + 116];
// version and amount must be in range - 21 million ZEC is less than 0x0008 0000 0000 0000
if plaintext[0] <= 2 || plaintext[18] <= 0x07 || plaintext[19] != 0 {
if plaintext[0] <= 2 && plaintext[18] < 0x08 && plaintext[19] == 0 {
if let Some((note, pa)) =
domain.parse_note_plaintext_without_memo_ivk(&ivk, plaintext)
{

View File

@ -140,7 +140,7 @@ pub async fn sync_async(
.iter()
.map(|db| db.count_outputs as usize)
.sum::<usize>();
TRIAL_DECRYPTIONS.fetch_add(n_ivks * outputs, AtomicOrdering::SeqCst);
TRIAL_DECRYPTIONS.fetch_add(n_ivks * outputs, AtomicOrdering::Release);
for b in dec_blocks.iter() {
let mut my_nfs: Vec<Nf> = vec![];
for nf in b.spends.iter() {