mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Updates to ensure multithreaded CI tests don't fail (#81)
Locks loading of miner plugins so it only ever happens once.
This commit is contained in:
parent
dca5504203
commit
26ce1d27d7
4 changed files with 35 additions and 4 deletions
|
@ -70,7 +70,8 @@ use_cuckoo_miner = true
|
||||||
#directory
|
#directory
|
||||||
#Plugins currently included are:
|
#Plugins currently included are:
|
||||||
#"simple" : the basic cuckoo algorithm
|
#"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:
|
#Not included but verified working:
|
||||||
#"cuda" a gpu miner - which currently needs to bebuilt and installed
|
#"cuda" a gpu miner - which currently needs to bebuilt and installed
|
||||||
#separately from#the cuckoo-miner repository. Instructions found there
|
#separately from#the cuckoo-miner repository. Instructions found there
|
||||||
|
|
|
@ -15,7 +15,7 @@ grin_util = { path = "../util" }
|
||||||
grin_wallet = { path = "../wallet" }
|
grin_wallet = { path = "../wallet" }
|
||||||
secp256k1zkp = { path = "../secp256k1zkp" }
|
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"
|
env_logger="^0.3.5"
|
||||||
futures = "^0.1.9"
|
futures = "^0.1.9"
|
||||||
|
@ -29,3 +29,4 @@ tokio-core="^0.1.1"
|
||||||
tokio-timer="^0.1.0"
|
tokio-timer="^0.1.0"
|
||||||
rand = "^0.3"
|
rand = "^0.3"
|
||||||
tiny-keccak = "1.1"
|
tiny-keccak = "1.1"
|
||||||
|
lazy_static = "0.2.8"
|
||||||
|
|
|
@ -34,6 +34,8 @@ extern crate serde_derive;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
extern crate tokio_timer;
|
extern crate tokio_timer;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
extern crate grin_api as api;
|
extern crate grin_api as api;
|
||||||
extern crate grin_chain as chain;
|
extern crate grin_chain as chain;
|
||||||
|
|
|
@ -29,6 +29,8 @@ use std::collections::HashMap;
|
||||||
use core::core::Proof;
|
use core::core::Proof;
|
||||||
use types::{MinerConfig, ServerConfig};
|
use types::{MinerConfig, ServerConfig};
|
||||||
|
|
||||||
|
use std::sync::{Mutex};
|
||||||
|
|
||||||
use cuckoo_miner::{
|
use cuckoo_miner::{
|
||||||
CuckooMiner,
|
CuckooMiner,
|
||||||
CuckooPluginManager,
|
CuckooPluginManager,
|
||||||
|
@ -37,6 +39,15 @@ use cuckoo_miner::{
|
||||||
CuckooMinerSolution,
|
CuckooMinerSolution,
|
||||||
CuckooPluginCapabilities};
|
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<Option<CuckooMinerConfig>> = Mutex::new(None);
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PluginMiner {
|
pub struct PluginMiner {
|
||||||
miner:Option<CuckooMiner>,
|
miner:Option<CuckooMiner>,
|
||||||
last_solution: CuckooMinerSolution,
|
last_solution: CuckooMinerSolution,
|
||||||
|
@ -73,6 +84,17 @@ impl PluginMiner {
|
||||||
//to the executable path, though they should appear somewhere else
|
//to the executable path, though they should appear somewhere else
|
||||||
//when packaging is more//thought out
|
//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 mut plugin_manager = CuckooPluginManager::new().unwrap();
|
||||||
let result=plugin_manager.load_plugin_dir(plugin_install_path);
|
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();
|
let caps = plugin_manager.get_available_plugins(&filter).unwrap();
|
||||||
//insert it into the miner configuration being created below
|
//insert it into the miner configuration being created below
|
||||||
|
|
||||||
|
|
||||||
let mut config = CuckooMinerConfig::new();
|
let mut config = CuckooMinerConfig::new();
|
||||||
|
|
||||||
info!("Mining using plugin: {}", caps[0].full_path.clone());
|
info!("Mining using plugin: {}", caps[0].full_path.clone());
|
||||||
config.plugin_full_path = caps[0].full_path.clone();
|
config.plugin_full_path = caps[0].full_path.clone();
|
||||||
if let Some(l) = miner_config.cuckoo_miner_parameter_list {
|
if let Some(l) = miner_config.cuckoo_miner_parameter_list {
|
||||||
config.parameter_list = l.clone();
|
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
|
//this will load the associated plugin
|
||||||
let result=CuckooMiner::new(config);
|
let result=CuckooMiner::new(config);
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
|
@ -112,6 +137,8 @@ impl PluginMiner {
|
||||||
error!("Accepted values are: {:?}", caps[0].parameters);
|
error!("Accepted values are: {:?}", caps[0].parameters);
|
||||||
panic!("Unable to init mining plugin.");
|
panic!("Unable to init mining plugin.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.miner=Some(result.unwrap());
|
self.miner=Some(result.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue