Cleanup build warnings (#87)

* minor cleanup - unused imports
* cleanup build warnings - unused vars
* make structs pub to get rid of the private_in_public lint warning
* missing docs on RangeProof
* add missing docs to store delete function
* cleaned up deprecation warning -
tokio_core -> tokio_io
complete() -> send()
This commit is contained in:
AntiochP
2017-08-09 20:54:10 -04:00
committed by Ignotus Peverell
parent 131ea2f799
commit 3b4a48b2fd
48 changed files with 418 additions and 362 deletions
-1
View File
@@ -24,7 +24,6 @@ use core::{Input, Output, Proof, TxKernel, Transaction, COINBASE_KERNEL, COINBAS
use core::transaction::merkle_inputs_outputs;
use consensus::REWARD;
use consensus::MINIMUM_DIFFICULTY;
use consensus::PROOFSIZE;
use core::hash::{Hash, Hashed, ZERO_HASH};
use core::target::Difficulty;
use ser::{self, Readable, Reader, Writeable, Writer};
+4 -1
View File
@@ -83,7 +83,10 @@ pub trait Committed {
/// Proof of work
pub struct Proof {
/// The nonces
pub nonces:Vec<u32>,
/// The proof size
pub proof_size: usize,
}
@@ -124,7 +127,7 @@ impl Clone for Proof {
}
impl Proof {
/// Builds a proof with all bytes zeroed out
pub fn new(in_nonces:Vec<u32>) -> Proof {
Proof {
+14 -10
View File
@@ -38,7 +38,7 @@
use std::clone::Clone;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::{self, Deref};
use std::ops::{self};
use core::hash::{Hash, Hashed};
use ser::{self, Readable, Reader, Writeable, Writer};
@@ -96,11 +96,14 @@ impl<T> Summable for NoSum<T> {
/// of two HashSums is the (Hash(h1|h2), h1 + h2) HashSum.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HashSum<T> where T: Summable {
/// The hash
pub hash: Hash,
/// The sum
pub sum: T::Sum,
}
impl<T> HashSum<T> where T: Summable + Writeable {
/// Create a hash sum from a summable
pub fn from_summable(idx: u64, elmt: T) -> HashSum<T> {
let hash = Hashed::hash(&elmt);
let sum = elmt.sum();
@@ -156,7 +159,7 @@ pub trait Backend<T> where T: Summable {
/// Heavily relies on navigation operations within a binary tree. In particular,
/// all the implementation needs to keep track of the MMR structure is how far
/// we are in the sequence of nodes making up the MMR.
struct PMMR<T, B> where T: Summable, B: Backend<T> {
pub struct PMMR<T, B> where T: Summable, B: Backend<T> {
last_pos: u64,
backend: B,
// only needed for parameterizing Backend
@@ -179,7 +182,7 @@ impl<T, B> PMMR<T, B> where T: Summable + Writeable + Debug + Clone, B: Backend<
pub fn root(&self) -> HashSum<T> {
let peaks_pos = peaks(self.last_pos);
let peaks: Vec<Option<HashSum<T>>> = map_vec!(peaks_pos, |&pi| self.backend.get(pi));
let mut ret = None;
for peak in peaks {
ret = match (ret, peak) {
@@ -199,7 +202,7 @@ impl<T, B> PMMR<T, B> where T: Summable + Writeable + Debug + Clone, B: Backend<
let mut to_append = vec![current_hashsum.clone()];
let mut height = 0;
let mut pos = elmt_pos;
// we look ahead one position in the MMR, if the expected node has a higher
// height it means we have to build a higher peak by summing with a previous
// sibling. we do it iteratively in case the new peak itself allows the
@@ -231,13 +234,12 @@ impl<T, B> PMMR<T, B> where T: Summable + Writeable + Debug + Clone, B: Backend<
// only leaves can be pruned
return;
}
// loop going up the tree, from node to parent, as long as we stay inside
// the tree.
let mut to_prune = vec![];
let mut current = position;
while current+1 < self.last_pos {
let current_height = bintree_postorder_height(current);
let next_height = bintree_postorder_height(current+1);
// compare the node's height to the next height, if the next is higher
@@ -257,7 +259,7 @@ impl<T, B> PMMR<T, B> where T: Summable + Writeable + Debug + Clone, B: Backend<
// can't prune when our parent isn't here yet
break;
}
to_prune.push(current);
to_prune.push(current);
// if we have a pruned sibling, we can continue up the tree
// otherwise we're done
@@ -289,7 +291,7 @@ fn peaks(num: u64) -> Vec<u64> {
if bintree_postorder_height(num+1) > bintree_postorder_height(num) {
return vec![];
}
// our top peak is always on the leftmost side of the tree and leftmost trees
// have for index a binary values with all 1s (i.e. 11, 111, 1111, etc.)
let mut top = 1;
@@ -454,8 +456,10 @@ fn most_significant_pos(num: u64) -> u64 {
#[cfg(test)]
mod test {
use super::*;
use core::hash::{Hash, Hashed};
use core::hash::Hashed;
use std::sync::{Arc, Mutex};
use std::ops::Deref;
#[test]
fn some_all_ones() {
@@ -687,7 +691,7 @@ mod test {
pmmr.prune(1);
assert_eq!(orig_root, pmmr.root());
assert_eq!(ba.used_size(), orig_sz - 7);
// pruning everything should only leave us the peaks
for n in 1..16 {
pmmr.prune(n);
+1
View File
@@ -698,6 +698,7 @@ where
}
#[allow(dead_code)]
#[allow(missing_docs)]
pub fn print_tree<T>(tree: &SumTree<T>)
where
T: Summable + Writeable,
+2 -4
View File
@@ -21,11 +21,9 @@
use std::fmt;
use std::ops::{Add, Mul, Div, Sub};
use std::io::Cursor;
use std::u64::MAX;
use serde::{Serialize, Serializer, Deserialize, Deserializer, de};
use byteorder::{ByteOrder, ReadBytesExt, BigEndian};
use byteorder::{ByteOrder, BigEndian};
use core::hash::Hash;
use ser::{self, Reader, Writer, Writeable, Readable};
@@ -150,7 +148,7 @@ impl<'de> de::Visitor<'de> for DiffVisitor {
where E: de::Error
{
let num_in = s.parse::<u64>();
if let Err(e)=num_in {
if let Err(_)=num_in {
return Err(de::Error::invalid_value(de::Unexpected::Str(s), &"a value number"));
};
Ok(Difficulty { num: num_in.unwrap() })
-1
View File
@@ -18,7 +18,6 @@ use time;
use core;
use consensus::MINIMUM_DIFFICULTY;
use consensus::PROOFSIZE;
use core::hash::Hashed;
use core::target::Difficulty;
use global;
+10 -1
View File
@@ -28,14 +28,19 @@ use consensus::DEFAULT_SIZESHIFT;
/// Define these here, as they should be developer-set, not really tweakable
/// by users
/// Automated testing sizeshift
pub const AUTOMATED_TESTING_SIZESHIFT:u8 = 10;
/// Automated testing proof size
pub const AUTOMATED_TESTING_PROOF_SIZE:usize = 4;
/// User testing sizeshift
pub const USER_TESTING_SIZESHIFT:u8 = 16;
/// User testing proof size
pub const USER_TESTING_PROOF_SIZE:usize = 42;
/// Mining parameter modes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MiningParameterMode {
/// For CI testing
@@ -49,14 +54,17 @@ pub enum MiningParameterMode {
}
lazy_static!{
/// The mining parameter mode
pub static ref MINING_PARAMETER_MODE: RwLock<MiningParameterMode> = RwLock::new(MiningParameterMode::Production);
}
/// Set the mining mode
pub fn set_mining_mode(mode:MiningParameterMode){
let mut param_ref=MINING_PARAMETER_MODE.write().unwrap();
*param_ref=mode;
}
/// The sizeshift
pub fn sizeshift() -> u8 {
let param_ref=MINING_PARAMETER_MODE.read().unwrap();
match *param_ref {
@@ -66,6 +74,7 @@ pub fn sizeshift() -> u8 {
}
}
/// The proofsize
pub fn proofsize() -> usize {
let param_ref=MINING_PARAMETER_MODE.read().unwrap();
match *param_ref {
@@ -75,6 +84,7 @@ pub fn proofsize() -> usize {
}
}
/// Are we in automated testing mode?
pub fn is_automated_testing_mode() -> bool {
let param_ref=MINING_PARAMETER_MODE.read().unwrap();
if let MiningParameterMode::AutomatedTesting=*param_ref {
@@ -83,4 +93,3 @@ pub fn is_automated_testing_mode() -> bool {
return false;
}
}
+2
View File
@@ -39,6 +39,7 @@ macro_rules! try_map_vec {
/// Eliminates some of the verbosity in having iter and collect
/// around every fitler_map call.
#[macro_export]
macro_rules! filter_map_vec {
($thing:expr, $mapfn:expr ) => {
$thing.iter()
@@ -52,6 +53,7 @@ macro_rules! filter_map_vec {
/// Example:
/// let foo = vec![1,2,3]
/// println!(tee!(foo, foo.append(vec![3,4,5]))
#[macro_export]
macro_rules! tee {
($thing:ident, $thing_expr:expr) => {
{
+7 -6
View File
@@ -31,8 +31,6 @@ use consensus::EASINESS;
use core::BlockHeader;
use core::hash::Hashed;
use core::Proof;
use global;
use global::{MiningParameterMode, MINING_PARAMETER_MODE};
use core::target::Difficulty;
use pow::cuckoo::{Cuckoo, Error};
@@ -41,10 +39,10 @@ use pow::cuckoo::{Cuckoo, Error};
///
pub trait MiningWorker {
/// This only sets parameters and does initialisation work now
fn new(ease: u32, sizeshift: u32, proof_size:usize) -> Self;
/// Actually perform a mining attempt on the given input and
/// return a proof if found
fn mine(&mut self, header: &[u8]) -> Result<Proof, Error>;
@@ -70,8 +68,8 @@ pub fn pow20<T: MiningWorker>(miner:&mut T, bh: &mut BlockHeader, diff: Difficul
/// Runs a proof of work computation over the provided block using the provided Mining Worker,
/// until the required difficulty target is reached. May take a while for a low target...
pub fn pow_size<T: MiningWorker>(miner:&mut T, bh: &mut BlockHeader,
diff: Difficulty, sizeshift: u32) -> Result<(), Error> {
pub fn pow_size<T: MiningWorker>(miner:&mut T, bh: &mut BlockHeader,
diff: Difficulty, _: u32) -> Result<(), Error> {
let start_nonce = bh.nonce;
// try to find a cuckoo cycle on that header hash
@@ -104,9 +102,12 @@ pub fn pow_size<T: MiningWorker>(miner:&mut T, bh: &mut BlockHeader,
#[cfg(test)]
mod test {
use super::*;
use global;
use core::target::Difficulty;
use genesis;
use consensus::MINIMUM_DIFFICULTY;
use global::MiningParameterMode;
#[test]
fn genesis_pow() {
+1
View File
@@ -388,6 +388,7 @@ impl Writeable for [u8; 4] {
/// Useful marker trait on types that can be sized byte slices
pub trait AsFixedBytes: Sized + AsRef<[u8]> {
/// The length in bytes
fn len(&self) -> usize;
}