Skip to content

Commit

Permalink
Fix compiler warning and rustfmt (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlesceller authored Dec 17, 2019
1 parent 10afbc1 commit 846ff1d
Show file tree
Hide file tree
Showing 24 changed files with 361 additions and 336 deletions.
4 changes: 2 additions & 2 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ extern crate toml;
#[macro_use]
extern crate slog;

extern crate grin_miner_util as util;
extern crate cuckoo_miner as cuckoo;
extern crate grin_miner_util as util;

mod config;
mod types;

pub use types::{ConfigError, ConfigMembers, GlobalConfig, GrinMinerPluginConfig, MinerConfig};
pub use config::read_configs;
pub use types::{ConfigError, ConfigMembers, GlobalConfig, GrinMinerPluginConfig, MinerConfig};
18 changes: 8 additions & 10 deletions cuckoo-miner/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ extern crate fs_extra;
mod sanity;

use cmake::Config;
use std::{env, fs};
use std::path::PathBuf;
use fs_extra::dir::*;

use std::path::PathBuf;
use std::{env, fs};

#[cfg(feature = "build-cuda-plugins")]
const BUILD_CUDA_PLUGINS:&str="TRUE";
const BUILD_CUDA_PLUGINS: &str = "TRUE";
#[cfg(not(feature = "build-cuda-plugins"))]
const BUILD_CUDA_PLUGINS:&str="FALSE";
const BUILD_CUDA_PLUGINS: &str = "FALSE";

/// Tests whether source cuckoo directory exists
Expand Down Expand Up @@ -72,10 +71,10 @@ fn main() {
}

let dst = Config::new("src/cuckoo_sys/plugins")
.define("BUILD_CUDA_PLUGINS",BUILD_CUDA_PLUGINS) //whatever flags go here
//.cflag("-foo") //and here
.build_target("")
.build();
.define("BUILD_CUDA_PLUGINS", BUILD_CUDA_PLUGINS) //whatever flags go here
//.cflag("-foo") //and here
.build_target("")
.build();

println!("Plugin path: {:?}", plugin_path);
println!("OUT PATH: {:?}", out_path);
Expand All @@ -86,5 +85,4 @@ fn main() {
}

println!("cargo:rustc-link-search=native={}", dst.display());

}
20 changes: 8 additions & 12 deletions cuckoo-miner/src/cuckoo_sys/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ impl PluginLibrary {
lib_full_path: String::from(path),

cuckoo_create_solver_ctx: {
let cuckoo_create_solver_ctx: libloading::Symbol<
CuckooCreateSolverCtx,
> = loaded_library.get(b"create_solver_ctx\0").unwrap();
let cuckoo_create_solver_ctx: libloading::Symbol<CuckooCreateSolverCtx> =
loaded_library.get(b"create_solver_ctx\0").unwrap();
Arc::new(Mutex::new(*cuckoo_create_solver_ctx.into_raw()))
},

cuckoo_destroy_solver_ctx: {
let cuckoo_destroy_solver_ctx: libloading::Symbol<
CuckooDestroySolverCtx,
> = loaded_library.get(b"destroy_solver_ctx\0").unwrap();
let cuckoo_destroy_solver_ctx: libloading::Symbol<CuckooDestroySolverCtx> =
loaded_library.get(b"destroy_solver_ctx\0").unwrap();
Arc::new(Mutex::new(*cuckoo_destroy_solver_ctx.into_raw()))
},

Expand All @@ -87,16 +85,14 @@ impl PluginLibrary {
},

cuckoo_stop_solver: {
let cuckoo_stop_solver: libloading::Symbol<
CuckooStopSolver,
> = loaded_library.get(b"stop_solver\0").unwrap();
let cuckoo_stop_solver: libloading::Symbol<CuckooStopSolver> =
loaded_library.get(b"stop_solver\0").unwrap();
Arc::new(Mutex::new(*cuckoo_stop_solver.into_raw()))
},

cuckoo_fill_default_params: {
let cuckoo_fill_default_params: libloading::Symbol<
CuckooFillDefaultParams,
> = loaded_library.get(b"fill_default_params\0").unwrap();
let cuckoo_fill_default_params: libloading::Symbol<CuckooFillDefaultParams> =
loaded_library.get(b"fill_default_params\0").unwrap();
Arc::new(Mutex::new(*cuckoo_fill_default_params.into_raw()))
},

Expand Down
7 changes: 4 additions & 3 deletions cuckoo-miner/src/error/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ impl From<io::Error> for CuckooMinerError {

impl From<string::FromUtf8Error> for CuckooMinerError {
fn from(error: string::FromUtf8Error) -> Self {
CuckooMinerError::PluginIOError(String::from(
format!("Error loading plugin description: {}", error),
))
CuckooMinerError::PluginIOError(String::from(format!(
"Error loading plugin description: {}",
error
)))
}
}
7 changes: 2 additions & 5 deletions cuckoo-miner/src/miner/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

/// Difficulty calculation as from Grin
use blake2::blake2b::Blake2b;
use byteorder::{BigEndian, ByteOrder};
use std::cmp::{max, min};
use std::fmt;
use byteorder::{BigEndian, ByteOrder};

// constants from grin
const DEFAULT_MIN_EDGE_BITS: u8 = 31;
Expand Down Expand Up @@ -229,14 +228,13 @@ impl fmt::Display for Hash {
}
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn proof_hash() {
let mut in_nonces: Vec<u64> = [0u64; 42].to_vec();
let mut in_nonces: Vec<u64> = [0u64; 42].to_vec();
let proof = Proof::new(in_nonces.clone(), DEFAULT_MIN_EDGE_BITS);
let hash_str = format!("{}", proof.hash());
println!("Hash is: {}", hash_str);
Expand Down Expand Up @@ -282,4 +280,3 @@ mod tests {
assert_eq!(difficulty, Difficulty::from_num(296303));
}
}

18 changes: 10 additions & 8 deletions cuckoo-miner/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use util::LOGGER;
use config::types::PluginConfig;
use miner::types::{JobSharedData, JobSharedDataType, SolverInstance};

use miner::util;
use miner::consensus::Proof;
use plugin::{SolverCtxWrapper, SolverSolutions, Solution, SolverStats};
use miner::util;
use plugin::{Solution, SolverCtxWrapper, SolverSolutions, SolverStats};
use {CuckooMinerError, PluginLibrary};

/// Miner control Messages
Expand Down Expand Up @@ -118,7 +118,10 @@ impl CuckooMiner {
let mut paused = true;
loop {
if let Some(message) = solver_loop_rx.try_iter().next() {
debug!(LOGGER, "solver_thread - solver_loop_rx got msg: {:?}", message);
debug!(
LOGGER,
"solver_thread - solver_loop_rx got msg: {:?}", message
);
match message {
ControlMessage::Stop => break,
ControlMessage::Pause => paused = true,
Expand Down Expand Up @@ -158,21 +161,20 @@ impl CuckooMiner {
s.stats[instance].iterations = iter_count;
if solver.solutions.num_sols > 0 {
// Filter solutions that don't meet difficulty check
let mut filtered_sols:Vec<Solution> = vec![];
let mut filtered_sols: Vec<Solution> = vec![];
for i in 0..solver.solutions.num_sols {
filtered_sols.push(solver.solutions.sols[i as usize]);
}
let mut filtered_sols: Vec<Solution> = filtered_sols.iter()
let mut filtered_sols: Vec<Solution> = filtered_sols
.iter()
.filter(|s| {
let proof = Proof {
edge_bits: solver.solutions.edge_bits as u8,
nonces: s.proof.to_vec(),
};
proof.to_difficulty_unscaled().to_num() >= target_difficulty
})
.map(|s| {
s.clone()
})
.map(|s| s.clone())
.collect();
for mut ss in filtered_sols.iter_mut() {
ss.nonce = nonce;
Expand Down
2 changes: 1 addition & 1 deletion cuckoo-miner/src/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![deny(unused_mut)]
#![warn(missing_docs)]

pub mod consensus;
pub mod miner;
pub mod types;
pub mod util;
pub mod consensus;
2 changes: 1 addition & 1 deletion cuckoo-miner/src/miner/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn header_data(pre_nonce: &str, post_nonce: &str, nonce: u64) -> (Vec<u8>, u
let mut pre_vec = from_hex_string(pre_nonce);
let mut post_vec = from_hex_string(post_nonce);

let sec_scaling_bytes = &pre_vec.clone()[pre_vec.len()-4..pre_vec.len()];
let sec_scaling_bytes = &pre_vec.clone()[pre_vec.len() - 4..pre_vec.len()];
let sec_scaling = BigEndian::read_u32(&sec_scaling_bytes);

let mut nonce_bytes = [0; 8];
Expand Down
Loading

0 comments on commit 846ff1d

Please sign in to comment.