Skip to content

Commit

Permalink
edition fixes: tests/win/ocl, error messages improved: outage/retries…
Browse files Browse the repository at this point in the history
…, server target dl enforcement, allow slash at url end, additional header support
  • Loading branch information
JohnnyFFM committed Jan 31, 2019
1 parent 7ad797f commit 65a6d80
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 81 deletions.
9 changes: 6 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ plot_dirs:
# - '/first/linux/plot/dir'
# - '/second/linux/plot/dir'

url: 'http://dummypool.megash.it' # dummypool with constant scoop number for benchmarking
url: 'http://50-50-pool.burst.cryptoguru.org:8124' # cryptoguru 50-50 pool
#url: 'http://dummypool.megash.it' # dummypool with constant scoop number for benchmarking

hdd_reader_thread_count: 0 # default 0 (=auto: number of disks)
hdd_use_direct_io: true # default true
Expand All @@ -27,14 +28,16 @@ gpu_nonces_per_cache: 262144 # default 262144
gpu_mem_mapping: false # default false
gpu_async: false # default false

target_deadline: 31536000 # default u32::MAX
target_deadline: 18446744073709551615 # default u32::MAX
account_id_to_target_deadline: # target dls for multi-id (optional)
10282355196851764065: 600000
10282355196851764065: 18446744073709551615
1796535821016683299: 55555555

get_mining_info_interval: 3000 # default 3000ms
timeout: 5000 # default 5000ms
send_proxy_details: true # default false
#additional_headers: # add/overwrite html header
# "AccountKey" : "1234567890"

