From 03182b181df8fba21af561dd5d5a33aef3561cfc Mon Sep 17 00:00:00 2001 From: JohnnyFFM Date: Sat, 22 Dec 2018 22:13:12 +0100 Subject: [PATCH] v.1.6.8, stable rust, multi_chain switch --- Cargo.lock | 2 +- Cargo.toml | 2 +- config.yaml | 8 ++++++-- src/config.rs | 21 +++++++++++++++++++++ src/logger.rs | 12 ++++++++---- src/miner.rs | 40 ++++++++++++++++++++++++++++++++-------- src/ocl.rs | 49 ++++++++++++++++++++++++++++++++++--------------- src/reader.rs | 12 ++++++++---- src/requests.rs | 9 ++++++--- src/worker.rs | 3 ++- 10 files changed, 119 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13de06b..14e167d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -923,7 +923,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "scavenger" -version = "1.6.7" +version = "1.6.8" dependencies = [ "aligned_alloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 2cfc649..2b49d5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scavenger" -version = "1.6.7" +version = "1.6.8" license = "GPL-3.0" authors = ["PoC Consortium "] description = """ diff --git a/config.yaml b/config.yaml index 0de2781..00b7fd3 100644 --- a/config.yaml +++ b/config.yaml @@ -8,8 +8,8 @@ plot_dirs: # - '/first/linux/plot/dir' # - '/second/linux/plot/dir' -# url: 'http://pool.dev.burst-test.net:8124' # testnet pool url: 'http://wallet.dev.burst-test.net:6876' # testnet wallet +# url: 'http://pool.dev.burst-test.net:8124' # testnet pool # url: 'http://dummypool.megash.it' # dummypool with constant scoop number for benchmarking hdd_reader_thread_count: 0 # default 0 (=number of disks) @@ -44,10 +44,14 @@ show_progress: true # default true show_drive_stats: false # default false benchmark_only: 'disabled' # default disabled, options (disabled, I/O, XPU) +multi_chain: false # enable multi-chain mining +maximum_fork_difference: 1440 # maximum block-height difference to last block +minimum_block_height: 500000 # don't work blocks lower than this height + # Low noise log patterns console_log_pattern: "{({d(%H:%M:%S)} [{l}]):16.16} {m}{n}" logfile_log_pattern: "{({d(%Y-%m-%d %H:%M:%S)} [{l}]):26.26} {m}{n}" # More detailed log patterns #console_log_pattern: "{d(%H:%M:%S.%3f%z)} [{h({l}):<5}] [{T}] [{t}] - {M}:{m}{n}" -#logfile_log_pattern: "{d(%Y-%m-%dT%H:%M:%S.%3f%z)} [{h({l}):<5}] [{T}]-[{t}] [{f}:{L}] - {M}:{m}{n}" \ No newline at end of file +#logfile_log_pattern: "{d(%Y-%m-%dT%H:%M:%S.%3f%z)} [{h({l}):<5}] [{T}]-[{t}] [{f}:{L}] - {M}:{m}{n}" diff --git a/src/config.rs b/src/config.rs index 44d5705..e250dab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -87,6 +87,15 @@ pub struct Cfg { #[serde(default = "default_benchmark_only")] pub benchmark_only: String, + + #[serde(default = "default_multi_chain")] + pub multi_chain: bool, + + #[serde(default = "default_maximum_fork_difference")] + pub maximum_fork_difference: u64, + + #[serde(default = "default_minimum_block_height")] + pub minimum_block_height: u64, } fn default_secret_phrase() -> HashMap { @@ -193,6 +202,18 @@ fn default_benchmark_only() -> String { "disabled".to_owned() } +fn default_multi_chain() -> bool { + false +} + +fn default_maximum_fork_difference() -> u64 { + 1440 +} + +fn default_minimum_block_height() -> u64 { + 500000 +} + pub fn load_cfg(config: &str) -> Cfg { let cfg_str = fs::read_to_string(config).expect("failed to open config"); let cfg: Cfg = serde_yaml::from_str(&cfg_str).expect("failed to parse config"); diff --git a/src/logger.rs b/src/logger.rs index 5aa054b..a1a1edf 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -57,7 +57,8 @@ pub fn init_logger(cfg: &Cfg) -> log4rs::Handle { Appender::builder() .filter(Box::new(ThresholdFilter::new(level_console))) .build("stdout", Box::new(stdout)), - ).build(Root::builder().appender("stdout").build(LevelFilter::Info)) + ) + .build(Root::builder().appender("stdout").build(LevelFilter::Info)) .unwrap() } else { let logfile = RollingFileAppender::builder() @@ -69,16 +70,19 @@ pub fn init_logger(cfg: &Cfg) -> log4rs::Handle { Appender::builder() .filter(Box::new(ThresholdFilter::new(level_console))) .build("stdout", Box::new(stdout)), - ).appender( + ) + .appender( Appender::builder() .filter(Box::new(ThresholdFilter::new(level_logfile))) .build("logfile", Box::new(logfile)), - ).build( + ) + .build( Root::builder() .appender("stdout") .appender("logfile") .build(LevelFilter::Trace), - ).unwrap() + ) + .unwrap() }; log4rs::init_config(config).unwrap() } diff --git a/src/miner.rs b/src/miner.rs index f63deca..fa211cc 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -41,12 +41,15 @@ pub struct Miner { request_handler: RequestHandler, rx_nonce_data: mpsc::Receiver, target_deadline: u64, - account_id_to_target_deadline : HashMap, + account_id_to_target_deadline: HashMap, state: Arc>, reader_task_count: usize, get_mining_info_interval: u64, core: Core, wakeup_after: i64, + multi_chain: bool, + maximum_fork_difference: u64, + minimum_block_height: u64, } pub struct State { @@ -289,7 +292,7 @@ impl Miner { cfg.send_proxy_details, ), state: Arc::new(Mutex::new(State { - generation_signature : "".to_owned(), + generation_signature: "".to_owned(), height: 0, account_id_to_best_deadline: HashMap::new(), base_target: 1, @@ -300,6 +303,9 @@ impl Miner { get_mining_info_interval: cfg.get_mining_info_interval, core, wakeup_after: cfg.hdd_wakeup_after * 1000, // ms -> s + multi_chain: cfg.multi_chain, + maximum_fork_difference: cfg.maximum_fork_difference, + minimum_block_height: cfg.minimum_block_height, } } @@ -315,18 +321,29 @@ impl Miner { // there might be a way to solve this without two nested moves let get_mining_info_interval = self.get_mining_info_interval; let wakeup_after = self.wakeup_after; + let multi_chain = self.multi_chain; + let maximum_fork_difference = self.maximum_fork_difference; + let minimum_block_height = self.minimum_block_height; handle.spawn( Interval::new( Instant::now(), Duration::from_millis(get_mining_info_interval), - ).for_each(move |_| { + ) + .for_each(move |_| { let state = state.clone(); let reader = reader.clone(); request_handler.get_mining_info().then(move |mining_info| { match mining_info { Ok(mining_info) => { let mut state = state.lock().unwrap(); - if mining_info.generation_signature != state.generation_signature { + let new_block = + mining_info.generation_signature != state.generation_signature; + if (new_block && multi_chain) + || (new_block + && (state.height == 0 || mining_info.height + > (state.height - maximum_fork_difference)) + && mining_info.height > minimum_block_height) + { for best_deadlines in state.account_id_to_best_deadline.values_mut() { *best_deadlines = u64::MAX; @@ -368,7 +385,8 @@ impl Miner { } future::ok(()) }) - }).map_err(|e| panic!("interval errored: err={:?}", e)), + }) + .map_err(|e| panic!("interval errored: err={:?}", e)), ); let target_deadline = self.target_deadline; @@ -386,7 +404,12 @@ impl Miner { .account_id_to_best_deadline .get(&nonce_data.account_id) .unwrap_or(&u64::MAX); - if best_deadline > deadline && deadline < *(account_id_to_target_deadline.get(&nonce_data.account_id).unwrap_or(&target_deadline)) { + if best_deadline > deadline + && deadline + < *(account_id_to_target_deadline + .get(&nonce_data.account_id) + .unwrap_or(&target_deadline)) + { state .account_id_to_best_deadline .insert(nonce_data.account_id, deadline); @@ -400,7 +423,7 @@ impl Miner { 0, ); /* tradeoff between non-verbosity and information: stopped informing about - found deadlines, but reporting accepted deadlines instead. + found deadlines, but reporting accepted deadlines instead. info!( "deadline captured: account={}, nonce={}, deadline={}", nonce_data.account_id, nonce_data.nonce, deadline @@ -425,7 +448,8 @@ impl Miner { } } Ok(()) - }).map_err(|e| panic!("interval errored: err={:?}", e)), + }) + .map_err(|e| panic!("interval errored: err={:?}", e)), ); self.core.run(future::empty::<(), ()>()).unwrap(); diff --git a/src/ocl.rs b/src/ocl.rs index d0f14ac..681faed 100644 --- a/src/ocl.rs +++ b/src/ocl.rs @@ -156,7 +156,8 @@ impl GpuBuffer { core::MEM_READ_WRITE, context.gdim1[0], None, - ).unwrap() + ) + .unwrap() }; let best_offset_gpu = unsafe { @@ -183,7 +184,8 @@ impl GpuBuffer { core::MEM_READ_ONLY | core::MEM_USE_HOST_PTR, context.gdim1[0] * 64, Some(&data), - ).unwrap() + ) + .unwrap() }; GpuBuffer { @@ -215,7 +217,8 @@ impl Buffer for GpuBuffer { &(*locked_context).gdim1[0] * 64, None::, None::<&mut Event>, - ).unwrap(), + ) + .unwrap(), )); } } @@ -260,7 +263,8 @@ impl GpuContext { &CString::new("").unwrap(), None, None, - ).unwrap(); + ) + .unwrap(); let queue = core::create_command_queue(&context, &device_id, None).unwrap(); let kernel1 = core::create_kernel(&program, "calculate_deadlines").unwrap(); let kernel2 = core::create_kernel(&program, "find_min").unwrap(); @@ -311,7 +315,8 @@ pub fn find_best_deadline_gpu( &gensig, None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } if gpu_context.mapping { @@ -323,7 +328,8 @@ pub fn find_best_deadline_gpu( &*temp2, None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } else { unsafe { core::enqueue_write_buffer( @@ -334,7 +340,8 @@ pub fn find_best_deadline_gpu( &data2, None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } } @@ -352,26 +359,35 @@ pub fn find_best_deadline_gpu( Some(gpu_context.ldim1), None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } core::set_kernel_arg(&gpu_context.kernel2, 0, ArgVal::mem(&buffer.deadlines_gpu)).unwrap(); - core::set_kernel_arg(&gpu_context.kernel2, 1, ArgVal::primitive(&(nonce_count as u64))).unwrap(); + core::set_kernel_arg( + &gpu_context.kernel2, + 1, + ArgVal::primitive(&(nonce_count as u64)), + ) + .unwrap(); core::set_kernel_arg( &gpu_context.kernel2, 2, ArgVal::local::(&gpu_context.ldim2[0]), - ).unwrap(); + ) + .unwrap(); core::set_kernel_arg( &gpu_context.kernel2, 3, ArgVal::mem(&buffer.best_offset_gpu), - ).unwrap(); + ) + .unwrap(); core::set_kernel_arg( &gpu_context.kernel2, 4, ArgVal::mem(&buffer.best_deadline_gpu), - ).unwrap(); + ) + .unwrap(); unsafe { core::enqueue_kernel( @@ -383,7 +399,8 @@ pub fn find_best_deadline_gpu( Some(gpu_context.ldim2), None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } let mut best_offset = vec![0u64; 1]; @@ -398,7 +415,8 @@ pub fn find_best_deadline_gpu( &mut best_offset, None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } unsafe { core::enqueue_read_buffer( @@ -409,7 +427,8 @@ pub fn find_best_deadline_gpu( &mut best_deadline, None::, None::<&mut Event>, - ).unwrap(); + ) + .unwrap(); } (best_deadline[0], best_offset[0]) diff --git a/src/reader.rs b/src/reader.rs index 67bd0e7..0dfed37 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -80,7 +80,8 @@ impl Reader { #[cfg(windows)] set_thread_ideal_processor(id % core_ids.len()); } - }).build() + }) + .build() .unwrap(), rx_empty_buffers, tx_read_replies_cpu, @@ -131,7 +132,8 @@ impl Reader { self.pool.spawn(task); interupt - }).collect(); + }) + .collect(); } pub fn wakeup(&mut self) { @@ -297,7 +299,8 @@ pub fn check_overlap(drive_id_to_plots: &HashMap 0 }); result |= dupes.count() > 0; @@ -311,7 +314,8 @@ pub fn check_overlap(drive_id_to_plots: &HashMap 0 }); result |= dupes.count() > 0; diff --git a/src/requests.rs b/src/requests.rs index c30ed47..8da93b8 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -242,11 +242,13 @@ impl RequestHandler { .header( "X-Minername", hostname::get_hostname().unwrap_or("".to_owned()), - ).header( + ) + .header( "X-Plotfile", "ScavengerProxy/".to_owned() + &*hostname::get_hostname().unwrap_or("".to_owned()), - ).body(hyper::Body::empty()) + ) + .body(hyper::Body::empty()) .unwrap() } else { Request::post(self.uri_for(path)) @@ -275,7 +277,8 @@ impl RequestHandler { .and_then(|body| { let res = parse_json_result(&body)?; Ok(res) - }).from_err(); + }) + .from_err(); let timeout = Timeout::new(self.timeout, &self.handle).unwrap(); let timeout = timeout diff --git a/src/worker.rs b/src/worker.rs index f178a89..2b6719f 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -289,7 +289,8 @@ pub fn create_worker_task( nonce: offset + read_reply.start_nonce, reader_task_processed: read_reply.finished, account_id: read_reply.account_id, - }).wait() + }) + .wait() .expect("failed to send nonce data"); tx_empty_buffers.send(buffer); }