From c2bbe4344e337444ab6703181d83779804980ef4 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 9 Aug 2018 08:56:04 -0600 Subject: [PATCH] Rename KeyPair to Keypair --- benches/bank.rs | 6 ++-- benches/banking_stage.rs | 14 ++++---- benches/ledger.rs | 4 +-- src/bank.rs | 30 ++++++++-------- src/banking_stage.rs | 4 +-- src/bin/bench-tps.rs | 12 +++---- src/bin/fullnode.rs | 4 +-- src/bin/wallet.rs | 6 ++-- src/budget.rs | 10 +++--- src/choose_gossip_peer_strategy.rs | 20 +++++------ src/crdt.rs | 58 +++++++++++++++--------------- src/drone.rs | 26 +++++++------- src/entry.rs | 10 +++--- src/entry_writer.rs | 4 +-- src/erasure.rs | 6 ++-- src/fullnode.rs | 24 ++++++------- src/ledger.rs | 10 +++--- src/mint.rs | 10 +++--- src/record_stage.rs | 6 ++-- src/replicate_stage.rs | 4 +-- src/signature.rs | 12 +++---- src/thin_client.rs | 20 +++++------ src/tpu.rs | 4 +-- src/transaction.rs | 42 +++++++++++----------- src/tvu.rs | 10 +++--- src/vote_stage.rs | 16 ++++----- src/write_stage.rs | 4 +-- tests/multinode.rs | 42 +++++++++++----------- 28 files changed, 209 insertions(+), 209 deletions(-) diff --git a/benches/bank.rs b/benches/bank.rs index 1f5edf96a..08f00d4a8 100644 --- a/benches/bank.rs +++ b/benches/bank.rs @@ -10,7 +10,7 @@ use rayon::prelude::*; use solana::bank::*; use solana::hash::hash; use solana::mint::Mint; -use solana::signature::{KeyPair, KeyPairUtil}; +use solana::signature::{Keypair, KeypairUtil}; use solana::transaction::Transaction; fn bench_process_transaction(bencher: &mut Bencher) { @@ -22,7 +22,7 @@ fn bench_process_transaction(bencher: &mut Bencher) { .into_par_iter() .map(|i| { // Seed the 'from' account. - let rando0 = KeyPair::new(); + let rando0 = Keypair::new(); let tx = Transaction::new(&mint.keypair(), rando0.pubkey(), 10_000, mint.last_id()); assert!(bank.process_transaction(&tx).is_ok()); @@ -30,7 +30,7 @@ fn bench_process_transaction(bencher: &mut Bencher) { let last_id = hash(&serialize(&i).unwrap()); // Unique hash bank.register_entry_id(&last_id); - let rando1 = KeyPair::new(); + let rando1 = Keypair::new(); let tx = Transaction::new(&rando0, rando1.pubkey(), 1, last_id); assert!(bank.process_transaction(&tx).is_ok()); diff --git a/benches/banking_stage.rs b/benches/banking_stage.rs index c7b4d15ec..115e48c4f 100644 --- a/benches/banking_stage.rs +++ b/benches/banking_stage.rs @@ -11,7 +11,7 @@ use solana::banking_stage::BankingStage; use solana::mint::Mint; use solana::packet::{to_packets_chunked, PacketRecycler}; use solana::record_stage::Signal; -use solana::signature::{KeyPair, KeyPairUtil}; +use solana::signature::{Keypair, KeypairUtil}; use solana::transaction::Transaction; use std::iter; use std::sync::mpsc::{channel, Receiver}; @@ -23,7 +23,7 @@ use std::sync::Arc; // use hash::hash; // use mint::Mint; // use rayon::prelude::*; -// use signature::{KeyPair, KeyPairUtil}; +// use signature::{Keypair, KeypairUtil}; // use std::collections::HashSet; // use std::time::Instant; // use transaction::Transaction; @@ -49,11 +49,11 @@ use std::sync::Arc; // } // // // Seed the 'from' account. -// let rando0 = KeyPair::new(); +// let rando0 = Keypair::new(); // let tx = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, last_id); // bank.process_transaction(&tx).unwrap(); // -// let rando1 = KeyPair::new(); +// let rando1 = Keypair::new(); // let tx = Transaction::new(&rando0, rando1.pubkey(), 2, last_id); // bank.process_transaction(&tx).unwrap(); // @@ -102,9 +102,9 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) { let num_dst_accounts = 8 * 1024; let num_src_accounts = 8 * 1024; - let srckeys: Vec<_> = (0..num_src_accounts).map(|_| KeyPair::new()).collect(); + let srckeys: Vec<_> = (0..num_src_accounts).map(|_| Keypair::new()).collect(); let dstkeys: Vec<_> = (0..num_dst_accounts) - .map(|_| KeyPair::new().pubkey()) + .map(|_| Keypair::new().pubkey()) .collect(); let transactions: Vec<_> = (0..tx) @@ -175,7 +175,7 @@ fn bench_banking_stage_single_from(bencher: &mut Bencher) { let mut pubkeys = Vec::new(); let num_keys = 8; for _ in 0..num_keys { - pubkeys.push(KeyPair::new().pubkey()); + pubkeys.push(Keypair::new().pubkey()); } let transactions: Vec<_> = (0..tx) diff --git a/benches/ledger.rs b/benches/ledger.rs index 8172c0319..f0db373db 100644 --- a/benches/ledger.rs +++ b/benches/ledger.rs @@ -6,14 +6,14 @@ use criterion::{Bencher, Criterion}; use solana::hash::{hash, Hash}; use solana::ledger::{next_entries, reconstruct_entries_from_blobs, Block}; use solana::packet::BlobRecycler; -use solana::signature::{KeyPair, KeyPairUtil}; +use solana::signature::{Keypair, KeypairUtil}; use solana::transaction::Transaction; use std::collections::VecDeque; fn bench_block_to_blobs_to_block(bencher: &mut Bencher) { let zero = Hash::default(); let one = hash(&zero.as_ref()); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new(&keypair, keypair.pubkey(), 1, one); let transactions = vec![tx0; 10]; let entries = next_entries(&zero, 1, transactions); diff --git a/src/bank.rs b/src/bank.rs index 8c75df625..962daee56 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -14,7 +14,7 @@ use ledger::Block; use log::Level; use mint::Mint; use payment_plan::{Payment, PaymentPlan, Witness}; -use signature::{KeyPair, PublicKey, Signature}; +use signature::{Keypair, PublicKey, Signature}; use std::collections::hash_map::Entry::Occupied; use std::collections::{HashMap, HashSet, VecDeque}; use std::result; @@ -519,7 +519,7 @@ impl Bank { pub fn transfer( &self, n: i64, - keypair: &KeyPair, + keypair: &Keypair, to: PublicKey, last_id: Hash, ) -> Result { @@ -534,7 +534,7 @@ impl Bank { pub fn transfer_on_date( &self, n: i64, - keypair: &KeyPair, + keypair: &Keypair, to: PublicKey, dt: DateTime, last_id: Hash, @@ -580,14 +580,14 @@ mod tests { use hash::hash; use ledger; use packet::BLOB_DATA_SIZE; - use signature::KeyPairUtil; + use signature::KeypairUtil; use std::io::{BufReader, Cursor, Seek, SeekFrom}; use std::mem::size_of; #[test] fn test_two_payments_to_one_party() { let mint = Mint::new(10_000); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); let bank = Bank::new(&mint); assert_eq!(bank.last_id(), mint.last_id()); @@ -604,7 +604,7 @@ mod tests { #[test] fn test_negative_tokens() { let mint = Mint::new(1); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); let bank = Bank::new(&mint); assert_eq!( bank.transfer(-1, &mint.keypair(), pubkey, mint.last_id()), @@ -617,7 +617,7 @@ mod tests { fn test_account_not_found() { let mint = Mint::new(1); let bank = Bank::new(&mint); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); assert_eq!( bank.transfer(1, &keypair, mint.pubkey(), mint.last_id()), Err(BankError::AccountNotFound(keypair.pubkey())) @@ -629,7 +629,7 @@ mod tests { fn test_insufficient_funds() { let mint = Mint::new(11_000); let bank = Bank::new(&mint); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); bank.transfer(1_000, &mint.keypair(), pubkey, mint.last_id()) .unwrap(); assert_eq!(bank.transaction_count(), 1); @@ -648,7 +648,7 @@ mod tests { fn test_transfer_to_newb() { let mint = Mint::new(10_000); let bank = Bank::new(&mint); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); bank.transfer(500, &mint.keypair(), pubkey, mint.last_id()) .unwrap(); assert_eq!(bank.get_balance(&pubkey), 500); @@ -658,7 +658,7 @@ mod tests { fn test_transfer_on_date() { let mint = Mint::new(1); let bank = Bank::new(&mint); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); let dt = Utc::now(); bank.transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id()) .unwrap(); @@ -690,7 +690,7 @@ mod tests { fn test_cancel_transfer() { let mint = Mint::new(1); let bank = Bank::new(&mint); - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); let dt = Utc::now(); let sig = bank .transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id()) @@ -795,7 +795,7 @@ mod tests { fn test_debits_before_credits() { let mint = Mint::new(2); let bank = Bank::new(&mint); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new(&mint.keypair(), keypair.pubkey(), 2, mint.last_id()); let tx1 = Transaction::new(&keypair, mint.pubkey(), 1, mint.last_id()); let txs = vec![tx0, tx1]; @@ -810,7 +810,7 @@ mod tests { fn test_process_empty_entry_is_registered() { let mint = Mint::new(1); let bank = Bank::new(&mint); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let entry = next_entry(&mint.last_id(), 1, vec![]); let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, entry.id); @@ -838,7 +838,7 @@ mod tests { mint: &Mint, length: usize, ) -> impl Iterator { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let hash = mint.last_id(); let mut txs = Vec::with_capacity(length); for i in 0..length { @@ -858,7 +858,7 @@ mod tests { let mut hash = mint.last_id(); let mut num_hashes = 0; for _ in 0..length { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, hash); let entry = Entry::new_mut(&mut hash, &mut num_hashes, vec![tx], false); entries.push(entry); diff --git a/src/banking_stage.rs b/src/banking_stage.rs index aec0cf65b..56ccc443d 100644 --- a/src/banking_stage.rs +++ b/src/banking_stage.rs @@ -238,7 +238,7 @@ mod test { //mod tests { // use bank::Bank; // use mint::Mint; -// use signature::{KeyPair, KeyPairUtil}; +// use signature::{Keypair, KeypairUtil}; // use transaction::Transaction; // // #[test] @@ -253,7 +253,7 @@ mod test { // let banking_stage = EventProcessor::new(bank, &mint.last_id(), None); // // // Process a batch that includes a transaction that receives two tokens. -// let alice = KeyPair::new(); +// let alice = Keypair::new(); // let tx = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id()); // let transactions = vec![tx]; // let entry0 = banking_stage.process_transactions(transactions).unwrap(); diff --git a/src/bin/bench-tps.rs b/src/bin/bench-tps.rs index b97ea6288..0dfe15489 100644 --- a/src/bin/bench-tps.rs +++ b/src/bin/bench-tps.rs @@ -19,7 +19,7 @@ use solana::metrics; use solana::nat::{udp_public_bind, udp_random_bind, UdpSocketPair}; use solana::ncp::Ncp; use solana::service::Service; -use solana::signature::{read_keypair, GenKeys, KeyPair, KeyPairUtil}; +use solana::signature::{read_keypair, GenKeys, Keypair, KeypairUtil}; use solana::streamer::default_window; use solana::thin_client::ThinClient; use solana::timing::{duration_as_ms, duration_as_s}; @@ -109,7 +109,7 @@ fn sample_tx_count( } /// Send loopback payment of 0 tokens and confirm the network processed it -fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash, id: &KeyPair) { +fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash, id: &Keypair) { let transfer_start = Instant::now(); let mut poll_count = 0; @@ -172,8 +172,8 @@ fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash, fn generate_txs( shared_txs: &Arc>>>, - id: &KeyPair, - keypairs: &[KeyPair], + id: &Keypair, + keypairs: &[Keypair], last_id: &Hash, threads: usize, reclaim: bool, @@ -271,7 +271,7 @@ fn do_tx_transfers( } } -fn airdrop_tokens(client: &mut ThinClient, leader: &NodeInfo, id: &KeyPair, tx_count: i64) { +fn airdrop_tokens(client: &mut ThinClient, leader: &NodeInfo, id: &Keypair, tx_count: i64) { let mut drone_addr = leader.contact_info.tpu; drone_addr.set_port(DRONE_PORT); @@ -655,7 +655,7 @@ fn spy_node(addr: Option) -> (NodeInfo, UdpSocket) { gossip_socket_pair = udp_public_bind("gossip", 8000, 10000); } - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); let daddr = "0.0.0.0:0".parse().unwrap(); assert!(!gossip_socket_pair.addr.ip().is_unspecified()); assert!(!gossip_socket_pair.addr.ip().is_multicast()); diff --git a/src/bin/fullnode.rs b/src/bin/fullnode.rs index 05d13bfe2..434baab11 100644 --- a/src/bin/fullnode.rs +++ b/src/bin/fullnode.rs @@ -13,7 +13,7 @@ use solana::fullnode::{Config, FullNode}; use solana::logger; use solana::metrics::set_panic_hook; use solana::service::Service; -use solana::signature::{KeyPair, KeyPairUtil}; +use solana::signature::{Keypair, KeypairUtil}; use solana::wallet::request_airdrop; use std::fs::File; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; @@ -53,7 +53,7 @@ fn main() -> () { .get_matches(); let bind_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000); - let mut keypair = KeyPair::new(); + let mut keypair = Keypair::new(); let mut repl_data = NodeInfo::new_leader_with_pubkey(keypair.pubkey(), &bind_addr); if let Some(i) = matches.value_of("identity") { let path = i.to_string(); diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index a9639f102..a73ffd8f7 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -13,7 +13,7 @@ use solana::crdt::NodeInfo; use solana::drone::DRONE_PORT; use solana::fullnode::Config; use solana::logger; -use solana::signature::{read_keypair, KeyPair, KeyPairUtil, PublicKey, Signature}; +use solana::signature::{read_keypair, Keypair, KeypairUtil, PublicKey, Signature}; use solana::thin_client::ThinClient; use solana::wallet::request_airdrop; use std::error; @@ -56,7 +56,7 @@ impl error::Error for WalletError { struct WalletConfig { leader: NodeInfo, - id: KeyPair, + id: Keypair, drone_addr: SocketAddr, command: WalletCommand, } @@ -66,7 +66,7 @@ impl Default for WalletConfig { let default_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000); WalletConfig { leader: NodeInfo::new_leader(&default_addr), - id: KeyPair::new(), + id: Keypair::new(), drone_addr: default_addr, command: WalletCommand::Balance, } diff --git a/src/budget.rs b/src/budget.rs index 41f4f1033..967a02d62 100644 --- a/src/budget.rs +++ b/src/budget.rs @@ -118,7 +118,7 @@ impl PaymentPlan for Budget { #[cfg(test)] mod tests { use super::*; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; #[test] fn test_signature_satisfied() { @@ -160,8 +160,8 @@ mod tests { #[test] fn test_future_payment() { let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10); - let from = KeyPair::new().pubkey(); - let to = KeyPair::new().pubkey(); + let from = Keypair::new().pubkey(); + let to = Keypair::new().pubkey(); let mut budget = Budget::new_future_payment(dt, from, 42, to); budget.apply_witness(&Witness::Timestamp(dt), &from); @@ -173,8 +173,8 @@ mod tests { // Ensure timestamp will only be acknowledged if it came from the // whitelisted public key. let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10); - let from = KeyPair::new().pubkey(); - let to = KeyPair::new().pubkey(); + let from = Keypair::new().pubkey(); + let to = Keypair::new().pubkey(); let mut budget = Budget::new_future_payment(dt, from, 42, to); let orig_budget = budget.clone(); diff --git a/src/choose_gossip_peer_strategy.rs b/src/choose_gossip_peer_strategy.rs index bd2c17fa7..04bda7c20 100644 --- a/src/choose_gossip_peer_strategy.rs +++ b/src/choose_gossip_peer_strategy.rs @@ -192,7 +192,7 @@ impl<'a> ChooseGossipPeerStrategy for ChooseWeightedPeerStrategy<'a> { mod tests { use choose_gossip_peer_strategy::{ChooseWeightedPeerStrategy, DEFAULT_WEIGHT}; use logger; - use signature::{KeyPair, KeyPairUtil, PublicKey}; + use signature::{Keypair, KeypairUtil, PublicKey}; use std; use std::collections::HashMap; @@ -205,7 +205,7 @@ mod tests { logger::setup(); // Initialize the filler keys - let key1 = KeyPair::new().pubkey(); + let key1 = Keypair::new().pubkey(); let remote: HashMap = HashMap::new(); let external_liveness: HashMap> = HashMap::new(); @@ -224,8 +224,8 @@ mod tests { logger::setup(); // Initialize the filler keys - let key1 = KeyPair::new().pubkey(); - let key2 = KeyPair::new().pubkey(); + let key1 = Keypair::new().pubkey(); + let key2 = Keypair::new().pubkey(); let remote: HashMap = HashMap::new(); let mut external_liveness: HashMap> = HashMap::new(); @@ -249,8 +249,8 @@ mod tests { logger::setup(); // Initialize the filler keys - let key1 = KeyPair::new().pubkey(); - let key2 = KeyPair::new().pubkey(); + let key1 = Keypair::new().pubkey(); + let key2 = Keypair::new().pubkey(); let remote: HashMap = HashMap::new(); let mut external_liveness: HashMap> = HashMap::new(); @@ -273,7 +273,7 @@ mod tests { logger::setup(); // Initialize the filler keys - let key1 = KeyPair::new().pubkey(); + let key1 = Keypair::new().pubkey(); let mut remote: HashMap = HashMap::new(); let mut external_liveness: HashMap> = HashMap::new(); @@ -285,7 +285,7 @@ mod tests { remote.insert(key1, 0); for i in 0..num_peers { - let pk = KeyPair::new().pubkey(); + let pk = Keypair::new().pubkey(); rumors.insert(pk, i); } @@ -303,7 +303,7 @@ mod tests { logger::setup(); // Initialize the filler keys - let key1 = KeyPair::new().pubkey(); + let key1 = Keypair::new().pubkey(); let mut remote: HashMap = HashMap::new(); let mut external_liveness: HashMap> = HashMap::new(); @@ -316,7 +316,7 @@ mod tests { remote.insert(key1, old_index); for _i in 0..num_peers { - let pk = KeyPair::new().pubkey(); + let pk = Keypair::new().pubkey(); rumors.insert(pk, old_index); } diff --git a/src/crdt.rs b/src/crdt.rs index 4d6f3bf28..73fb445e8 100644 --- a/src/crdt.rs +++ b/src/crdt.rs @@ -25,7 +25,7 @@ use pnet_datalink as datalink; use rand::{thread_rng, RngCore}; use rayon::prelude::*; use result::{Error, Result}; -use signature::{KeyPair, KeyPairUtil, PublicKey}; +use signature::{Keypair, KeypairUtil, PublicKey}; use std; use std::collections::HashMap; use std::collections::VecDeque; @@ -176,7 +176,7 @@ impl NodeInfo { let addr: SocketAddr = "0.0.0.0:0".parse().unwrap(); assert!(addr.ip().is_unspecified()); Self::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), addr.clone(), addr.clone(), addr.clone(), @@ -190,7 +190,7 @@ impl NodeInfo { let addr: SocketAddr = "224.0.1.255:1000".parse().unwrap(); assert!(addr.ip().is_multicast()); Self::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), addr.clone(), addr.clone(), addr.clone(), @@ -223,7 +223,7 @@ impl NodeInfo { ) } pub fn new_leader(bind_addr: &SocketAddr) -> Self { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); Self::new_leader_with_pubkey(keypair.pubkey(), bind_addr) } pub fn new_entry_point(gossip_addr: SocketAddr) -> Self { @@ -1269,7 +1269,7 @@ pub struct TestNode { impl TestNode { pub fn new_localhost() -> Self { - let pubkey = KeyPair::new().pubkey(); + let pubkey = Keypair::new().pubkey(); Self::new_localhost_with_pubkey(pubkey) } pub fn new_localhost_with_pubkey(pubkey: PublicKey) -> Self { @@ -1381,7 +1381,7 @@ mod tests { use logger; use packet::BlobRecycler; use result::Error; - use signature::{KeyPair, KeyPairUtil, PublicKey}; + use signature::{Keypair, KeypairUtil, PublicKey}; use std::fs::remove_dir_all; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::channel; @@ -1403,7 +1403,7 @@ mod tests { #[test] fn test_bad_address() { let d1 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.0:1234".parse().unwrap(), "0.0.0.0:1235".parse().unwrap(), "0.0.0.0:1236".parse().unwrap(), @@ -1415,7 +1415,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadGossipAddress)) ); let d1_1 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.1:1234".parse().unwrap(), "0.0.0.0:1235".parse().unwrap(), "0.0.0.0:1236".parse().unwrap(), @@ -1427,7 +1427,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadContactInfo)) ); let d2 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.1:0".parse().unwrap(), "0.0.0.1:0".parse().unwrap(), "0.0.0.1:0".parse().unwrap(), @@ -1439,7 +1439,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadGossipAddress)) ); let d2_1 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.1:1234".parse().unwrap(), "0.0.0.1:0".parse().unwrap(), "0.0.0.1:0".parse().unwrap(), @@ -1467,7 +1467,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadNodeInfo)) ); let d6 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.0:1234".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), @@ -1479,7 +1479,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadGossipAddress)) ); let d7 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.1:0".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), @@ -1491,7 +1491,7 @@ mod tests { Some(Error::CrdtError(CrdtError::BadGossipAddress)) ); let d8 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "0.0.0.1:1234".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), "0.0.0.0:0".parse().unwrap(), @@ -1504,7 +1504,7 @@ mod tests { #[test] fn insert_test() { let mut d = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1597,7 +1597,7 @@ mod tests { } #[test] fn replicated_data_new_leader_with_pubkey() { - let kp = KeyPair::new(); + let kp = Keypair::new(); let d1 = NodeInfo::new_leader_with_pubkey( kp.pubkey().clone(), &"127.0.0.1:1234".parse().unwrap(), @@ -1615,7 +1615,7 @@ mod tests { #[test] fn update_test() { let d1 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1623,7 +1623,7 @@ mod tests { "127.0.0.1:1238".parse().unwrap(), ); let d2 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1631,7 +1631,7 @@ mod tests { "127.0.0.1:1238".parse().unwrap(), ); let d3 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1674,7 +1674,7 @@ mod tests { #[test] fn window_index_request() { let me = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1685,7 +1685,7 @@ mod tests { let rv = crdt.window_index_request(0); assert_matches!(rv, Err(Error::CrdtError(CrdtError::NoPeers))); let nxt = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1696,7 +1696,7 @@ mod tests { let rv = crdt.window_index_request(0); assert_matches!(rv, Err(Error::CrdtError(CrdtError::NoPeers))); let nxt = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.2:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1709,7 +1709,7 @@ mod tests { assert_eq!(rv.0, "127.0.0.2:1234".parse().unwrap()); let nxt = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.3:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1735,7 +1735,7 @@ mod tests { #[test] fn gossip_request_bad_addr() { let me = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:127".parse().unwrap(), "127.0.0.1:127".parse().unwrap(), "127.0.0.1:127".parse().unwrap(), @@ -1760,7 +1760,7 @@ mod tests { #[test] fn gossip_request() { let me = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1771,7 +1771,7 @@ mod tests { let rv = crdt.gossip_request(); assert_matches!(rv, Err(Error::CrdtError(CrdtError::NoPeers))); let nxt1 = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.2:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1894,7 +1894,7 @@ mod tests { logger::setup(); let window = default_window(); let me = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), @@ -1917,7 +1917,7 @@ mod tests { assert!(rv.is_none()); fn tmp_ledger(name: &str) -> String { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let path = format!("/tmp/farf/{}-{}", name, keypair.pubkey()); @@ -1998,7 +1998,7 @@ mod tests { //add a bunch of nodes with a new leader for _ in 0..10 { let mut dum = NodeInfo::new_entry_point("127.0.0.1:1234".parse().unwrap()); - dum.id = KeyPair::new().pubkey(); + dum.id = Keypair::new().pubkey(); dum.leader_id = leader1.id; crdt.insert(&dum); } @@ -2061,7 +2061,7 @@ mod tests { fn test_default_leader() { logger::setup(); let node_info = NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), diff --git a/src/drone.rs b/src/drone.rs index b84a024da..cd2fed1dc 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -7,7 +7,7 @@ use influx_db_client as influxdb; use metrics; use signature::Signature; -use signature::{KeyPair, PublicKey}; +use signature::{Keypair, PublicKey}; use std::io; use std::io::{Error, ErrorKind}; use std::net::{IpAddr, SocketAddr, UdpSocket}; @@ -28,7 +28,7 @@ pub enum DroneRequest { } pub struct Drone { - mint_keypair: KeyPair, + mint_keypair: Keypair, ip_cache: Vec, _airdrop_addr: SocketAddr, transactions_addr: SocketAddr, @@ -40,7 +40,7 @@ pub struct Drone { impl Drone { pub fn new( - mint_keypair: KeyPair, + mint_keypair: Keypair, _airdrop_addr: SocketAddr, transactions_addr: SocketAddr, requests_addr: SocketAddr, @@ -163,7 +163,7 @@ mod tests { use logger; use mint::Mint; use service::Service; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::fs::remove_dir_all; use std::net::{SocketAddr, UdpSocket}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -174,7 +174,7 @@ mod tests { #[test] fn test_check_request_limit() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut addr: SocketAddr = "0.0.0.0:9900".parse().unwrap(); addr.set_ip(get_ip_addr().unwrap()); let transactions_addr = "0.0.0.0:0".parse().unwrap(); @@ -194,7 +194,7 @@ mod tests { #[test] fn test_clear_request_count() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut addr: SocketAddr = "0.0.0.0:9900".parse().unwrap(); addr.set_ip(get_ip_addr().unwrap()); let transactions_addr = "0.0.0.0:0".parse().unwrap(); @@ -208,7 +208,7 @@ mod tests { #[test] fn test_add_ip_to_cache() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut addr: SocketAddr = "0.0.0.0:9900".parse().unwrap(); addr.set_ip(get_ip_addr().unwrap()); let transactions_addr = "0.0.0.0:0".parse().unwrap(); @@ -223,7 +223,7 @@ mod tests { #[test] fn test_clear_ip_cache() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut addr: SocketAddr = "0.0.0.0:9900".parse().unwrap(); addr.set_ip(get_ip_addr().unwrap()); let transactions_addr = "0.0.0.0:0".parse().unwrap(); @@ -240,7 +240,7 @@ mod tests { #[test] fn test_drone_default_init() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut addr: SocketAddr = "0.0.0.0:9900".parse().unwrap(); addr.set_ip(get_ip_addr().unwrap()); let transactions_addr = "0.0.0.0:0".parse().unwrap(); @@ -260,7 +260,7 @@ mod tests { } fn tmp_ledger_path(name: &str) -> String { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); format!("/tmp/tmp-ledger-{}-{}", name, keypair.pubkey()) } @@ -272,13 +272,13 @@ mod tests { const TPS_BATCH: i64 = 5_000_000; logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let alice = Mint::new(10_000_000); let bank = Bank::new(&alice); - let bob_pubkey = KeyPair::new().pubkey(); - let carlos_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); + let carlos_pubkey = Keypair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); let leader_data = leader.data.clone(); let ledger_path = tmp_ledger_path("send_airdrop"); diff --git a/src/entry.rs b/src/entry.rs index 6abca08b6..0091deea6 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -219,7 +219,7 @@ mod tests { use chrono::prelude::*; use entry::Entry; use hash::hash; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use transaction::Transaction; #[test] @@ -237,7 +237,7 @@ mod tests { let zero = Hash::default(); // First, verify entries - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new(&keypair, keypair.pubkey(), 0, zero); let tx1 = Transaction::new(&keypair, keypair.pubkey(), 1, zero); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()], false); @@ -254,7 +254,7 @@ mod tests { let zero = Hash::default(); // First, verify entries - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new_timestamp(&keypair, Utc::now(), zero); let tx1 = Transaction::new_signature(&keypair, Default::default(), zero); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()], false); @@ -277,7 +277,7 @@ mod tests { assert_eq!(tick.num_hashes, 0); assert_eq!(tick.id, zero); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new_timestamp(&keypair, Utc::now(), zero); let entry0 = next_entry(&zero, 1, vec![tx0.clone()]); assert_eq!(entry0.num_hashes, 1); @@ -288,7 +288,7 @@ mod tests { #[should_panic] fn test_next_entry_panic() { let zero = Hash::default(); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx = Transaction::new(&keypair, keypair.pubkey(), 0, zero); next_entry(&zero, 0, vec![tx]); } diff --git a/src/entry_writer.rs b/src/entry_writer.rs index 4e5e1857f..f357bd7ca 100644 --- a/src/entry_writer.rs +++ b/src/entry_writer.rs @@ -104,7 +104,7 @@ mod tests { use ledger; use mint::Mint; use packet::BLOB_DATA_SIZE; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::io::Cursor; use transaction::Transaction; @@ -115,7 +115,7 @@ mod tests { let writer = io::sink(); let mut entry_writer = EntryWriter::new(&bank, writer); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, mint.last_id()); // NOTE: if Entry grows to larger than a transaction, the code below falls over diff --git a/src/erasure.rs b/src/erasure.rs index bf034dd08..dacf61649 100644 --- a/src/erasure.rs +++ b/src/erasure.rs @@ -599,8 +599,8 @@ mod test { use logger; use packet::{BlobRecycler, BLOB_HEADER_SIZE, BLOB_SIZE}; use rand::{thread_rng, Rng}; - use signature::KeyPair; - use signature::KeyPairUtil; + use signature::Keypair; + use signature::KeypairUtil; // use std::sync::{Arc, RwLock}; use streamer::{index_blobs, WindowSlot}; @@ -728,7 +728,7 @@ mod test { } let d = crdt::NodeInfo::new( - KeyPair::new().pubkey(), + Keypair::new().pubkey(), "127.0.0.1:1234".parse().unwrap(), "127.0.0.1:1235".parse().unwrap(), "127.0.0.1:1236".parse().unwrap(), diff --git a/src/fullnode.rs b/src/fullnode.rs index f443eaf7a..39857e85d 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -8,7 +8,7 @@ use ncp::Ncp; use packet::BlobRecycler; use rpu::Rpu; use service::Service; -use signature::{KeyPair, KeyPairUtil}; +use signature::{Keypair, KeypairUtil}; use std::collections::VecDeque; use std::net::SocketAddr; use std::sync::atomic::{AtomicBool, Ordering}; @@ -37,13 +37,13 @@ pub struct Config { impl Config { pub fn new(bind_addr: &SocketAddr, pkcs8: Vec) -> Self { let keypair = - KeyPair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in fullnode::Config new"); + Keypair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in fullnode::Config new"); let pubkey = keypair.pubkey(); let node_info = NodeInfo::new_leader_with_pubkey(pubkey, bind_addr); Config { node_info, pkcs8 } } - pub fn keypair(&self) -> KeyPair { - KeyPair::from_pkcs8(Input::from(&self.pkcs8)) + pub fn keypair(&self) -> Keypair { + Keypair::from_pkcs8(Input::from(&self.pkcs8)) .expect("from_pkcs8 in fullnode::Config keypair") } } @@ -53,7 +53,7 @@ impl FullNode { mut node: TestNode, leader: bool, ledger_path: &str, - keypair: KeyPair, + keypair: Keypair, network_entry_for_validator: Option, sigverify_disabled: bool, ) -> FullNode { @@ -127,7 +127,7 @@ impl FullNode { node: TestNode, leader: bool, ledger: &str, - keypair: KeyPair, + keypair: Keypair, network_entry_for_validator: Option, ) -> FullNode { FullNode::new_internal( @@ -144,7 +144,7 @@ impl FullNode { node: TestNode, leader: bool, ledger_path: &str, - keypair: KeyPair, + keypair: Keypair, network_entry_for_validator: Option, ) -> FullNode { FullNode::new_internal( @@ -202,7 +202,7 @@ impl FullNode { /// `---------------------` /// ``` pub fn new_leader( - keypair: KeyPair, + keypair: Keypair, bank: Bank, entry_height: u64, ledger_tail: Option>, @@ -292,7 +292,7 @@ impl FullNode { /// `-------------------------------` /// ``` pub fn new_validator( - keypair: KeyPair, + keypair: Keypair, bank: Bank, entry_height: u64, ledger_tail: Option>, @@ -376,13 +376,13 @@ mod tests { use fullnode::FullNode; use mint::Mint; use service::Service; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::sync::atomic::AtomicBool; use std::sync::Arc; #[test] fn validator_exit() { - let kp = KeyPair::new(); + let kp = Keypair::new(); let tn = TestNode::new_localhost_with_pubkey(kp.pubkey()); let alice = Mint::new(10_000); let bank = Bank::new(&alice); @@ -396,7 +396,7 @@ mod tests { fn validator_parallel_exit() { let vals: Vec = (0..2) .map(|_| { - let kp = KeyPair::new(); + let kp = Keypair::new(); let tn = TestNode::new_localhost_with_pubkey(kp.pubkey()); let alice = Mint::new(10_000); let bank = Bank::new(&alice); diff --git a/src/ledger.rs b/src/ledger.rs index 530a29a3d..64bc7795d 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -508,13 +508,13 @@ mod tests { use entry::{next_entry, Entry}; use hash::hash; use packet::{BlobRecycler, BLOB_DATA_SIZE, PACKET_DATA_SIZE}; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use transaction::{Transaction, Vote}; fn tmp_ledger_path(name: &str) -> String { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); format!("/tmp/tmp-ledger-{}-{}", name, keypair.pubkey()) } @@ -538,7 +538,7 @@ mod tests { fn make_tiny_test_entries(num: usize) -> Vec { let zero = Hash::default(); let one = hash(&zero.as_ref()); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mut id = one; let mut num_hashes = 0; @@ -557,7 +557,7 @@ mod tests { fn make_test_entries() -> Vec { let zero = Hash::default(); let one = hash(&zero.as_ref()); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx0 = Transaction::new_vote( &keypair, Vote { @@ -612,7 +612,7 @@ mod tests { logger::setup(); let id = Hash::default(); let next_id = hash(&id.as_ref()); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let tx_small = Transaction::new_vote( &keypair, Vote { diff --git a/src/mint.rs b/src/mint.rs index 4937b6955..17eec8465 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -3,7 +3,7 @@ use entry::Entry; use hash::{hash, Hash}; use ring::rand::SystemRandom; -use signature::{KeyPair, KeyPairUtil, PublicKey}; +use signature::{Keypair, KeypairUtil, PublicKey}; use transaction::Transaction; use untrusted::Input; @@ -17,7 +17,7 @@ pub struct Mint { impl Mint { pub fn new_with_pkcs8(tokens: i64, pkcs8: Vec) -> Self { let keypair = - KeyPair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in mint pub fn new"); + Keypair::from_pkcs8(Input::from(&pkcs8)).expect("from_pkcs8 in mint pub fn new"); let pubkey = keypair.pubkey(); Mint { pkcs8, @@ -28,7 +28,7 @@ impl Mint { pub fn new(tokens: i64) -> Self { let rnd = SystemRandom::new(); - let pkcs8 = KeyPair::generate_pkcs8(&rnd) + let pkcs8 = Keypair::generate_pkcs8(&rnd) .expect("generate_pkcs8 in mint pub fn new") .to_vec(); Self::new_with_pkcs8(tokens, pkcs8) @@ -42,8 +42,8 @@ impl Mint { self.create_entries()[1].id } - pub fn keypair(&self) -> KeyPair { - KeyPair::from_pkcs8(Input::from(&self.pkcs8)).expect("from_pkcs8 in mint pub fn keypair") + pub fn keypair(&self) -> Keypair { + Keypair::from_pkcs8(Input::from(&self.pkcs8)).expect("from_pkcs8 in mint pub fn keypair") } pub fn pubkey(&self) -> PublicKey { diff --git a/src/record_stage.rs b/src/record_stage.rs index a2aaa0699..dc7cee0fc 100644 --- a/src/record_stage.rs +++ b/src/record_stage.rs @@ -140,7 +140,7 @@ impl Service for RecordStage { mod tests { use super::*; use ledger::Block; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::sync::mpsc::channel; use std::thread::sleep; @@ -185,8 +185,8 @@ mod tests { let (tx_sender, signal_receiver) = channel(); let zero = Hash::default(); let (_record_stage, entry_receiver) = RecordStage::new(signal_receiver, &zero); - let alice_keypair = KeyPair::new(); - let bob_pubkey = KeyPair::new().pubkey(); + let alice_keypair = Keypair::new(); + let bob_pubkey = Keypair::new().pubkey(); let tx0 = Transaction::new(&alice_keypair, bob_pubkey, 1, zero); let tx1 = Transaction::new(&alice_keypair, bob_pubkey, 2, zero); tx_sender diff --git a/src/replicate_stage.rs b/src/replicate_stage.rs index d80753c5a..3a3ed7fbb 100644 --- a/src/replicate_stage.rs +++ b/src/replicate_stage.rs @@ -8,7 +8,7 @@ use log::Level; use packet::BlobRecycler; use result::{Error, Result}; use service::Service; -use signature::KeyPair; +use signature::Keypair; use std::net::UdpSocket; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicUsize; @@ -72,7 +72,7 @@ impl ReplicateStage { Ok(()) } pub fn new( - keypair: KeyPair, + keypair: Keypair, bank: Arc, crdt: Arc>, blob_recycler: BlobRecycler, diff --git a/src/signature.rs b/src/signature.rs index 0001fbd88..42a21aeab 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -13,7 +13,7 @@ use std::fmt; use std::fs::File; use untrusted::Input; -pub type KeyPair = Ed25519KeyPair; +pub type Keypair = Ed25519KeyPair; #[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct PublicKey(GenericArray); @@ -74,12 +74,12 @@ impl fmt::Display for Signature { } } -pub trait KeyPairUtil { +pub trait KeypairUtil { fn new() -> Self; fn pubkey(&self) -> PublicKey; } -impl KeyPairUtil for Ed25519KeyPair { +impl KeypairUtil for Ed25519KeyPair { /// Return a new ED25519 keypair fn new() -> Self { let rng = rand::SystemRandom::new(); @@ -113,10 +113,10 @@ impl GenKeys { (0..n).map(|_| self.gen_seed()).collect() } - pub fn gen_n_keypairs(&mut self, n: i64) -> Vec { + pub fn gen_n_keypairs(&mut self, n: i64) -> Vec { self.gen_n_seeds(n) .into_par_iter() - .map(|seed| KeyPair::from_seed_unchecked(Input::from(&seed)).unwrap()) + .map(|seed| Keypair::from_seed_unchecked(Input::from(&seed)).unwrap()) .collect() } } @@ -127,7 +127,7 @@ pub fn read_pkcs8(path: &str) -> Result, Box> { Ok(pkcs8) } -pub fn read_keypair(path: &str) -> Result> { +pub fn read_keypair(path: &str) -> Result> { let pkcs8 = read_pkcs8(path)?; let keypair = Ed25519KeyPair::from_pkcs8(Input::from(&pkcs8))?; Ok(keypair) diff --git a/src/thin_client.rs b/src/thin_client.rs index 0e10d0361..ec96dbbbb 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -6,7 +6,7 @@ use bincode::{deserialize, serialize}; use hash::Hash; use request::{Request, Response}; -use signature::{KeyPair, PublicKey, Signature}; +use signature::{Keypair, PublicKey, Signature}; use std::collections::HashMap; use std::io; use std::net::{SocketAddr, UdpSocket}; @@ -99,7 +99,7 @@ impl ThinClient { pub fn transfer( &self, n: i64, - keypair: &KeyPair, + keypair: &Keypair, to: PublicKey, last_id: &Hash, ) -> io::Result { @@ -289,14 +289,14 @@ mod tests { use logger; use mint::Mint; use service::Service; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::fs::remove_dir_all; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use transaction::{Instruction, Plan}; fn tmp_ledger(name: &str, mint: &Mint) -> String { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let path = format!("/tmp/tmp-ledger-{}-{}", name, keypair.pubkey()); @@ -309,13 +309,13 @@ mod tests { #[test] fn test_thin_client() { logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_data = leader.data.clone(); let alice = Mint::new(10_000); let bank = Bank::new(&alice); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = tmp_ledger("thin_client", &alice); @@ -358,11 +358,11 @@ mod tests { #[ignore] fn test_bad_sig() { logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let alice = Mint::new(10_000); let bank = Bank::new(&alice); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); let leader_data = leader.data.clone(); let ledger_path = tmp_ledger("bad_sig", &alice); @@ -418,11 +418,11 @@ mod tests { #[test] fn test_client_check_signature() { logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let alice = Mint::new(10_000); let bank = Bank::new(&alice); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); let leader_data = leader.data.clone(); let ledger_path = tmp_ledger("client_check_signature", &alice); diff --git a/src/tpu.rs b/src/tpu.rs index 90a4d2845..900e9ee89 100644 --- a/src/tpu.rs +++ b/src/tpu.rs @@ -32,7 +32,7 @@ use fetch_stage::FetchStage; use packet::{BlobRecycler, PacketRecycler}; use record_stage::RecordStage; use service::Service; -use signature::KeyPair; +use signature::Keypair; use sigverify_stage::SigVerifyStage; use std::net::UdpSocket; use std::sync::atomic::AtomicBool; @@ -52,7 +52,7 @@ pub struct Tpu { impl Tpu { pub fn new( - keypair: KeyPair, + keypair: Keypair, bank: &Arc, crdt: &Arc>, tick_duration: Option, diff --git a/src/transaction.rs b/src/transaction.rs index e9ecfcaaa..c52757197 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -5,7 +5,7 @@ use budget::{Budget, Condition}; use chrono::prelude::*; use hash::Hash; use payment_plan::{Payment, PaymentPlan, Witness}; -use signature::{KeyPair, KeyPairUtil, PublicKey, Signature}; +use signature::{Keypair, KeypairUtil, PublicKey, Signature}; pub const SIGNED_DATA_OFFSET: usize = 112; pub const SIG_OFFSET: usize = 8; @@ -97,7 +97,7 @@ pub struct Transaction { impl Transaction { /// Create a signed transaction from the given `Instruction`. fn new_from_instruction( - from_keypair: &KeyPair, + from_keypair: &Keypair, instruction: Instruction, last_id: Hash, fee: i64, @@ -116,7 +116,7 @@ impl Transaction { /// Create and sign a new Transaction. Used for unit-testing. pub fn new_taxed( - from_keypair: &KeyPair, + from_keypair: &Keypair, to: PublicKey, tokens: i64, fee: i64, @@ -133,29 +133,29 @@ impl Transaction { } /// Create and sign a new Transaction. Used for unit-testing. - pub fn new(from_keypair: &KeyPair, to: PublicKey, tokens: i64, last_id: Hash) -> Self { + pub fn new(from_keypair: &Keypair, to: PublicKey, tokens: i64, last_id: Hash) -> Self { Self::new_taxed(from_keypair, to, tokens, 0, last_id) } /// Create and sign a new Witness Timestamp. Used for unit-testing. - pub fn new_timestamp(from_keypair: &KeyPair, dt: DateTime, last_id: Hash) -> Self { + pub fn new_timestamp(from_keypair: &Keypair, dt: DateTime, last_id: Hash) -> Self { let instruction = Instruction::ApplyTimestamp(dt); Self::new_from_instruction(from_keypair, instruction, last_id, 0) } /// Create and sign a new Witness Signature. Used for unit-testing. - pub fn new_signature(from_keypair: &KeyPair, tx_sig: Signature, last_id: Hash) -> Self { + pub fn new_signature(from_keypair: &Keypair, tx_sig: Signature, last_id: Hash) -> Self { let instruction = Instruction::ApplySignature(tx_sig); Self::new_from_instruction(from_keypair, instruction, last_id, 0) } - pub fn new_vote(from_keypair: &KeyPair, vote: Vote, last_id: Hash, fee: i64) -> Self { + pub fn new_vote(from_keypair: &Keypair, vote: Vote, last_id: Hash, fee: i64) -> Self { Transaction::new_from_instruction(&from_keypair, Instruction::NewVote(vote), last_id, fee) } /// Create and sign a postdated Transaction. Used for unit-testing. pub fn new_on_date( - from_keypair: &KeyPair, + from_keypair: &Keypair, to: PublicKey, dt: DateTime, tokens: i64, @@ -184,7 +184,7 @@ impl Transaction { } /// Sign this transaction. - pub fn sign(&mut self, keypair: &KeyPair) { + pub fn sign(&mut self, keypair: &Keypair) { let sign_data = self.get_sign_data(); self.sig = Signature::new(keypair.sign(&sign_data).as_ref()); } @@ -208,7 +208,7 @@ impl Transaction { } pub fn test_tx() -> Transaction { - let keypair1 = KeyPair::new(); + let keypair1 = Keypair::new(); let pubkey1 = keypair1.pubkey(); let zero = Hash::default(); Transaction::new(&keypair1, pubkey1, 42, zero) @@ -233,7 +233,7 @@ mod tests { #[test] fn test_claim() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let zero = Hash::default(); let tx0 = Transaction::new(&keypair, keypair.pubkey(), 42, zero); assert!(tx0.verify_plan()); @@ -242,8 +242,8 @@ mod tests { #[test] fn test_transfer() { let zero = Hash::default(); - let keypair0 = KeyPair::new(); - let keypair1 = KeyPair::new(); + let keypair0 = Keypair::new(); + let keypair1 = Keypair::new(); let pubkey1 = keypair1.pubkey(); let tx0 = Transaction::new(&keypair0, pubkey1, 42, zero); assert!(tx0.verify_plan()); @@ -252,8 +252,8 @@ mod tests { #[test] fn test_transfer_with_fee() { let zero = Hash::default(); - let keypair0 = KeyPair::new(); - let pubkey1 = KeyPair::new().pubkey(); + let keypair0 = Keypair::new(); + let pubkey1 = Keypair::new().pubkey(); assert!(Transaction::new_taxed(&keypair0, pubkey1, 1, 1, zero).verify_plan()); assert!(!Transaction::new_taxed(&keypair0, pubkey1, 1, 2, zero).verify_plan()); assert!(!Transaction::new_taxed(&keypair0, pubkey1, 1, -1, zero).verify_plan()); @@ -282,7 +282,7 @@ mod tests { #[test] fn test_token_attack() { let zero = Hash::default(); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let pubkey = keypair.pubkey(); let mut tx = Transaction::new(&keypair, pubkey, 42, zero); if let Instruction::NewContract(contract) = &mut tx.instruction { @@ -297,9 +297,9 @@ mod tests { #[test] fn test_hijack_attack() { - let keypair0 = KeyPair::new(); - let keypair1 = KeyPair::new(); - let thief_keypair = KeyPair::new(); + let keypair0 = Keypair::new(); + let keypair1 = Keypair::new(); + let thief_keypair = Keypair::new(); let pubkey1 = keypair1.pubkey(); let zero = Hash::default(); let mut tx = Transaction::new(&keypair0, pubkey1, 42, zero); @@ -323,8 +323,8 @@ mod tests { #[test] fn test_overspend_attack() { - let keypair0 = KeyPair::new(); - let keypair1 = KeyPair::new(); + let keypair0 = Keypair::new(); + let keypair1 = Keypair::new(); let zero = Hash::default(); let mut tx = Transaction::new(&keypair0, keypair1.pubkey(), 1, zero); if let Instruction::NewContract(contract) = &mut tx.instruction { diff --git a/src/tvu.rs b/src/tvu.rs index 85ee0b115..55c3afef6 100644 --- a/src/tvu.rs +++ b/src/tvu.rs @@ -42,7 +42,7 @@ use crdt::Crdt; use packet::BlobRecycler; use replicate_stage::ReplicateStage; use service::Service; -use signature::KeyPair; +use signature::Keypair; use std::net::UdpSocket; use std::sync::atomic::AtomicBool; use std::sync::{Arc, RwLock}; @@ -70,7 +70,7 @@ impl Tvu { /// * `exit` - The exit signal. #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] pub fn new( - keypair: KeyPair, + keypair: Keypair, bank: &Arc, entry_height: u64, crdt: Arc>, @@ -152,7 +152,7 @@ pub mod tests { use packet::BlobRecycler; use result::Result; use service::Service; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::collections::VecDeque; use std::net::UdpSocket; use std::sync::atomic::AtomicBool; @@ -179,7 +179,7 @@ pub mod tests { fn test_replicate() { logger::setup(); let leader = TestNode::new_localhost(); - let target1_keypair = KeyPair::new(); + let target1_keypair = Keypair::new(); let target1 = TestNode::new_localhost_with_pubkey(target1_keypair.pubkey()); let target2 = TestNode::new_localhost(); let exit = Arc::new(AtomicBool::new(false)); @@ -252,7 +252,7 @@ pub mod tests { let mut blob_id = 0; let num_transfers = 10; let transfer_amount = 501; - let bob_keypair = KeyPair::new(); + let bob_keypair = Keypair::new(); for i in 0..num_transfers { let entry0 = Entry::new(&cur_hash, i, vec![], false); bank.register_entry_id(&cur_hash); diff --git a/src/vote_stage.rs b/src/vote_stage.rs index cd9affc35..7f1415b2d 100644 --- a/src/vote_stage.rs +++ b/src/vote_stage.rs @@ -11,7 +11,7 @@ use metrics; use packet::{BlobRecycler, SharedBlob}; use result::Result; use service::Service; -use signature::KeyPair; +use signature::Keypair; use std::collections::VecDeque; use std::result; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; @@ -35,7 +35,7 @@ enum VoteError { pub fn create_vote_tx_and_blob( last_id: &Hash, - keypair: &KeyPair, + keypair: &Keypair, crdt: &Arc>, blob_recycler: &BlobRecycler, ) -> Result<(Transaction, SharedBlob)> { @@ -114,7 +114,7 @@ fn get_last_id_to_vote_on( pub fn send_leader_vote( debug_id: u64, - keypair: &KeyPair, + keypair: &Keypair, bank: &Arc, crdt: &Arc>, blob_recycler: &BlobRecycler, @@ -166,7 +166,7 @@ pub fn send_leader_vote( fn send_validator_vote( bank: &Arc, - keypair: &Arc, + keypair: &Arc, crdt: &Arc>, blob_recycler: &BlobRecycler, vote_blob_sender: &BlobSender, @@ -182,7 +182,7 @@ fn send_validator_vote( impl VoteStage { pub fn new( - keypair: Arc, + keypair: Arc, bank: Arc, crdt: Arc>, blob_recycler: BlobRecycler, @@ -203,7 +203,7 @@ impl VoteStage { } fn run( - keypair: &Arc, + keypair: &Arc, bank: &Arc, crdt: &Arc>, blob_recycler: &BlobRecycler, @@ -243,7 +243,7 @@ pub mod tests { use mint::Mint; use packet::BlobRecycler; use service::Service; - use signature::{KeyPair, KeyPairUtil}; + use signature::{Keypair, KeypairUtil}; use std::sync::atomic::AtomicBool; use std::sync::mpsc::channel; use std::sync::{Arc, RwLock}; @@ -252,7 +252,7 @@ pub mod tests { /// Ensure the VoteStage issues votes at the expected cadence #[test] fn test_vote_cadence() { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let mint = Mint::new(1234); let bank = Arc::new(Bank::new(&mint)); diff --git a/src/write_stage.rs b/src/write_stage.rs index b666496be..2f39ca211 100644 --- a/src/write_stage.rs +++ b/src/write_stage.rs @@ -11,7 +11,7 @@ use log::Level; use packet::BlobRecycler; use result::{Error, Result}; use service::Service; -use signature::KeyPair; +use signature::Keypair; use std::collections::VecDeque; use std::net::UdpSocket; use std::sync::atomic::AtomicUsize; @@ -69,7 +69,7 @@ impl WriteStage { /// Create a new WriteStage for writing and broadcasting entries. pub fn new( - keypair: KeyPair, + keypair: Keypair, bank: Arc, crdt: Arc>, blob_recycler: BlobRecycler, diff --git a/tests/multinode.rs b/tests/multinode.rs index c9645f2e3..23f32e7a2 100755 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -15,7 +15,7 @@ use solana::mint::Mint; use solana::ncp::Ncp; use solana::result; use solana::service::Service; -use solana::signature::{KeyPair, KeyPairUtil, PublicKey}; +use solana::signature::{Keypair, KeypairUtil, PublicKey}; use solana::streamer::{default_window, WINDOW_SIZE}; use solana::thin_client::ThinClient; use solana::timing::duration_as_s; @@ -79,7 +79,7 @@ fn converge(leader: &NodeInfo, num_nodes: usize) -> Vec { } fn tmp_ledger_path(name: &str) -> String { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); format!("/tmp/tmp-ledger-{}-{}", name, keypair.pubkey()) } @@ -123,11 +123,11 @@ fn make_tiny_test_entries(start_hash: Hash, num: usize) -> Vec { fn test_multi_node_ledger_window() -> result::Result<()> { logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader_pubkey = leader_keypair.pubkey().clone(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_data = leader.data.clone(); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let mut ledger_paths = Vec::new(); let (alice, leader_ledger_path) = genesis("multi_node_ledger_window", 10_000); @@ -155,7 +155,7 @@ fn test_multi_node_ledger_window() -> result::Result<()> { // start up another validator from zero, converge and then check // balances - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let validator_data = validator.data.clone(); let validator = FullNode::new( @@ -203,11 +203,11 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> { logger::setup(); const N: usize = 5; trace!("test_multi_node_validator_catchup_from_zero"); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader_pubkey = leader_keypair.pubkey().clone(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_data = leader.data.clone(); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let mut ledger_paths = Vec::new(); let (alice, leader_ledger_path) = genesis("multi_node_validator_catchup_from_zero", 10_000); @@ -228,7 +228,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> { let mut nodes = vec![server]; for _ in 0..N { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let ledger_path = tmp_copy_ledger( &leader_ledger_path, @@ -269,7 +269,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> { success = 0; // start up another validator from zero, converge and then check everyone's // balances - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let val = FullNode::new( validator, @@ -327,11 +327,11 @@ fn test_multi_node_basic() { logger::setup(); const N: usize = 5; trace!("test_multi_node_basic"); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader_pubkey = leader_keypair.pubkey().clone(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_data = leader.data.clone(); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let mut ledger_paths = Vec::new(); let (alice, leader_ledger_path) = genesis("multi_node_basic", 10_000); @@ -345,7 +345,7 @@ fn test_multi_node_basic() { let mut nodes = vec![server]; for _ in 0..N { - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let ledger_path = tmp_copy_ledger(&leader_ledger_path, "multi_node_basic"); ledger_paths.push(ledger_path.clone()); @@ -389,9 +389,9 @@ fn test_multi_node_basic() { #[test] fn test_boot_validator_from_file() -> result::Result<()> { logger::setup(); - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let (alice, leader_ledger_path) = genesis("boot_validator_from_file", 100_000); let mut ledger_paths = Vec::new(); ledger_paths.push(leader_ledger_path.clone()); @@ -405,7 +405,7 @@ fn test_boot_validator_from_file() -> result::Result<()> { send_tx_and_retry_get_balance(&leader_data, &alice, &bob_pubkey, Some(1000)).unwrap(); assert_eq!(leader_balance, 1000); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let validator_data = validator.data.clone(); let ledger_path = tmp_copy_ledger(&leader_ledger_path, "boot_validator_from_file"); @@ -431,7 +431,7 @@ fn test_boot_validator_from_file() -> result::Result<()> { } fn create_leader(ledger_path: &str) -> (NodeInfo, FullNode) { - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_data = leader.data.clone(); let leader_fullnode = FullNode::new(leader, true, &ledger_path, leader_keypair, None); @@ -446,7 +446,7 @@ fn test_leader_restart_validator_start_from_old_ledger() -> result::Result<()> { logger::setup(); let (alice, ledger_path) = genesis("leader_restart_validator_start_from_old_ledger", 100_000); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let (leader_data, leader_fullnode) = create_leader(&ledger_path); @@ -475,7 +475,7 @@ fn test_leader_restart_validator_start_from_old_ledger() -> result::Result<()> { let (leader_data, leader_fullnode) = create_leader(&ledger_path); // start validator from old ledger - let keypair = KeyPair::new(); + let keypair = Keypair::new(); let validator = TestNode::new_localhost_with_pubkey(keypair.pubkey()); let validator_data = validator.data.clone(); @@ -535,10 +535,10 @@ fn test_multi_node_dynamic_network() { Err(_) => std::usize::MAX, }; - let leader_keypair = KeyPair::new(); + let leader_keypair = Keypair::new(); let leader_pubkey = leader_keypair.pubkey().clone(); let leader = TestNode::new_localhost_with_pubkey(leader_keypair.pubkey()); - let bob_pubkey = KeyPair::new().pubkey(); + let bob_pubkey = Keypair::new().pubkey(); let (alice, leader_ledger_path) = genesis("multi_node_dynamic_network", 10_000_000); let mut ledger_paths = Vec::new(); @@ -584,7 +584,7 @@ fn test_multi_node_dynamic_network() { .name("keypair-thread".to_string()) .spawn(move || { info!("Spawned thread {}", n); - let keypair = KeyPair::new(); + let keypair = Keypair::new(); //send some tokens to the new validator let bal = retry_send_tx_and_retry_get_balance( &leader_data,