Skip to content

Commit

Permalink
made bolds code look nicer.... NOT.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyFFM committed May 13, 2019
1 parent 209dabc commit 84a6a87
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 189 deletions.
342 changes: 175 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/com/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct SubmissionParameters {
pub account_id: u64,
pub nonce: u64,
pub height: u64,
pub block: u64,
pub deadline_unadjusted: u64,
pub deadline: u64,
pub gen_sig: [u8; 32],
Expand All @@ -38,9 +39,9 @@ pub struct SubmissionParameters {
/// parameters the old ones need to be replaced.
impl Ord for SubmissionParameters {
fn cmp(&self, other: &Self) -> Ordering {
if self.height < other.height {
if self.block < other.block {
Ordering::Less
} else if self.height > other.height {
} else if self.block > other.block {
Ordering::Greater
} else if self.gen_sig == other.gen_sig {
// on the same chain, best deadline wins
Expand Down Expand Up @@ -228,6 +229,7 @@ mod tests {
account_id: 1337,
nonce: 12,
height: 112,
block: 0,
deadline_unadjusted: 7123,
deadline: 1193,
gen_sig: [0; 32],
Expand Down Expand Up @@ -274,6 +276,7 @@ mod tests {
account_id: 1337,
nonce: 12,
height,
block: 0,
deadline_unadjusted: 7123,
deadline: 1193,
gen_sig: [0; 32],
Expand Down
15 changes: 8 additions & 7 deletions src/cpu_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub fn hash(
.clone()
.send(NonceData {
height: read_reply.info.height,
block: read_reply.info.block,
base_target: read_reply.info.base_target,
deadline,
nonce: 0,
Expand Down Expand Up @@ -210,6 +211,7 @@ pub fn hash(
.clone()
.send(NonceData {
height: read_reply.info.height,
block: read_reply.info.block,
base_target: read_reply.info.base_target,
deadline,
nonce: offset + read_reply.info.start_nonce,
Expand All @@ -228,6 +230,7 @@ pub fn hash(
mod tests {
use crate::poc_hashing::find_best_deadline_rust;
use hex;
use libc::{c_void, uint64_t};
use std::u64;

cfg_if! {
Expand Down Expand Up @@ -378,13 +381,11 @@ mod tests {
deadline = u64::MAX;
offset = 0;
}
find_best_deadline_sph(
data.as_ptr() as *mut c_void,
(i + 1) as u64,
gensig.as_ptr() as *const c_void,
&mut deadline,
&mut offset,
);
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;
Expand Down
8 changes: 4 additions & 4 deletions src/future/prio_retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ where
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
loop {
match self.stream.poll() {
Ok(Async::NotReady) => { break; }
Ok(Async::NotReady) => {
break;
}
Ok(Async::Ready(Some(new_item))) => {
// check if we currently have a delay item
if let Some(ref mut delayed_item) = self.delayed_item {
Expand Down Expand Up @@ -144,9 +146,7 @@ mod tests {
let len = items.len();
let items = Interval::new(Instant::now(), Duration::from_millis(200))
.take(len as u64)
.map(move |_| {
items.next().unwrap()
})
.map(move |_| items.next().unwrap())
.map_err(|e| error!("can't consume interval: {:?}", e));
let exp: Vec<i64> = vec![0, 1, 2, 3, 3, 3, 6, 7];
let stream = PrioRetry::new(items, Duration::from_millis(100));
Expand Down
2 changes: 2 additions & 0 deletions src/gpu_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn create_gpu_worker_task(
.clone()
.send(NonceData {
height: read_reply.info.height,
block: read_reply.info.block,
base_target: read_reply.info.base_target,
deadline,
nonce: 0,
Expand Down Expand Up @@ -64,6 +65,7 @@ pub fn create_gpu_worker_task(
.clone()
.send(NonceData {
height: read_reply.info.height,
block: read_reply.info.block,
base_target: read_reply.info.base_target,
deadline,
nonce: offset + read_reply.info.start_nonce,
Expand Down
4 changes: 4 additions & 0 deletions src/gpu_worker_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn create_gpu_worker_task_async(
let mut last_buffer_info_a = BufferInfo {
len: 0,
height: 0,
block: 0,
base_target: 0,
gensig: Arc::new([0u8; 32]),
start_nonce: 0,
Expand All @@ -43,6 +44,7 @@ pub fn create_gpu_worker_task_async(
.clone()
.send(NonceData {
height: read_reply.info.height,
block: read_reply.info.block,
base_target: read_reply.info.base_target,
deadline,
nonce: 0,
Expand Down Expand Up @@ -89,6 +91,7 @@ pub fn create_gpu_worker_task_async(
.clone()
.send(NonceData {
height: last_buffer_info_a.height,
block: last_buffer_info_a.block,
base_target: last_buffer_info_a.base_target,
deadline,
nonce: offset + last_buffer_info_a.start_nonce,
Expand Down Expand Up @@ -129,6 +132,7 @@ pub fn create_gpu_worker_task_async(
.clone()
.send(NonceData {
height: last_buffer_info_a.height,
block: last_buffer_info_a.block,
base_target: last_buffer_info_a.base_target,
deadline,
nonce: offset + last_buffer_info_a.start_nonce,
Expand Down
6 changes: 6 additions & 0 deletions src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct State {
generation_signature: String,
generation_signature_bytes: [u8; 32],
height: u64,
block: u64,
account_id_to_best_deadline: HashMap<u64, u64>,
server_target_deadline: u64,
base_target: u64,
Expand All @@ -66,6 +67,7 @@ impl State {
Self {
generation_signature: "".to_owned(),
height: 0,
block: 0,
scoop: 0,
account_id_to_best_deadline: HashMap::new(),
server_target_deadline: u64::MAX,
Expand All @@ -84,6 +86,7 @@ impl State {
*best_deadlines = u64::MAX;
}
self.height = mining_info.height;
self.block += 1;
self.base_target = mining_info.base_target;
self.server_target_deadline = mining_info.target_deadline;

Expand All @@ -107,6 +110,7 @@ impl State {

pub struct NonceData {
pub height: u64,
pub block: u64,
pub base_target: u64,
pub deadline: u64,
pub nonce: u64,
Expand Down Expand Up @@ -479,6 +483,7 @@ impl Miner {

reader.lock().unwrap().start_reading(
mining_info.height,
state.block,
mining_info.base_target,
state.scoop,
&Arc::new(state.generation_signature_bytes),
Expand Down Expand Up @@ -550,6 +555,7 @@ impl Miner {
nonce_data.account_id,
nonce_data.nonce,
nonce_data.height,
nonce_data.block,
nonce_data.deadline,
deadline,
state.generation_signature_bytes,
Expand Down
9 changes: 9 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use stopwatch::Stopwatch;
pub struct BufferInfo {
pub len: usize,
pub height: u64,
pub block: u64,
pub base_target: u64,
pub gensig: Arc<[u8; 32]>,
pub start_nonce: u64,
Expand Down Expand Up @@ -76,6 +77,7 @@ impl Reader {
pub fn start_reading(
&mut self,
height: u64,
block: u64,
base_target: u64,
scoop: u32,
gensig: &Arc<[u8; 32]>,
Expand All @@ -99,6 +101,7 @@ impl Reader {
info: BufferInfo {
len: 1,
height,
block,
base_target,
gensig: gensig.clone(),
start_nonce: 0,
Expand All @@ -120,6 +123,7 @@ impl Reader {
drive.clone(),
plots.clone(),
height,
block,
base_target,
scoop,
gensig.clone(),
Expand All @@ -131,6 +135,7 @@ impl Reader {
drive.clone(),
plots.clone(),
height,
block,
base_target,
scoop,
gensig.clone(),
Expand Down Expand Up @@ -166,6 +171,7 @@ impl Reader {
drive: String,
plots: Arc<Vec<Mutex<Plot>>>,
height: u64,
block: u64,
base_target: u64,
scoop: u32,
gensig: Arc<[u8; 32]>,
Expand Down Expand Up @@ -228,6 +234,7 @@ impl Reader {
info: BufferInfo {
len: bytes_read,
height,
block,
base_target,
gensig: gensig.clone(),
start_nonce,
Expand All @@ -245,6 +252,7 @@ impl Reader {
info: BufferInfo {
len: bytes_read,
height,
block,
base_target,
gensig: gensig.clone(),
start_nonce,
Expand Down Expand Up @@ -297,6 +305,7 @@ impl Reader {
info: BufferInfo {
len: 1,
height,
block,
base_target,
gensig: gensig.clone(),
start_nonce: 0,
Expand Down
12 changes: 3 additions & 9 deletions src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl RequestHandler {
account_id: u64,
nonce: u64,
height: u64,
block: u64,
deadline_unadjusted: u64,
deadline: u64,
gen_sig: [u8; 32],
Expand All @@ -144,6 +145,7 @@ impl RequestHandler {
account_id,
nonce,
height,
block,
deadline_unadjusted,
deadline,
gen_sig,
Expand Down Expand Up @@ -231,16 +233,8 @@ mod tests {
rt.executor(),
);

request_handler.submit_nonce(
1337,
12,
111,
7123,
1193,
[0; 32],
);
request_handler.submit_nonce(1337, 12, 111, 0, 7123, 1193, [0; 32]);

rt.shutdown_on_idle();
}
}

0 comments on commit 84a6a87

Please sign in to comment.