From 544a296f77f9de1abba6774464af31c78331bad3 Mon Sep 17 00:00:00 2001 From: Quentin Le Sceller Date: Mon, 3 Sep 2018 13:09:28 +0200 Subject: [PATCH] Fix typos and unused imports (#1466) * Fix typos and unused imports --- api/src/handlers.rs | 2 +- chain/src/txhashset.rs | 2 +- config/src/comments.rs | 2 +- core/src/consensus.rs | 2 +- core/src/core/merkle_proof.rs | 4 +- core/src/core/pmmr.rs | 2 +- core/src/core/target.rs | 2 +- core/src/global.rs | 2 +- core/tests/consensus.rs | 69 +++++++++++++++---------------- core/tests/pmmr.rs | 2 +- doc/contracts.md | 4 +- doc/intro.md | 1 - doc/pow/pow.md | 2 +- doc/wallet/usage.md | 2 +- p2p/src/protocol.rs | 2 +- servers/src/common/stats.rs | 2 +- servers/tests/api.rs | 6 +-- servers/tests/framework/mod.rs | 4 +- src/bin/cmd/config.rs | 2 +- src/bin/cmd/server.rs | 2 - wallet/src/libwallet/api.rs | 2 +- wallet/tests/common/testclient.rs | 2 +- 22 files changed, 58 insertions(+), 62 deletions(-) diff --git a/api/src/handlers.rs b/api/src/handlers.rs index aa0675609..2b401ad47 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -865,7 +865,7 @@ pub fn start_rest_apis( ROUTER.with(|router| { *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); let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address"); diff --git a/chain/src/txhashset.rs b/chain/src/txhashset.rs index 2b13e6a80..e5bd27db4 100644 --- a/chain/src/txhashset.rs +++ b/chain/src/txhashset.rs @@ -577,7 +577,7 @@ impl<'a> Extension<'a> { let cutoff_header = self.commit_index.get_header_by_height(cutoff_height)?; 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. if pos > cutoff_pos { return Err(ErrorKind::ImmatureCoinbase.into()); diff --git a/config/src/comments.rs b/config/src/comments.rs index 8050fd5f6..2225dc2b1 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -15,7 +15,7 @@ //! Comments for configuration + injection into output .toml use std::collections::HashMap; -/// maps entries to Comments that should preceed them +/// maps entries to Comments that should precede them fn comments() -> HashMap { let mut retval = HashMap::new(); retval.insert( diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 770b7d329..58c6db9b0 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -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, /// 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). /// /// A more "standard" block, filled with transactions of 2 inputs, 2 outputs diff --git a/core/src/core/merkle_proof.rs b/core/src/core/merkle_proof.rs index 7e1a18aef..78a93d847 100644 --- a/core/src/core/merkle_proof.rs +++ b/core/src/core/merkle_proof.rs @@ -82,7 +82,7 @@ impl MerkleProof { 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 { let bytes = util::from_hex(hex.to_string()).unwrap(); let res = ser::deserialize(&mut &bytes[..]) @@ -106,7 +106,7 @@ impl MerkleProof { } /// Consumes the Merkle proof while verifying it. - /// The proof can no longer beused by the caller after dong this. + /// The proof can no longer be used by the caller after dong this. /// Caller must clone() the proof first. fn verify_consume( &mut self, diff --git a/core/src/core/pmmr.rs b/core/src/core/pmmr.rs index cbebc3e74..21717bd77 100644 --- a/core/src/core/pmmr.rs +++ b/core/src/core/pmmr.rs @@ -285,7 +285,7 @@ where /// "undo". pub fn rewind(&mut self, position: u64, rewind_rm_pos: &Bitmap) -> Result<(), String> { // 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. let mut pos = position; while bintree_postorder_height(pos + 1) > 0 { diff --git a/core/src/core/target.rs b/core/src/core/target.rs index c4cff40a2..654fbc45e 100644 --- a/core/src/core/target.rs +++ b/core/src/core/target.rs @@ -42,7 +42,7 @@ impl Difficulty { 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) pub fn one() -> Difficulty { Difficulty { num: 1 } diff --git a/core/src/global.rs b/core/src/global.rs index f01e4eaa2..357c05cd9 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -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 /// blocks after genesis diff --git a/core/tests/consensus.rs b/core/tests/consensus.rs index f34d2799b..ddc9b217a 100644 --- a/core/tests/consensus.rs +++ b/core/tests/consensus.rs @@ -16,13 +16,14 @@ extern crate grin_core as core; extern crate chrono; -use core::consensus::{next_difficulty, valid_header_version, TargetError, - DIFFICULTY_ADJUST_WINDOW, MEDIAN_TIME_WINDOW, - UPPER_TIME_BOUND, BLOCK_TIME_WINDOW, DAMP_FACTOR, MEDIAN_TIME_INDEX}; +use chrono::prelude::Utc; +use core::consensus::{ + 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 std::fmt::{self, Display}; -use chrono::prelude::{Utc}; use core::global; +use std::fmt::{self, Display}; /// Last n blocks for difficulty calculation purposes /// (copied from stats in server crate) @@ -58,11 +59,10 @@ pub struct DiffStats { pub block_diff_sum: u64, /// latest ts pub latest_ts: u64, - /// earlist ts + /// earliest ts pub earliest_ts: u64, /// ts delta pub ts_delta: u64, - } impl Display for DiffBlock { @@ -98,20 +98,21 @@ fn repeat( } // Creates a new chain with a genesis at a simulated difficulty -fn create_chain_sim(diff: u64) - -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> { +fn create_chain_sim(diff: u64) -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> { println!( "adding create: {}, {}", Utc::now().timestamp(), Difficulty::from_num(diff) ); - let return_vec = vec![ - Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))), - ]; + let return_vec = vec![Ok(( + Utc::now().timestamp() as u64, + Difficulty::from_num(diff), + ))]; let diff_stats = get_diff_stats(&return_vec); - vec![ - (Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))), diff_stats), - ] + vec![( + Ok((Utc::now().timestamp() as u64, Difficulty::from_num(diff))), + diff_stats, + )] } fn get_diff_stats(chain_sim: &Vec>) -> DiffStats { @@ -126,7 +127,8 @@ fn get_diff_stats(chain_sim: &Vec>) -> Di // Obtain the median window for the earlier time period // the first MEDIAN_TIME_WINDOW elements - let mut window_earliest: Vec = last_blocks.clone() + let mut window_earliest: Vec = last_blocks + .clone() .iter() .take(MEDIAN_TIME_WINDOW as usize) .map(|n| n.clone().unwrap().0) @@ -137,7 +139,8 @@ fn get_diff_stats(chain_sim: &Vec>) -> Di // Obtain the median window for the latest time period // i.e. the last MEDIAN_TIME_WINDOW elements - let mut window_latest: Vec = last_blocks.clone() + let mut window_latest: Vec = last_blocks + .clone() .iter() .skip(DIFFICULTY_ADJUST_WINDOW as usize) .map(|n| n.clone().unwrap().0) @@ -147,13 +150,13 @@ fn get_diff_stats(chain_sim: &Vec>) -> Di let latest_ts = window_latest[MEDIAN_TIME_INDEX as usize]; let mut i = 1; - - let sum_blocks: Vec> = - global::difficulty_data_to_vector(diff_iter) - .into_iter() - .skip(MEDIAN_TIME_WINDOW as usize) - .take(DIFFICULTY_ADJUST_WINDOW as usize) - .collect(); + + let sum_blocks: Vec> = global::difficulty_data_to_vector( + diff_iter, + ).into_iter() + .skip(MEDIAN_TIME_WINDOW as usize) + .take(DIFFICULTY_ADJUST_WINDOW as usize) + .collect(); let sum_entries: Vec = sum_blocks .iter() @@ -207,7 +210,7 @@ fn get_diff_stats(chain_sim: &Vec>) -> Di block_diff_sum: block_diff_sum, latest_ts: latest_ts, earliest_ts: earliest_ts, - ts_delta: latest_ts-earliest_ts, + ts_delta: latest_ts - earliest_ts, } } @@ -218,9 +221,8 @@ fn add_block( chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>, ) -> Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> { let mut ret_chain_sim = chain_sim.clone(); - let mut return_chain: Vec<(Result<(u64, Difficulty), TargetError>)> = chain_sim.clone().iter() - .map(|e| e.0.clone()) - .collect(); + let mut return_chain: Vec<(Result<(u64, Difficulty), TargetError>)> = + chain_sim.clone().iter().map(|e| e.0.clone()).collect(); // get last interval let diff = next_difficulty(return_chain.clone()).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 // tweaking -fn print_chain_sim( - chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)> -){ +fn print_chain_sim(chain_sim: Vec<((Result<(u64, Difficulty), TargetError>), DiffStats)>) { let mut chain_sim = chain_sim.clone(); chain_sim.reverse(); let mut last_time = 0; @@ -307,13 +307,12 @@ fn repeat_offs( diff: u64, len: u64, ) -> Vec> { - map_vec!( - repeat(interval, diff, len, Some(from)), - |e| match e.clone() { + map_vec!(repeat(interval, diff, len, Some(from)), |e| { + match e.clone() { Err(e) => Err(e), Ok((t, d)) => Ok((t, d)), } - ) + }) } /// Checks different next_target adjustments and difficulty boundaries diff --git a/core/tests/pmmr.rs b/core/tests/pmmr.rs index 32bba2740..5a1c0e568 100644 --- a/core/tests/pmmr.rs +++ b/core/tests/pmmr.rs @@ -419,7 +419,7 @@ fn pmmr_prune() { assert_eq!(ba.elems.len(), 16); 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 { let mut pmmr: PMMR = PMMR::at(&mut ba, sz); diff --git a/doc/contracts.md b/doc/contracts.md index bcdd9ea71..28b2800e4 100644 --- a/doc/contracts.md +++ b/doc/contracts.md @@ -54,7 +54,7 @@ can be used to construct a variety of contracts using "simple" arithmetic. ## (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: @@ -250,7 +250,7 @@ can compute `sr' - sr` to get `x`. ### Notes on the Bitcoin setup 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 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` diff --git a/doc/intro.md b/doc/intro.md index 8cb6bab86..ecccc087d 100644 --- a/doc/intro.md +++ b/doc/intro.md @@ -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 factors in the outputs. - ## Conclusion In this document we covered the basic principles that underlie a MimbleWimble diff --git a/doc/pow/pow.md b/doc/pow/pow.md index 54aa461d7..fc663bd2a 100644 --- a/doc/pow/pow.md +++ b/doc/pow/pow.md @@ -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) 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. ## Cycles in a Graph diff --git a/doc/wallet/usage.md b/doc/wallet/usage.md index 37758bda1..e4f94d549 100644 --- a/doc/wallet/usage.md +++ b/doc/wallet/usage.md @@ -57,7 +57,7 @@ spend any generated outputs. The password is specified with `-p` ## Basic Wallet Commands `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 diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index b9a1a2f41..89a791604 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -355,7 +355,7 @@ fn headers_streaming_body( msg_len: u64, // (i) length of whole 'Headers' 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 - reserved: &mut Vec, // (i/o) reserved part of previous read, which's not a whole header + reserved: &mut Vec, // (i/o) reserved part of previous read, which is not a whole header max_header_size: u64, // (i) maximum possible size of single BlockHeader ) -> Result { if headers_num == 0 || msg_len < *total_read || *total_read < 2 { diff --git a/servers/src/common/stats.rs b/servers/src/common/stats.rs index 6c9368aea..ef7d94979 100644 --- a/servers/src/common/stats.rs +++ b/servers/src/common/stats.rs @@ -138,7 +138,7 @@ pub struct PeerStats { pub addr: String, /// version running pub version: u32, - /// difficulty repored by peer + /// difficulty reported by peer pub total_difficulty: u64, /// height reported by peer on ping pub height: u64, diff --git a/servers/tests/api.rs b/servers/tests/api.rs index 3d06d83b0..08a130a32 100644 --- a/servers/tests/api.rs +++ b/servers/tests/api.rs @@ -131,9 +131,9 @@ fn simple_server_wallet() { assert!(last_10_rangeproofs.is_ok()); let last_5_rangeproofs = get_txhashset_lastrangeproofs(&base_addr, api_server_port, 5); 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()); - 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()); //let some more mining happen, make sure nothing pukes @@ -392,7 +392,7 @@ fn get_txhashset_lastrangeproofs( api::client::get::>(url.as_str()).map_err(|e| Error::API(e)) } -fn gettxhashset_lastkernels( +fn get_txhashset_lastkernels( base_addr: &String, api_server_port: u16, n: u64, diff --git a/servers/tests/framework/mod.rs b/servers/tests/framework/mod.rs index fc1190a56..898903226 100644 --- a/servers/tests/framework/mod.rs +++ b/servers/tests/framework/mod.rs @@ -70,7 +70,7 @@ pub struct LocalServerContainerConfig { // Whether we're going to mine 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 pub miner_slowdown_in_millis: u64, @@ -265,7 +265,7 @@ impl LocalServerContainer { let client = HTTPWalletClient::new(&self.wallet_config.check_node_api_http_addr); if let Err(e) = r { - //panic!("Error initting wallet seed: {}", e); + //panic!("Error initializing wallet seed: {}", e); } let wallet: FileWallet = diff --git a/src/bin/cmd/config.rs b/src/bin/cmd/config.rs index 3e993244f..912885864 100644 --- a/src/bin/cmd/config.rs +++ b/src/bin/cmd/config.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/// Grin configuation file output command +/// Grin configuration file output command use config::{GlobalConfig, GlobalWalletConfig}; use std::env; diff --git a/src/bin/cmd/server.rs b/src/bin/cmd/server.rs index 6525feca0..ac3029692 100644 --- a/src/bin/cmd/server.rs +++ b/src/bin/cmd/server.rs @@ -24,10 +24,8 @@ use clap::ArgMatches; use ctrlc; use daemonize::Daemonize; -use cmd::wallet; use config::GlobalConfig; use core::global; -use grin_wallet::controller; use p2p::Seeding; use servers; use tui::ui; diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index 0e4cca738..f5cc34860 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -92,7 +92,7 @@ where 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) pub fn retrieve_txs( &self, diff --git a/wallet/tests/common/testclient.rs b/wallet/tests/common/testclient.rs index 4de6a794b..22b7d7bac 100644 --- a/wallet/tests/common/testclient.rs +++ b/wallet/tests/common/testclient.rs @@ -283,7 +283,7 @@ where pub struct LocalWalletClient { /// wallet identifier for the proxy queue 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>>, /// my rx queue pub rx: Arc>>,