mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11: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
|
||||
#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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Option<CuckooMinerConfig>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
pub struct PluginMiner {
|
||||
miner:Option<CuckooMiner>,
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue