Skip to content

Commit

Permalink
nonce submission bugfix, version push, rust upgrade v.1.51
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyFFM committed May 5, 2021
1 parent 55c2411 commit 99326f2
Show file tree
Hide file tree
Showing 12 changed files with 1,133 additions and 1,085 deletions.
2,071 changes: 1,062 additions & 1,009 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scavenger"
version = "1.7.8"
version = "1.8.0"
license = "GPL-3.0"
authors = ["PoC Consortium <[email protected]>"]
description = """
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() {
let mut config = shared_config.clone();

#[cfg(target_env = "msvc")]
config.flag("/arch:AVX512F");
config.flag("/arch:AVX512");

#[cfg(not(target_env = "msvc"))]
config.flag("-mavx512f");
Expand Down
41 changes: 20 additions & 21 deletions src/com/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,24 @@ impl Client {
&self,
submission_data: &SubmissionParameters,
) -> impl Future<Item = SubmitNonceResponse, Error = FetchError> {
let empty = "".to_owned();
let secret_phrase = self
.account_id_to_secret_phrase
.get(&submission_data.account_id);
.get(&submission_data.account_id).unwrap_or(&empty);

let mut query = format!(
"requestType=submitNonce&accountId={}&nonce={}&secretPhrase={}&blockheight={}",
submission_data.account_id, submission_data.nonce, secret_phrase, submission_data.height
);

// If we don't have a secret phrase then we most likely talk to a pool or a proxy.
// Both can make use of the deadline, e.g. a proxy won't validate deadlines but still
// needs to rank the deadlines.
// The best thing is that legacy proxies use the unadjusted deadlines so...
// yay another parameter!
let deadline = if secret_phrase.is_none() {
Some(submission_data.deadline_unadjusted)
} else {
None
};

let query = SubmitNonceRequest {
request_type: &"submitNonce",
account_id: submission_data.account_id,
nonce: submission_data.nonce,
secret_phrase,
blockheight: submission_data.height,
deadline,
};
if secret_phrase == "" {
query += &format!("&deadline={}", submission_data.deadline_unadjusted);
}

// Some "Extrawurst" for the CreepMiner proxy (I think?) which needs the deadline inside
// the "X-Deadline" header.
Expand All @@ -210,10 +205,12 @@ impl Client {
submission_data.deadline.to_string().parse().unwrap(),
);

let mut uri = self.uri_for("burst");
uri.set_query(Some(&query));

self.inner
.post(self.uri_for("burst"))
.post(uri)
.headers(headers)
.query(&query)
.send()
.and_then(|mut res| {
let body = mem::replace(res.body_mut(), Decoder::empty());
Expand All @@ -232,7 +229,7 @@ mod tests {
use super::*;
use tokio;

static BASE_URL: &str = "http://94.130.178.37:31000";
static BASE_URL: &str = "https://wallet.burstcoin.ro/";

#[test]
fn test_submit_params_cmp() {
Expand Down Expand Up @@ -268,17 +265,19 @@ mod tests {
fn test_requests() {
let mut rt = tokio::runtime::Runtime::new().expect("can't create runtime");

let mut secret = HashMap::new();
secret.insert(1337u64,"secret".to_owned());
let client = Client::new(
BASE_URL.parse().unwrap(),
HashMap::new(),
secret,
5000,
12,
ProxyDetails::Enabled,
HashMap::new(),
);

let height = match rt.block_on(client.get_mining_info()) {
Err(e) => panic!(format!("can't get mining info: {:?}", e)),
Err(e) => panic!("can't get mining info: {:?}", e),
Ok(mining_info) => mining_info.height,
};

Expand All @@ -294,7 +293,7 @@ mod tests {
}));

if let Err(e) = nonce_submission_response {
assert!(false, format!("can't submit nonce: {:?}", e));
assert!(false, "can't submit nonce: {:?}", e);
}
}
}
73 changes: 35 additions & 38 deletions src/cpu_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ use crossbeam_channel::{Receiver, Sender};
use futures::sync::mpsc;
use futures::{Future, Sink};
#[cfg(any(feature = "simd", feature = "neon"))]
use libc::{c_void, uint64_t};
use libc::{c_void};
use std::u64;

cfg_if! {
if #[cfg(feature = "simd")] {
extern "C" {
pub fn find_best_deadline_avx512f(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_avx2(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_avx(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_sse2(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();
}
}
Expand All @@ -51,10 +51,10 @@ cfg_if! {
extern "C" {
pub fn find_best_deadline_neon(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();
}
}
Expand All @@ -64,7 +64,7 @@ pub fn create_cpu_worker_task(
benchmark: bool,
thread_pool: rayon::ThreadPool,
rx_read_replies: Receiver<ReadReply>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
) -> impl FnOnce() {
move || {
Expand All @@ -83,7 +83,7 @@ pub fn create_cpu_worker_task(

pub fn hash(
read_reply: ReadReply,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
benchmark: bool,
) -> impl FnOnce() {
Expand Down Expand Up @@ -230,7 +230,8 @@ pub fn hash(
mod tests {
use crate::poc_hashing::find_best_deadline_rust;
use hex;
use libc::{c_void, uint64_t};
#[cfg(any(feature = "simd", feature = "neon"))]
use libc::{c_void};
use std::u64;

cfg_if! {
Expand All @@ -242,34 +243,34 @@ mod tests {
pub fn init_shabal_sse2() -> ();
pub fn find_best_deadline_avx512f(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_avx2(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_avx(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();

pub fn find_best_deadline_sse2(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();
}
}
Expand All @@ -281,10 +282,10 @@ mod tests {
pub fn init_shabal_neon() -> ();
pub fn find_best_deadline_neon(
scoops: *mut c_void,
nonce_count: uint64_t,
nonce_count: u64,
gensig: *const c_void,
best_deadline: *mut uint64_t,
best_offset: *mut uint64_t,
best_deadline: *mut u64,
best_offset: *mut u64,
) -> ();
}
}
Expand Down Expand Up @@ -378,17 +379,13 @@ mod tests {
&mut offset,
);
assert_eq!(3084580316385335914u64, deadline);
deadline = u64::MAX;
offset = 0;
}
let mut gensig_array = [0; 32];
gensig_array.copy_from_slice(&gensig[..gensig.len()]);
let result = find_best_deadline_rust(&data, (i + 1) as u64, &gensig_array);
deadline = result.0;
offset = result.1;
assert_eq!(3084580316385335914u64, deadline);
deadline = u64::MAX;
offset = 0;
}
data[i * 64..i * 64 + 64].clone_from_slice(&loser);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpu_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::u64;
pub fn create_gpu_worker_task(
benchmark: bool,
rx_read_replies: Receiver<ReadReply>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
context_mu: Arc<GpuContext>,
) -> impl FnOnce() {
Expand Down
2 changes: 1 addition & 1 deletion src/gpu_worker_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::u64;
pub fn create_gpu_worker_task_async(
benchmark: bool,
rx_read_replies: Receiver<ReadReply>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
context_mu: Arc<GpuContext>,
num_drives: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Miner {
for _ in 0..cpu_buffer_count {
let cpu_buffer = CpuBuffer::new(buffer_size_cpu);
tx_empty_buffers
.send(Box::new(cpu_buffer) as Box<Buffer + Send>)
.send(Box::new(cpu_buffer) as Box<dyn Buffer + Send>)
.unwrap();
}

Expand All @@ -368,7 +368,7 @@ impl Miner {
{
let gpu_buffer = GpuBuffer::new(&context.clone(), i + 1);
tx_empty_buffers
.send(Box::new(gpu_buffer) as Box<Buffer + Send>)
.send(Box::new(gpu_buffer) as Box<dyn Buffer + Send>)
.unwrap();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cfg_if! {
}

impl Plot {
pub fn new(path: &PathBuf, mut use_direct_io: bool, dummy: bool) -> Result<Plot, Box<Error>> {
pub fn new(path: &PathBuf, mut use_direct_io: bool, dummy: bool) -> Result<Plot, Box<dyn Error>> {
if !path.is_file() {
return Err(From::from(format!(
"{} is not a file",
Expand Down
14 changes: 7 additions & 7 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct BufferInfo {
pub gpu_signal: u64,
}
pub struct ReadReply {
pub buffer: Box<Buffer + Send>,
pub buffer: Box<dyn Buffer + Send>,
pub info: BufferInfo,
}

Expand All @@ -33,8 +33,8 @@ pub struct Reader {
drive_id_to_plots: HashMap<String, Arc<Vec<Mutex<Plot>>>>,
pub total_size: u64,
pool: rayon::ThreadPool,
rx_empty_buffers: Receiver<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
rx_empty_buffers: Receiver<Box<dyn Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_read_replies_cpu: Sender<ReadReply>,
tx_read_replies_gpu: Option<Vec<Sender<ReadReply>>>,
interupts: Vec<Sender<()>>,
Expand All @@ -47,8 +47,8 @@ impl Reader {
drive_id_to_plots: HashMap<String, Arc<Vec<Mutex<Plot>>>>,
total_size: u64,
num_threads: usize,
rx_empty_buffers: Receiver<Box<Buffer + Send>>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
rx_empty_buffers: Receiver<Box<dyn Buffer + Send>>,
tx_empty_buffers: Sender<Box<dyn Buffer + Send>>,
tx_read_replies_cpu: Sender<ReadReply>,
tx_read_replies_gpu: Option<Vec<Sender<ReadReply>>>,
show_progress: bool,
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Reader {
for i in 0..self.tx_read_replies_gpu.as_ref().unwrap().len() {
self.tx_read_replies_gpu.as_ref().unwrap()[i]
.send(ReadReply {
buffer: Box::new(CpuBuffer::new(0)) as Box<Buffer + Send>,
buffer: Box::new(CpuBuffer::new(0)) as Box<dyn Buffer + Send>,
info: BufferInfo {
len: 1,
height,
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Reader {
for i in 0..tx_read_replies_gpu.as_ref().unwrap().len() {
tx_read_replies_gpu.as_ref().unwrap()[i]
.send(ReadReply {
buffer: Box::new(CpuBuffer::new(0)) as Box<Buffer + Send>,
buffer: Box::new(CpuBuffer::new(0)) as Box<dyn Buffer + Send>,
info: BufferInfo {
len: 1,
height,
Expand Down
3 changes: 1 addition & 2 deletions src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use futures::future::Future;
use futures::stream::Stream;
use futures::sync::mpsc;
use std::collections::HashMap;
use std::error::Error;
use std::time::Duration;
use std::u64;
use tokio;
Expand Down Expand Up @@ -118,7 +117,7 @@ impl RequestHandler {
submission_params.account_id,
submission_params.nonce,
submission_params.deadline,
x.description(),
&x.to_string(),
);
let res = tx_submit_data.unbounded_send(submission_params);
if let Err(e) = res {
Expand Down
Loading

0 comments on commit 99326f2

Please sign in to comment.