Fix typos and unused imports (#1466)

* Fix typos and unused imports
This commit is contained in:
Quentin Le Sceller 2018-09-03 13:09:28 +02:00 committed by GitHub
parent eae0ab6b2a
commit 544a296f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 58 additions and 62 deletions

View file

@ -865,7 +865,7 @@ pub fn start_rest_apis(
ROUTER.with(|router| { ROUTER.with(|router| {
*router.borrow_mut() = *router.borrow_mut() =
Some(build_router(chain, tx_pool, peers).expect("unbale to build API router")); Some(build_router(chain, tx_pool, peers).expect("unable to build API router"));
info!(LOGGER, "Starting HTTP API server at {}.", addr); info!(LOGGER, "Starting HTTP API server at {}.", addr);
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address"); let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address");

View file

@ -577,7 +577,7 @@ impl<'a> Extension<'a> {
let cutoff_header = self.commit_index.get_header_by_height(cutoff_height)?; let cutoff_header = self.commit_index.get_header_by_height(cutoff_height)?;
let cutoff_pos = cutoff_header.output_mmr_size; let cutoff_pos = cutoff_header.output_mmr_size;
// If any output pos exceeed the cutoff_pos // If any output pos exceed the cutoff_pos
// we know they have not yet sufficiently matured. // we know they have not yet sufficiently matured.
if pos > cutoff_pos { if pos > cutoff_pos {
return Err(ErrorKind::ImmatureCoinbase.into()); return Err(ErrorKind::ImmatureCoinbase.into());

View file

@ -15,7 +15,7 @@
//! Comments for configuration + injection into output .toml //! Comments for configuration + injection into output .toml
use std::collections::HashMap; use std::collections::HashMap;
/// maps entries to Comments that should preceed them /// maps entries to Comments that should precede them
fn comments() -> HashMap<String, String> { fn comments() -> HashMap<String, String> {
let mut retval = HashMap::new(); let mut retval = HashMap::new();
retval.insert( retval.insert(

View file

@ -89,7 +89,7 @@ pub const BLOCK_KERNEL_WEIGHT: usize = 2;
/// ///
/// Given that a block needs to have at least one kernel for the coinbase, /// Given that a block needs to have at least one kernel for the coinbase,
/// and one kernel for the transaction, practical maximum size is 2_831_440, /// and one kernel for the transaction, practical maximum size is 2_831_440,
/// (ignoring the edge case of a miner producting a block with all coinbase /// (ignoring the edge case of a miner producing a block with all coinbase
/// outputs and a single kernel). /// outputs and a single kernel).
/// ///
/// A more "standard" block, filled with transactions of 2 inputs, 2 outputs /// A more "standard" block, filled with transactions of 2 inputs, 2 outputs

View file

@ -82,7 +82,7 @@ impl MerkleProof {
util::to_hex(vec) util::to_hex(vec)
} }
/// Convert hex string represenation back to a Merkle proof instance /// Convert hex string representation back to a Merkle proof instance
pub fn from_hex(hex: &str) -> Result<MerkleProof, String> { pub fn from_hex(hex: &str) -> Result<MerkleProof, String> {
let bytes = util::from_hex(hex.to_string()).unwrap(); let bytes = util::from_hex(hex.to_string()).unwrap();
let res = ser::deserialize(&mut &bytes[..]) let res = ser::deserialize(&mut &bytes[..])

View file

@ -285,7 +285,7 @@ where
/// "undo". /// "undo".
pub fn rewind(&mut self, position: u64, rewind_rm_pos: &Bitmap) -> Result<(), String> { pub fn rewind(&mut self, position: u64, rewind_rm_pos: &Bitmap) -> Result<(), String> {
// Identify which actual position we should rewind to as the provided // Identify which actual position we should rewind to as the provided
// position is a leaf. We traverse the MMR to inclue any parent(s) that // position is a leaf. We traverse the MMR to include any parent(s) that
// need to be included for the MMR to be valid. // need to be included for the MMR to be valid.
let mut pos = position; let mut pos = position;
while bintree_postorder_height(pos + 1) > 0 { while bintree_postorder_height(pos + 1) > 0 {

View file

@ -42,7 +42,7 @@ impl Difficulty {
Difficulty { num: 0 } Difficulty { num: 0 }
} }
/// Difficulty of one, which is the minumum difficulty /// Difficulty of one, which is the minimum difficulty
/// (when the hash equals the max target) /// (when the hash equals the max target)
pub fn one() -> Difficulty { pub fn one() -> Difficulty {
Difficulty { num: 1 } Difficulty { num: 1 }

View file

@ -203,7 +203,7 @@ pub fn get_genesis_nonce() -> u64 {
} }
} }
/// Converts an iterator of block difficulty data to more a more mangeable /// Converts an iterator of block difficulty data to more a more manageable
/// vector and pads if needed (which will) only be needed for the first few /// vector and pads if needed (which will) only be needed for the first few
/// blocks after genesis /// blocks after genesis

View file

@ -16,13 +16,14 @@
extern crate grin_core as core; extern crate grin_core as core;
extern crate chrono; extern crate chrono;
use core::consensus::{next_difficulty, valid_header_version, TargetError, use chrono::prelude::Utc;
DIFFICULTY_ADJUST_WINDOW, MEDIAN_TIME_WINDOW, use core::consensus::{
UPPER_TIME_BOUND, BLOCK_TIME_WINDOW, DAMP_FACTOR, MEDIAN_TIME_INDEX}; next_difficulty, valid_header_version, TargetError, BLOCK_TIME_WINDOW, DAMP_FACTOR,
DIFFICULTY_ADJUST_WINDOW, MEDIAN_TIME_INDEX, MEDIAN_TIME_WINDOW, UPPER_TIME_BOUND,
};
use core::core::target::Difficulty; use core::core::target::Difficulty;
use std::fmt::{self, Display};
use chrono::prelude::{Utc};
use core::global; use core::global;
use std::fmt::{self, Display};
/// Last n blocks for difficulty calculation purposes /// Last n blocks for difficulty calculation purposes
/// (copied from stats in server crate) /// (copied from stats in server crate)
@ -58,11 +59,10 @@ pub struct DiffStats {
pub block_diff_sum: u64, pub block_diff_sum: u64,
/// latest ts /// latest ts
pub latest_ts: u64, pub latest_ts: u64,
/// earlist ts /// earliest ts
pub earliest_ts: u64, pub earliest_ts: u64,
/// ts delta /// ts delta
pub ts_delta: u64, pub ts_delta: u64,
} }
impl Display for DiffBlock { impl Display for DiffBlock {
@ -98,20 +98,21 @@ fn repeat(
} }
// Creates a new chain with a genesis at a simulated difficulty // Creates a new chain with a genesis at a simulated difficulty
fn create_chain_sim(diff: u64) fn create_chain_sim(diff: u64) -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> {
-> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> {
println!( println!(
"adding create: {}, {}", "adding create: {}, {}",
Utc::now().timestamp(), Utc::now().timestamp(),
Difficulty::from_num(diff) Difficulty::from_num(diff)
); );
let return_vec = vec![ let return_vec = vec![Ok((
Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))), Utc::now().timestamp() as u64,
]; Difficulty::from_num(diff),
))];
let diff_stats = get_diff_stats(&return_vec); let diff_stats = get_diff_stats(&return_vec);
vec![ vec![(
(Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))), diff_stats), Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))),
] diff_stats,
)]
} }
fn get_diff_stats(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) -> DiffStats { fn get_diff_stats(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) -> DiffStats {
@ -126,7 +127,8 @@ fn get_diff_stats(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) -> Di
// Obtain the median window for the earlier time period // Obtain the median window for the earlier time period
// the first MEDIAN_TIME_WINDOW elements // the first MEDIAN_TIME_WINDOW elements
let mut window_earliest: Vec<u64> = last_blocks.clone() let mut window_earliest: Vec<u64> = last_blocks
.clone()
.iter() .iter()
.take(MEDIAN_TIME_WINDOW as usize) .take(MEDIAN_TIME_WINDOW as usize)
.map(|n| n.clone().unwrap().0) .map(|n| n.clone().unwrap().0)
@ -137,7 +139,8 @@ fn get_diff_stats(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) -> Di
// Obtain the median window for the latest time period // Obtain the median window for the latest time period
// i.e. the last MEDIAN_TIME_WINDOW elements // i.e. the last MEDIAN_TIME_WINDOW elements
let mut window_latest: Vec<u64> = last_blocks.clone() let mut window_latest: Vec<u64> = last_blocks
.clone()
.iter() .iter()
.skip(DIFFICULTY_ADJUST_WINDOW as usize) .skip(DIFFICULTY_ADJUST_WINDOW as usize)
.map(|n| n.clone().unwrap().0) .map(|n| n.clone().unwrap().0)
@ -148,9 +151,9 @@ fn get_diff_stats(chain_sim: &Vec<Result<(u64, Difficulty), TargetError>>) -> Di
let mut i = 1; let mut i = 1;
let sum_blocks: Vec<Result<(u64, Difficulty), TargetError>> = let sum_blocks: Vec<Result<(u64, Difficulty), TargetError>> = global::difficulty_data_to_vector(
global::difficulty_data_to_vector(diff_iter) diff_iter,
.into_iter() ).into_iter()
.skip(MEDIAN_TIME_WINDOW as usize) .skip(MEDIAN_TIME_WINDOW as usize)
.take(DIFFICULTY_ADJUST_WINDOW as usize) .take(DIFFICULTY_ADJUST_WINDOW as usize)
.collect(); .collect();
@ -218,9 +221,8 @@ fn add_block(
chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>, chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>,
) -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> { ) -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> {
let mut ret_chain_sim = chain_sim.clone(); let mut ret_chain_sim = chain_sim.clone();
let mut return_chain: Vec<(Result<(u64, Difficulty), TargetError>)> = chain_sim.clone().iter() let mut return_chain: Vec<(Result<(u64, Difficulty), TargetError>)> =
.map(|e| e.0.clone()) chain_sim.clone().iter().map(|e| e.0.clone()).collect();
.collect();
// get last interval // get last interval
let diff = next_difficulty(return_chain.clone()).unwrap(); let diff = next_difficulty(return_chain.clone()).unwrap();
let last_elem = chain_sim.first().as_ref().unwrap().0.as_ref().unwrap(); let last_elem = chain_sim.first().as_ref().unwrap().0.as_ref().unwrap();
@ -258,9 +260,7 @@ fn add_block_repeated(
// Prints the contents of the iterator and its difficulties.. useful for // Prints the contents of the iterator and its difficulties.. useful for
// tweaking // tweaking
fn print_chain_sim( fn print_chain_sim(chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>) {
chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>
){
let mut chain_sim = chain_sim.clone(); let mut chain_sim = chain_sim.clone();
chain_sim.reverse(); chain_sim.reverse();
let mut last_time = 0; let mut last_time = 0;
@ -307,13 +307,12 @@ fn repeat_offs(
diff: u64, diff: u64,
len: u64, len: u64,
) -> Vec<Result<(u64, Difficulty), TargetError>> { ) -> Vec<Result<(u64, Difficulty), TargetError>> {
map_vec!( map_vec!(repeat(interval, diff, len, Some(from)), |e| {
repeat(interval, diff, len, Some(from)), match e.clone() {
|e| match e.clone() {
Err(e) => Err(e), Err(e) => Err(e),
Ok((t, d)) => Ok((t, d)), Ok((t, d)) => Ok((t, d)),
} }
) })
} }
/// Checks different next_target adjustments and difficulty boundaries /// Checks different next_target adjustments and difficulty boundaries

View file

@ -419,7 +419,7 @@ fn pmmr_prune() {
assert_eq!(ba.elems.len(), 16); assert_eq!(ba.elems.len(), 16);
assert_eq!(ba.remove_list.len(), 4); assert_eq!(ba.remove_list.len(), 4);
// TODO - no longeer true (leaves only now) - pruning all leaves under level >1 // TODO - no longer true (leaves only now) - pruning all leaves under level >1
// removes all subtree // removes all subtree
{ {
let mut pmmr: PMMR<TestElem, _> = PMMR::at(&mut ba, sz); let mut pmmr: PMMR<TestElem, _> = PMMR::at(&mut ba, sz);

View file

@ -54,7 +54,7 @@ can be used to construct a variety of contracts using "simple" arithmetic.
## (Absolute) Timelocked Transactions ## (Absolute) Timelocked Transactions
Analogus to Bitcoin [nLockTime](https://en.bitcoin.it/wiki/Timelock#nLockTime). Analogous to Bitcoin [nLockTime](https://en.bitcoin.it/wiki/Timelock#nLockTime).
A transaction can be time-locked with a few simple modifications: A transaction can be time-locked with a few simple modifications:
@ -250,7 +250,7 @@ can compute `sr' - sr` to get `x`.
### Notes on the Bitcoin setup ### Notes on the Bitcoin setup
Prior to completing the atomic swap, Bob needs to know Alice's public key. Bob Prior to completing the atomic swap, Bob needs to know Alice's public key. Bob
would then create an outpout on the Bitcoin blockchain with a 2-of-2 multisig would then create an output on the Bitcoin blockchain with a 2-of-2 multisig
similar to `alice_pubkey secret_pubkey 2 OP_CHECKMULTISIG`. This should be similar to `alice_pubkey secret_pubkey 2 OP_CHECKMULTISIG`. This should be
wrapped in an `OP_IF` so Bob can get his money back after an agreed-upon time wrapped in an `OP_IF` so Bob can get his money back after an agreed-upon time
and all of this can even be wrapped in a P2SH. Here `secret_pubkey` is `x*G` and all of this can even be wrapped in a P2SH. Here `secret_pubkey` is `x*G`

View file

@ -428,7 +428,6 @@ only by adding or removing an output. Doing so would cause the summation of all
blinding factors in the transaction kernels to differ from the summation of blinding blinding factors in the transaction kernels to differ from the summation of blinding
factors in the outputs. factors in the outputs.
## Conclusion ## Conclusion
In this document we covered the basic principles that underlie a MimbleWimble In this document we covered the basic principles that underlie a MimbleWimble

View file

@ -26,7 +26,7 @@ further technical details.
There is also a [podcast with Mike from Monero Monitor](https://moneromonitor.com/episodes/2017-09-26-Episode-014.html) There is also a [podcast with Mike from Monero Monitor](https://moneromonitor.com/episodes/2017-09-26-Episode-014.html)
in which John Tromp talks at length about Cuckoo Cycle; recommended listening for anyone wanting in which John Tromp talks at length about Cuckoo Cycle; recommended listening for anyone wanting
more background on Cuckoo Cycle, including more technical detail, the history of the algorihm's development more background on Cuckoo Cycle, including more technical detail, the history of the algorithm's development
and some of the motivations behind it. and some of the motivations behind it.
## Cycles in a Graph ## Cycles in a Graph

View file

@ -57,7 +57,7 @@ spend any generated outputs. The password is specified with `-p`
## Basic Wallet Commands ## Basic Wallet Commands
`grin wallet --help` will display usage info and all flags. `grin wallet --help` will display usage info and all flags.
`grin wallet help [command]` will deplay flags specific to the command, e.g `grin wallet help listen` `grin wallet help [command]` will display flags specific to the command, e.g `grin wallet help listen`
### init ### init

View file

@ -355,7 +355,7 @@ fn headers_streaming_body(
msg_len: u64, // (i) length of whole 'Headers' msg_len: u64, // (i) length of whole 'Headers'
headers_num: u64, // (i) how many BlockHeader(s) do you want to read headers_num: u64, // (i) how many BlockHeader(s) do you want to read
total_read: &mut u64, // (i/o) how many bytes already read on this 'Headers' message total_read: &mut u64, // (i/o) how many bytes already read on this 'Headers' message
reserved: &mut Vec<u8>, // (i/o) reserved part of previous read, which's not a whole header reserved: &mut Vec<u8>, // (i/o) reserved part of previous read, which is not a whole header
max_header_size: u64, // (i) maximum possible size of single BlockHeader max_header_size: u64, // (i) maximum possible size of single BlockHeader
) -> Result<Headers, Error> { ) -> Result<Headers, Error> {
if headers_num == 0 || msg_len < *total_read || *total_read < 2 { if headers_num == 0 || msg_len < *total_read || *total_read < 2 {

View file

@ -138,7 +138,7 @@ pub struct PeerStats {
pub addr: String, pub addr: String,
/// version running /// version running
pub version: u32, pub version: u32,
/// difficulty repored by peer /// difficulty reported by peer
pub total_difficulty: u64, pub total_difficulty: u64,
/// height reported by peer on ping /// height reported by peer on ping
pub height: u64, pub height: u64,

View file

@ -131,9 +131,9 @@ fn simple_server_wallet() {
assert!(last_10_rangeproofs.is_ok()); assert!(last_10_rangeproofs.is_ok());
let last_5_rangeproofs = get_txhashset_lastrangeproofs(&base_addr, api_server_port, 5); let last_5_rangeproofs = get_txhashset_lastrangeproofs(&base_addr, api_server_port, 5);
assert!(last_5_rangeproofs.is_ok()); assert!(last_5_rangeproofs.is_ok());
let last_10_kernels = gettxhashset_lastkernels(&base_addr, api_server_port, 0); let last_10_kernels = get_txhashset_lastkernels(&base_addr, api_server_port, 0);
assert!(last_10_kernels.is_ok()); assert!(last_10_kernels.is_ok());
let last_5_kernels = gettxhashset_lastkernels(&base_addr, api_server_port, 5); let last_5_kernels = get_txhashset_lastkernels(&base_addr, api_server_port, 5);
assert!(last_5_kernels.is_ok()); assert!(last_5_kernels.is_ok());
//let some more mining happen, make sure nothing pukes //let some more mining happen, make sure nothing pukes
@ -392,7 +392,7 @@ fn get_txhashset_lastrangeproofs(
api::client::get::<Vec<api::TxHashSetNode>>(url.as_str()).map_err(|e| Error::API(e)) api::client::get::<Vec<api::TxHashSetNode>>(url.as_str()).map_err(|e| Error::API(e))
} }
fn gettxhashset_lastkernels( fn get_txhashset_lastkernels(
base_addr: &String, base_addr: &String,
api_server_port: u16, api_server_port: u16,
n: u64, n: u64,

View file

@ -70,7 +70,7 @@ pub struct LocalServerContainerConfig {
// Whether we're going to mine // Whether we're going to mine
pub start_miner: bool, pub start_miner: bool,
// time in millis by which to artifically slow down the mining loop // time in millis by which to artificially slow down the mining loop
// in this container // in this container
pub miner_slowdown_in_millis: u64, pub miner_slowdown_in_millis: u64,
@ -265,7 +265,7 @@ impl LocalServerContainer {
let client = HTTPWalletClient::new(&self.wallet_config.check_node_api_http_addr); let client = HTTPWalletClient::new(&self.wallet_config.check_node_api_http_addr);
if let Err(e) = r { if let Err(e) = r {
//panic!("Error initting wallet seed: {}", e); //panic!("Error initializing wallet seed: {}", e);
} }
let wallet: FileWallet<HTTPWalletClient, keychain::ExtKeychain> = let wallet: FileWallet<HTTPWalletClient, keychain::ExtKeychain> =

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
/// Grin configuation file output command /// Grin configuration file output command
use config::{GlobalConfig, GlobalWalletConfig}; use config::{GlobalConfig, GlobalWalletConfig};
use std::env; use std::env;

View file

@ -24,10 +24,8 @@ use clap::ArgMatches;
use ctrlc; use ctrlc;
use daemonize::Daemonize; use daemonize::Daemonize;
use cmd::wallet;
use config::GlobalConfig; use config::GlobalConfig;
use core::global; use core::global;
use grin_wallet::controller;
use p2p::Seeding; use p2p::Seeding;
use servers; use servers;
use tui::ui; use tui::ui;

View file

@ -92,7 +92,7 @@ where
res res
} }
/// Attempt to update outputs and retrieve tranasactions /// Attempt to update outputs and retrieve transactions
/// Return (whether the outputs were validated against a node, OutputData) /// Return (whether the outputs were validated against a node, OutputData)
pub fn retrieve_txs( pub fn retrieve_txs(
&self, &self,

View file

@ -283,7 +283,7 @@ where
pub struct LocalWalletClient { pub struct LocalWalletClient {
/// wallet identifier for the proxy queue /// wallet identifier for the proxy queue
pub id: String, pub id: String,
/// proxy's tx queue (receive messsages from other wallets or node /// proxy's tx queue (receive messages from other wallets or node
pub proxy_tx: Arc<Mutex<Sender<WalletProxyMessage>>>, pub proxy_tx: Arc<Mutex<Sender<WalletProxyMessage>>>,
/// my rx queue /// my rx queue
pub rx: Arc<Mutex<Receiver<WalletProxyMessage>>>, pub rx: Arc<Mutex<Receiver<WalletProxyMessage>>>,