From 26ce1d27d727475a34bccc70f053b23c5e452447 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 19 Jul 2017 16:40:57 +0000 Subject: [PATCH] Updates to ensure multithreaded CI tests don't fail (#81) Locks loading of miner plugins so it only ever happens once. --- grin.toml | 3 ++- grin/Cargo.toml | 3 ++- grin/src/lib.rs | 2 ++ grin/src/plugin.rs | 31 +++++++++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/grin.toml b/grin.toml index b5b9fb98f..f9e304b92 100644 --- a/grin.toml +++ b/grin.toml @@ -70,7 +70,8 @@ use_cuckoo_miner = true #directory #Plugins currently included are: #"simple" : the basic cuckoo algorithm -#"edgetrim" : an algorithm trading speed for a much lower memory footpring +#"edgetrim" : an algorithm trading speed for a much lower memory footprint +#"tomato" : Time memory-tradeoff... low memory but very slow #Not included but verified working: #"cuda" a gpu miner - which currently needs to bebuilt and installed #separately from#the cuckoo-miner repository. Instructions found there diff --git a/grin/Cargo.toml b/grin/Cargo.toml index ef4546eb3..2373e4114 100644 --- a/grin/Cargo.toml +++ b/grin/Cargo.toml @@ -15,7 +15,7 @@ grin_util = { path = "../util" } grin_wallet = { path = "../wallet" } secp256k1zkp = { path = "../secp256k1zkp" } -cuckoo_miner = { git = "https://github.com/mimblewimble/cuckoo-miner", tag="grin_integration"} +cuckoo_miner = { git = "https://github.com/mimblewimble/cuckoo-miner", tag="grin_integration_2"} env_logger="^0.3.5" futures = "^0.1.9" @@ -29,3 +29,4 @@ tokio-core="^0.1.1" tokio-timer="^0.1.0" rand = "^0.3" tiny-keccak = "1.1" +lazy_static = "0.2.8" diff --git a/grin/src/lib.rs b/grin/src/lib.rs index 190aed30d..038fdbc49 100644 --- a/grin/src/lib.rs +++ b/grin/src/lib.rs @@ -34,6 +34,8 @@ extern crate serde_derive; extern crate time; extern crate tokio_core; extern crate tokio_timer; +#[macro_use] +extern crate lazy_static; extern crate grin_api as api; extern crate grin_chain as chain; diff --git a/grin/src/plugin.rs b/grin/src/plugin.rs index 06f843f6f..c28555799 100644 --- a/grin/src/plugin.rs +++ b/grin/src/plugin.rs @@ -29,6 +29,8 @@ use std::collections::HashMap; use core::core::Proof; use types::{MinerConfig, ServerConfig}; +use std::sync::{Mutex}; + use cuckoo_miner::{ CuckooMiner, CuckooPluginManager, @@ -37,6 +39,15 @@ use cuckoo_miner::{ CuckooMinerSolution, CuckooPluginCapabilities}; +//For now, we're just going to keep a static reference around to the loaded config +//And not allow querying the plugin directory twice once a plugin has been selected +//This is to keep compatibility with multi-threaded testing, so that spawned +//testing threads don't try to load/unload the library while another thread is +//using it. +lazy_static!{ + static ref LOADED_CONFIG: Mutex> = Mutex::new(None); +} + pub struct PluginMiner { miner:Option, last_solution: CuckooMinerSolution, @@ -73,6 +84,17 @@ impl PluginMiner { //to the executable path, though they should appear somewhere else //when packaging is more//thought out + let mut loaded_config_ref = LOADED_CONFIG.lock().unwrap(); + + //Load from here instead + if let Some(ref c) = *loaded_config_ref { + debug!("Not re-loading plugin or directory."); + //this will load the associated plugin + let result=CuckooMiner::new(c.clone()); + self.miner=Some(result.unwrap()); + return; + } + let mut plugin_manager = CuckooPluginManager::new().unwrap(); let result=plugin_manager.load_plugin_dir(plugin_install_path); @@ -96,15 +118,18 @@ impl PluginMiner { let caps = plugin_manager.get_available_plugins(&filter).unwrap(); //insert it into the miner configuration being created below - let mut config = CuckooMinerConfig::new(); - + info!("Mining using plugin: {}", caps[0].full_path.clone()); config.plugin_full_path = caps[0].full_path.clone(); if let Some(l) = miner_config.cuckoo_miner_parameter_list { config.parameter_list = l.clone(); } + //Store this config now, because we just want one instance + //of the plugin lib per invocation now + *loaded_config_ref=Some(config.clone()); + //this will load the associated plugin let result=CuckooMiner::new(config); if let Err(e) = result { @@ -112,6 +137,8 @@ impl PluginMiner { error!("Accepted values are: {:?}", caps[0].parameters); panic!("Unable to init mining plugin."); } + + self.miner=Some(result.unwrap()); } }