console_log_level: 'info' # default Info, options (off, error, warn, info, debug, trace)
logfile_log_level: 'warn' # default Warn, options (off, error, warn, info, debug, trace)
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ pub struct Cfg {
#[serde(default = "default_send_proxy_details")]
pub send_proxy_details: bool,

#[serde(default = "default_additional_headers")]
pub additional_headers: HashMap<String, String>,

#[serde(default = "default_console_log_level")]
pub console_log_level: String,

Expand Down Expand Up @@ -175,6 +178,10 @@ fn default_send_proxy_details() -> bool {
false
}

fn default_additional_headers() -> HashMap<String, String> {
HashMap::new()
}

fn default_console_log_level() -> String {
"Info".to_owned()
}
Expand Down
22 changes: 11 additions & 11 deletions src/gpu_worker.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use chan;
use crate::miner::{Buffer, NonceData};
use crate::ocl::GpuContext;
use crate::ocl::{gpu_hash, gpu_transfer};
use crate::reader::ReadReply;
use crossbeam_channel::{Receiver, Sender};
use futures::sync::mpsc;
use futures::{Future, Sink};
use miner::{Buffer, NonceData};
use ocl::GpuContext;
use ocl::{gpu_hash, gpu_transfer};
use reader::ReadReply;
use std::sync::Arc;
use std::u64;

pub fn create_gpu_worker_task(
benchmark: bool,
rx_read_replies: chan::Receiver<ReadReply>,
tx_empty_buffers: chan::Sender<Box<Buffer + Send>>,
rx_read_replies: Receiver<ReadReply>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
context_mu: Arc<GpuContext>,
) -> impl FnOnce() {
move || {
for read_reply in rx_read_replies {
let mut buffer = read_reply.buffer;
let buffer = read_reply.buffer;
// handle empty buffers (read errors) && benchmark
if read_reply.info.len == 0 || benchmark {
// forward 'drive finished signal'
Expand Down Expand Up @@ -80,11 +80,11 @@ pub fn create_gpu_worker_task(

#[cfg(test)]
mod tests {
extern crate ocl_core as core;
use self::core::Event;
use crate::ocl::gpu_hash;
use crate::ocl::GpuContext;
use hex;
use ocl::gpu_hash;
use ocl::GpuContext;
use ocl_core as core;
use std::sync::Arc;
use std::u64;

Expand Down
18 changes: 9 additions & 9 deletions src/gpu_worker_async.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use chan;
use crate::miner::{Buffer, NonceData};
use crate::ocl::GpuContext;
use crate::ocl::{gpu_hash, gpu_transfer, gpu_transfer_and_hash};
use crate::reader::{BufferInfo, ReadReply};
use crossbeam_channel::{Receiver, Sender};
use futures::sync::mpsc;
use futures::{Future, Sink};
use miner::{Buffer, NonceData};
use ocl::GpuContext;
use ocl::{gpu_hash, gpu_transfer, gpu_transfer_and_hash};
use reader::{BufferInfo, ReadReply};
use std::sync::Arc;
use std::u64;

pub fn create_gpu_worker_task_async(
benchmark: bool,
rx_read_replies: chan::Receiver<ReadReply>,
tx_empty_buffers: chan::Sender<Box<Buffer + Send>>,
rx_read_replies: Receiver<ReadReply>,
tx_empty_buffers: Sender<Box<Buffer + Send>>,
tx_nonce_data: mpsc::Sender<NonceData>,
context_mu: Arc<GpuContext>,
num_drives: usize,
Expand All @@ -30,10 +30,10 @@ pub fn create_gpu_worker_task_async(
gpu_signal: 0,
};
let mut drive_count = 0;
let (tx_sink, rx_sink) = chan::bounded(1);
let (tx_sink, rx_sink) = crossbeam_channel::bounded(1);
let mut active_height = 0;
for read_reply in rx_read_replies {
let mut buffer = read_reply.buffer;
let buffer = read_reply.buffer;
// handle empty buffers (read errors) && benchmark
if read_reply.info.len == 0 || benchmark {
// forward 'drive finished signal'
Expand Down
74 changes: 57 additions & 17 deletions src/miner.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use crate::config::Cfg;
use crate::cpu_worker::create_cpu_worker_task;
#[cfg(feature = "opencl")]
use crate::gpu_worker::create_gpu_worker_task;
#[cfg(feature = "opencl")]
use crate::gpu_worker_async::create_gpu_worker_task_async;
#[cfg(feature = "opencl")]
use crate::ocl::GpuBuffer;
#[cfg(feature = "opencl")]
use crate::ocl::GpuContext;
use crate::plot::{Plot, SCOOP_SIZE};
use crate::pocmath;
use crate::reader::Reader;
use crate::requests::RequestHandler;
use crate::utils::get_device_id;
use crossbeam_channel;
#[cfg(windows)]
use crate::utils::set_thread_ideal_processor;
use core_affinity;
use crossbeam_channel;
use futures::sync::mpsc;
#[cfg(feature = "opencl")]
use gpu_worker::create_gpu_worker_task;
#[cfg(feature = "opencl")]
use gpu_worker_async::create_gpu_worker_task_async;
#[cfg(feature = "opencl")]
use ocl::GpuBuffer;
use ocl_core::Mem;
use std::cell::RefCell;
use std::cmp::min;
use std::collections::HashMap;
Expand All @@ -32,8 +36,7 @@ use stopwatch::Stopwatch;
use tokio::prelude::*;
use tokio::timer::Interval;
use tokio_core::reactor::Core;
#[cfg(windows)]
use utils::set_thread_ideal_processor;
use url::Url;

pub struct Miner {
reader: Reader,
Expand All @@ -52,10 +55,13 @@ pub struct State {
generation_signature: String,
height: u64,
account_id_to_best_deadline: HashMap<u64, u64>,
server_target_deadline: u64,
base_target: u64,
sw: Stopwatch,
scanning: bool,
processed_reader_tasks: usize,
first: bool,
outage: bool,
}

pub struct NonceData {
Expand All @@ -73,7 +79,7 @@ pub trait Buffer {
#[cfg(feature = "opencl")]
fn get_gpu_buffers(&self) -> Option<&GpuBuffer>;
#[cfg(feature = "opencl")]
fn get_gpu_data(&self) -> Option<core::Mem>;
fn get_gpu_data(&self) -> Option<Mem>;
fn unmap(&self);
fn get_id(&self) -> usize;
}
Expand Down Expand Up @@ -107,7 +113,7 @@ impl Buffer for CpuBuffer {
None
}
#[cfg(feature = "opencl")]
fn get_gpu_data(&self) -> Option<core::Mem> {
fn get_gpu_data(&self) -> Option<Mem> {
None
}
fn unmap(&self) {}
Expand Down Expand Up @@ -282,8 +288,10 @@ impl Miner {
#[cfg(feature = "opencl")]
let buffer_count = cpu_buffer_count + gpu_buffer_count;
let buffer_size_cpu = cfg.cpu_nonces_per_cache * SCOOP_SIZE as usize;
let (tx_empty_buffers, rx_empty_buffers) = crossbeam_channel::bounded(buffer_count as usize);
let (tx_read_replies_cpu, rx_read_replies_cpu) = crossbeam_channel::bounded(cpu_buffer_count);
let (tx_empty_buffers, rx_empty_buffers) =
crossbeam_channel::bounded(buffer_count as usize);
let (tx_read_replies_cpu, rx_read_replies_cpu) =
crossbeam_channel::bounded(cpu_buffer_count);

#[cfg(feature = "opencl")]
let mut tx_read_replies_gpu = Vec::new();
Expand Down Expand Up @@ -392,6 +400,7 @@ impl Miner {
let tx_read_replies_gpu = Some(tx_read_replies_gpu);
#[cfg(not(feature = "opencl"))]
let tx_read_replies_gpu = None;
let base_url = Url::parse(&cfg.url).expect("invalid mining server url");

let core = Core::new().unwrap();
Miner {
Expand All @@ -413,21 +422,25 @@ impl Miner {
target_deadline: cfg.target_deadline,
account_id_to_target_deadline: cfg.account_id_to_target_deadline,
request_handler: RequestHandler::new(
cfg.url,
base_url,
cfg.account_id_to_secret_phrase,
cfg.timeout,
core.handle(),
(total_size * 4 / 1024 / 1024) as usize,
cfg.send_proxy_details,
cfg.additional_headers,
),
state: Arc::new(Mutex::new(State {
generation_signature: "".to_owned(),
height: 0,
account_id_to_best_deadline: HashMap::new(),
server_target_deadline: u64::MAX,
base_target: 1,
processed_reader_tasks: 0,
sw: Stopwatch::new(),
scanning: false,
first: true,
outage: false,
})),
get_mining_info_interval: cfg.get_mining_info_interval,
core,
Expand Down Expand Up @@ -459,13 +472,19 @@ impl Miner {
match mining_info {
Ok(mining_info) => {
let mut state = state.lock().unwrap();
state.first = false;
if state.outage {
error!("{: <80}", "outage resolved.");
state.outage = false;
}
if mining_info.generation_signature != state.generation_signature {
for best_deadlines in state.account_id_to_best_deadline.values_mut()
{
*best_deadlines = u64::MAX;
}
state.height = mining_info.height;
state.base_target = mining_info.base_target;
state.server_target_deadline = mining_info.target_deadline;

let gensig =
pocmath::decode_gensig(&mining_info.generation_signature);
Expand Down Expand Up @@ -501,7 +520,25 @@ impl Miner {
state.sw.restart();
}
}
_ => warn!("{: <80}", "error getting mining info"),
_ => {
let mut state = state.lock().unwrap();
if state.first {
error!(
"{: <80}",
"error getting mining info, please check server config"
);
state.first = false;
state.outage = true;
} else {
if !state.outage {
error!(
"{: <80}",
"error getting mining info => connection outage..."
);
}
state.outage = true;
}
}
}
future::ok(())
})
Expand All @@ -526,9 +563,12 @@ impl Miner {
.unwrap_or(&u64::MAX);
if best_deadline > deadline
&& deadline
< *(account_id_to_target_deadline
.get(&nonce_data.account_id)
.unwrap_or(&target_deadline))
< min(
state.server_target_deadline,
*(account_id_to_target_deadline
.get(&nonce_data.account_id)
.unwrap_or(&target_deadline)),
)
{
state
.account_id_to_best_deadline
Expand Down
6 changes: 3 additions & 3 deletions src/ocl.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate ocl_core as core;
use self::core::{
ArgVal, ContextProperties, DeviceInfo, Event, KernelWorkGroupInfo, PlatformInfo, Status,
};
use ocl_core as core;

use config::Cfg;
use miner::Buffer;
use crate::config::Cfg;
use crate::miner::Buffer;
use std::cmp::{max, min};
use std::ffi::CString;
use std::process;
Expand Down
8 changes: 4 additions & 4 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::miner::Buffer;
#[cfg(feature = "opencl")]
use crate::miner::CpuBuffer;
use crate::plot::Plot;
use crossbeam_channel::{Receiver, Sender};
use crossbeam_channel;
#[cfg(windows)]
use crate::utils::set_thread_ideal_processor;
use core_affinity;
use crossbeam_channel;
use crossbeam_channel::{Receiver, Sender};
use filetime::FileTime;
use pbr::{ProgressBar, Units};
use rayon::prelude::*;
Expand All @@ -13,8 +15,6 @@ use std::io::Stdout;
use std::sync::RwLock;
use std::sync::{Arc, Mutex};
use stopwatch::Stopwatch;
#[cfg(windows)]
use utils::set_thread_ideal_processor;

pub struct BufferInfo {
pub len: usize,
Expand Down
Loading

0 comments on commit 65a6d80

Please sign in to comment.