Rename PublicKey type to Pubkey

Recognize pubkey as a noun meaning the public key of a keypair.
This commit is contained in:
Greg Fitzgerald 2018-08-09 09:13:57 -06:00
parent d7e4e57548
commit ad331e6d56
18 changed files with 156 additions and 156 deletions

View File

@ -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, Pubkey, Signature};
use std::collections::hash_map::Entry::Occupied;
use std::collections::{HashMap, HashSet, VecDeque};
use std::result;
@ -38,13 +38,13 @@ pub const VERIFY_BLOCK_SIZE: usize = 16;
/// Reasons a transaction might be rejected.
#[derive(Debug, PartialEq, Eq)]
pub enum BankError {
/// Attempt to debit from `PublicKey`, but no found no record of a prior credit.
AccountNotFound(PublicKey),
/// Attempt to debit from `Pubkey`, but no found no record of a prior credit.
AccountNotFound(Pubkey),
/// The requested debit from `PublicKey` has the potential to draw the balance
/// The requested debit from `Pubkey` has the potential to draw the balance
/// below zero. This can occur when a debit and credit are processed in parallel.
/// The bank may reject the debit or push it to a future entry.
InsufficientFunds(PublicKey),
InsufficientFunds(Pubkey),
/// The bank has seen `Signature` before. This can occur under normal operation
/// when a UDP packet is duplicated, as a user error from a client not updating
@ -68,7 +68,7 @@ pub type Result<T> = result::Result<T, BankError>;
/// The state of all accounts and contracts after processing its entries.
pub struct Bank {
/// A map of account public keys to the balance in that account.
balances: RwLock<HashMap<PublicKey, i64>>,
balances: RwLock<HashMap<Pubkey, i64>>,
/// A map of smart contract transaction signatures to what remains of its payment
/// plan. Each transaction that targets the plan should cause it to be reduced.
@ -121,7 +121,7 @@ impl Bank {
}
/// Commit funds to the `payment.to` party.
fn apply_payment(&self, payment: &Payment, balances: &mut HashMap<PublicKey, i64>) {
fn apply_payment(&self, payment: &Payment, balances: &mut HashMap<Pubkey, i64>) {
*balances.entry(payment.to).or_insert(0) += payment.tokens;
}
@ -219,7 +219,7 @@ impl Bank {
/// Deduct tokens from the 'from' address the account has sufficient
/// funds and isn't a duplicate.
fn apply_debits(&self, tx: &Transaction, bals: &mut HashMap<PublicKey, i64>) -> Result<()> {
fn apply_debits(&self, tx: &Transaction, bals: &mut HashMap<Pubkey, i64>) -> Result<()> {
let mut purge = false;
{
let option = bals.get_mut(&tx.from);
@ -260,7 +260,7 @@ impl Bank {
/// Apply only a transaction's credits.
/// Note: It is safe to apply credits from multiple transactions in parallel.
fn apply_credits(&self, tx: &Transaction, balances: &mut HashMap<PublicKey, i64>) {
fn apply_credits(&self, tx: &Transaction, balances: &mut HashMap<Pubkey, i64>) {
match &tx.instruction {
Instruction::NewContract(contract) => {
let plan = contract.plan.clone();
@ -470,7 +470,7 @@ impl Bank {
/// Process a Witness Signature. Any payment plans waiting on this signature
/// will progress one step.
fn apply_signature(&self, from: PublicKey, tx_sig: Signature) -> Result<()> {
fn apply_signature(&self, from: Pubkey, tx_sig: Signature) -> Result<()> {
if let Occupied(mut e) = self
.pending
.write()
@ -489,7 +489,7 @@ impl Bank {
/// Process a Witness Timestamp. Any payment plans waiting on this timestamp
/// will progress one step.
fn apply_timestamp(&self, from: PublicKey, dt: DateTime<Utc>) -> Result<()> {
fn apply_timestamp(&self, from: Pubkey, dt: DateTime<Utc>) -> Result<()> {
// Check to see if any timelocked transactions can be completed.
let mut completed = vec![];
@ -520,7 +520,7 @@ impl Bank {
&self,
n: i64,
keypair: &Keypair,
to: PublicKey,
to: Pubkey,
last_id: Hash,
) -> Result<Signature> {
let tx = Transaction::new(keypair, to, n, last_id);
@ -535,7 +535,7 @@ impl Bank {
&self,
n: i64,
keypair: &Keypair,
to: PublicKey,
to: Pubkey,
dt: DateTime<Utc>,
last_id: Hash,
) -> Result<Signature> {
@ -544,7 +544,7 @@ impl Bank {
self.process_transaction(&tx).map(|_| sig)
}
pub fn get_balance(&self, pubkey: &PublicKey) -> i64 {
pub fn get_balance(&self, pubkey: &Pubkey) -> i64 {
let bals = self
.balances
.read()
@ -868,14 +868,14 @@ mod tests {
fn create_sample_ledger_with_next_entries(
length: usize,
) -> (impl Iterator<Item = Entry>, PublicKey) {
) -> (impl Iterator<Item = Entry>, Pubkey) {
let mint = Mint::new((length * length) as i64);
let genesis = mint.create_entries();
let block = create_sample_block_with_next_entries(&mint, length);
(genesis.into_iter().chain(block), mint.pubkey())
}
fn create_sample_ledger(length: usize) -> (impl Iterator<Item = Entry>, PublicKey) {
fn create_sample_ledger(length: usize) -> (impl Iterator<Item = Entry>, Pubkey) {
let mint = Mint::new(1 + length as i64);
let genesis = mint.create_entries();
let block = create_sample_block(&mint, length);

View File

@ -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, Pubkey, Signature};
use solana::thin_client::ThinClient;
use solana::wallet::request_airdrop;
use std::error;
@ -27,7 +27,7 @@ enum WalletCommand {
Address,
Balance,
AirDrop(i64),
Pay(i64, PublicKey),
Pay(i64, Pubkey),
Confirm(Signature),
}
@ -177,11 +177,11 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
.into_vec()
.expect("base58-encoded public key");
if pubkey_vec.len() != std::mem::size_of::<PublicKey>() {
if pubkey_vec.len() != std::mem::size_of::<Pubkey>() {
eprintln!("{}", pay_matches.usage());
Err(WalletError::BadParameter("Invalid public key".to_string()))?;
}
PublicKey::new(&pubkey_vec)
Pubkey::new(&pubkey_vec)
} else {
id.pubkey()
};

View File

@ -5,22 +5,22 @@
use chrono::prelude::*;
use payment_plan::{Payment, PaymentPlan, Witness};
use signature::PublicKey;
use signature::Pubkey;
use std::mem;
/// A data type representing a `Witness` that the payment plan is waiting on.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub enum Condition {
/// Wait for a `Timestamp` `Witness` at or after the given `DateTime`.
Timestamp(DateTime<Utc>, PublicKey),
Timestamp(DateTime<Utc>, Pubkey),
/// Wait for a `Signature` `Witness` from `PublicKey`.
Signature(PublicKey),
/// Wait for a `Signature` `Witness` from `Pubkey`.
Signature(Pubkey),
}
impl Condition {
/// Return true if the given Witness satisfies this Condition.
pub fn is_satisfied(&self, witness: &Witness, from: &PublicKey) -> bool {
pub fn is_satisfied(&self, witness: &Witness, from: &Pubkey) -> bool {
match (self, witness) {
(Condition::Signature(pubkey), Witness::Signature) => pubkey == from,
(Condition::Timestamp(dt, pubkey), Witness::Timestamp(last_time)) => {
@ -47,22 +47,22 @@ pub enum Budget {
}
impl Budget {
/// Create the simplest budget - one that pays `tokens` to PublicKey.
pub fn new_payment(tokens: i64, to: PublicKey) -> Self {
/// Create the simplest budget - one that pays `tokens` to Pubkey.
pub fn new_payment(tokens: i64, to: Pubkey) -> Self {
Budget::Pay(Payment { tokens, to })
}
/// Create a budget that pays `tokens` to `to` after being witnessed by `from`.
pub fn new_authorized_payment(from: PublicKey, tokens: i64, to: PublicKey) -> Self {
pub fn new_authorized_payment(from: Pubkey, tokens: i64, to: Pubkey) -> Self {
Budget::After(Condition::Signature(from), Payment { tokens, to })
}
/// Create a budget that pays `tokens` to `to` after the given DateTime.
pub fn new_future_payment(
dt: DateTime<Utc>,
from: PublicKey,
from: Pubkey,
tokens: i64,
to: PublicKey,
to: Pubkey,
) -> Self {
Budget::After(Condition::Timestamp(dt, from), Payment { tokens, to })
}
@ -71,9 +71,9 @@ impl Budget {
/// unless cancelled by `from`.
pub fn new_cancelable_future_payment(
dt: DateTime<Utc>,
from: PublicKey,
from: Pubkey,
tokens: i64,
to: PublicKey,
to: Pubkey,
) -> Self {
Budget::Or(
(Condition::Timestamp(dt, from), Payment { tokens, to }),
@ -101,7 +101,7 @@ impl PaymentPlan for Budget {
/// Apply a witness to the budget to see if the budget can be reduced.
/// If so, modify the budget in-place.
fn apply_witness(&mut self, witness: &Witness, from: &PublicKey) {
fn apply_witness(&mut self, witness: &Witness, from: &Pubkey) {
let new_payment = match self {
Budget::After(cond, payment) if cond.is_satisfied(witness, from) => Some(payment),
Budget::Or((cond, payment), _) if cond.is_satisfied(witness, from) => Some(payment),
@ -122,7 +122,7 @@ mod tests {
#[test]
fn test_signature_satisfied() {
let from = PublicKey::default();
let from = Pubkey::default();
assert!(Condition::Signature(from).is_satisfied(&Witness::Signature, &from));
}
@ -130,7 +130,7 @@ mod tests {
fn test_timestamp_satisfied() {
let dt1 = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
let dt2 = Utc.ymd(2014, 11, 14).and_hms(10, 9, 8);
let from = PublicKey::default();
let from = Pubkey::default();
assert!(Condition::Timestamp(dt1, from).is_satisfied(&Witness::Timestamp(dt1), &from));
assert!(Condition::Timestamp(dt1, from).is_satisfied(&Witness::Timestamp(dt2), &from));
assert!(!Condition::Timestamp(dt2, from).is_satisfied(&Witness::Timestamp(dt1), &from));
@ -139,8 +139,8 @@ mod tests {
#[test]
fn test_verify() {
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
let from = PublicKey::default();
let to = PublicKey::default();
let from = Pubkey::default();
let to = Pubkey::default();
assert!(Budget::new_payment(42, to).verify(42));
assert!(Budget::new_authorized_payment(from, 42, to).verify(42));
assert!(Budget::new_future_payment(dt, from, 42, to).verify(42));
@ -149,8 +149,8 @@ mod tests {
#[test]
fn test_authorized_payment() {
let from = PublicKey::default();
let to = PublicKey::default();
let from = Pubkey::default();
let to = Pubkey::default();
let mut budget = Budget::new_authorized_payment(from, 42, to);
budget.apply_witness(&Witness::Signature, &from);
@ -185,8 +185,8 @@ mod tests {
#[test]
fn test_cancelable_future_payment() {
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
let from = PublicKey::default();
let to = PublicKey::default();
let from = Pubkey::default();
let to = Pubkey::default();
let mut budget = Budget::new_cancelable_future_payment(dt, from, 42, to);
budget.apply_witness(&Witness::Timestamp(dt), &from);

View File

@ -2,7 +2,7 @@ use crdt::{CrdtError, NodeInfo};
use rand::distributions::{Distribution, Weighted, WeightedChoice};
use rand::thread_rng;
use result::Result;
use signature::PublicKey;
use signature::Pubkey;
use std;
use std::collections::HashMap;
@ -61,21 +61,21 @@ impl<'a> ChooseGossipPeerStrategy for ChooseRandomPeerStrategy<'a> {
pub struct ChooseWeightedPeerStrategy<'a> {
// The map of last directly observed update_index for each active validator.
// This is how we get observed(v) from the formula above.
remote: &'a HashMap<PublicKey, u64>,
remote: &'a HashMap<Pubkey, u64>,
// The map of rumored update_index for each active validator. Using the formula above,
// to find rumor_v(i), we would first look up "v" in the outer map, then look up
// "i" in the inner map, i.e. look up external_liveness[v][i]
external_liveness: &'a HashMap<PublicKey, HashMap<PublicKey, u64>>,
external_liveness: &'a HashMap<Pubkey, HashMap<Pubkey, u64>>,
// A function returning the size of the stake for a particular validator, corresponds
// to stake(i) in the formula above.
get_stake: &'a Fn(PublicKey) -> f64,
get_stake: &'a Fn(Pubkey) -> f64,
}
impl<'a> ChooseWeightedPeerStrategy<'a> {
pub fn new(
remote: &'a HashMap<PublicKey, u64>,
external_liveness: &'a HashMap<PublicKey, HashMap<PublicKey, u64>>,
get_stake: &'a Fn(PublicKey) -> f64,
remote: &'a HashMap<Pubkey, u64>,
external_liveness: &'a HashMap<Pubkey, HashMap<Pubkey, u64>>,
get_stake: &'a Fn(Pubkey) -> f64,
) -> Self {
ChooseWeightedPeerStrategy {
remote,
@ -84,7 +84,7 @@ impl<'a> ChooseWeightedPeerStrategy<'a> {
}
}
fn calculate_weighted_remote_index(&self, peer_id: PublicKey) -> u32 {
fn calculate_weighted_remote_index(&self, peer_id: Pubkey) -> u32 {
let mut last_seen_index = 0;
// If the peer is not in our remote table, then we leave last_seen_index as zero.
// Only happens when a peer appears in our crdt.table but not in our crdt.remote,
@ -192,11 +192,11 @@ 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, Pubkey};
use std;
use std::collections::HashMap;
fn get_stake(_id: PublicKey) -> f64 {
fn get_stake(_id: Pubkey) -> f64 {
1.0
}
@ -207,8 +207,8 @@ mod tests {
// Initialize the filler keys
let key1 = Keypair::new().pubkey();
let remote: HashMap<PublicKey, u64> = HashMap::new();
let external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
let remote: HashMap<Pubkey, u64> = HashMap::new();
let external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
let weighted_strategy =
ChooseWeightedPeerStrategy::new(&remote, &external_liveness, &get_stake);
@ -227,13 +227,13 @@ mod tests {
let key1 = Keypair::new().pubkey();
let key2 = Keypair::new().pubkey();
let remote: HashMap<PublicKey, u64> = HashMap::new();
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
let remote: HashMap<Pubkey, u64> = HashMap::new();
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
// If only the liveness table contains the entry, should return the
// weighted liveness entries
let test_value: u32 = 5;
let mut rumors: HashMap<PublicKey, u64> = HashMap::new();
let mut rumors: HashMap<Pubkey, u64> = HashMap::new();
rumors.insert(key2, test_value as u64);
external_liveness.insert(key1, rumors);
@ -252,12 +252,12 @@ mod tests {
let key1 = Keypair::new().pubkey();
let key2 = Keypair::new().pubkey();
let remote: HashMap<PublicKey, u64> = HashMap::new();
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
let remote: HashMap<Pubkey, u64> = HashMap::new();
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
// If the vote index is greater than u32::MAX, default to u32::MAX
let test_value = (std::u32::MAX as u64) + 10;
let mut rumors: HashMap<PublicKey, u64> = HashMap::new();
let mut rumors: HashMap<Pubkey, u64> = HashMap::new();
rumors.insert(key2, test_value);
external_liveness.insert(key1, rumors);
@ -275,12 +275,12 @@ mod tests {
// Initialize the filler keys
let key1 = Keypair::new().pubkey();
let mut remote: HashMap<PublicKey, u64> = HashMap::new();
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
let mut remote: HashMap<Pubkey, u64> = HashMap::new();
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
// Test many validators' rumors in external_liveness
let num_peers = 10;
let mut rumors: HashMap<PublicKey, u64> = HashMap::new();
let mut rumors: HashMap<Pubkey, u64> = HashMap::new();
remote.insert(key1, 0);
@ -305,13 +305,13 @@ mod tests {
// Initialize the filler keys
let key1 = Keypair::new().pubkey();
let mut remote: HashMap<PublicKey, u64> = HashMap::new();
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
let mut remote: HashMap<Pubkey, u64> = HashMap::new();
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
// Test many validators' rumors in external_liveness
let num_peers = 10;
let old_index = 20;
let mut rumors: HashMap<PublicKey, u64> = HashMap::new();
let mut rumors: HashMap<Pubkey, u64> = HashMap::new();
remote.insert(key1, old_index);

View File

@ -2,7 +2,7 @@
//! a gossip control plane. The goal is to share small bits of off-chain information and detect and
//! repair partitions.
//!
//! This CRDT only supports a very limited set of types. A map of PublicKey -> Versioned Struct.
//! This CRDT only supports a very limited set of types. A map of Pubkey -> Versioned Struct.
//! The last version is always picked during an update.
//!
//! The network is arranged in layers:
@ -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, Pubkey};
use std;
use std::collections::HashMap;
use std::collections::VecDeque;
@ -126,18 +126,18 @@ pub struct LedgerState {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct NodeInfo {
pub id: PublicKey,
pub id: Pubkey,
/// If any of the bits change, update increment this value
pub version: u64,
/// network addresses
pub contact_info: ContactInfo,
/// current leader identity
pub leader_id: PublicKey,
pub leader_id: Pubkey,
/// information about the state of the ledger
pub ledger_state: LedgerState,
}
fn make_debug_id(key: &PublicKey) -> u64 {
fn make_debug_id(key: &Pubkey) -> u64 {
let buf: &[u8] = &key.as_ref();
let mut rdr = Cursor::new(&buf[..8]);
rdr.read_u64::<LittleEndian>()
@ -146,7 +146,7 @@ fn make_debug_id(key: &PublicKey) -> u64 {
impl NodeInfo {
pub fn new(
id: PublicKey,
id: Pubkey,
ncp: SocketAddr,
tvu: SocketAddr,
rpu: SocketAddr,
@ -164,7 +164,7 @@ impl NodeInfo {
tvu_window,
version: 0,
},
leader_id: PublicKey::default(),
leader_id: Pubkey::default(),
ledger_state: LedgerState {
last_id: Hash::default(),
},
@ -207,7 +207,7 @@ impl NodeInfo {
nxt_addr.set_port(addr.port() + nxt);
nxt_addr
}
pub fn new_leader_with_pubkey(pubkey: PublicKey, bind_addr: &SocketAddr) -> Self {
pub fn new_leader_with_pubkey(pubkey: Pubkey, bind_addr: &SocketAddr) -> Self {
let transactions_addr = *bind_addr;
let gossip_addr = Self::next_port(&bind_addr, 1);
let replicate_addr = Self::next_port(&bind_addr, 2);
@ -229,7 +229,7 @@ impl NodeInfo {
pub fn new_entry_point(gossip_addr: SocketAddr) -> Self {
let daddr: SocketAddr = "0.0.0.0:0".parse().unwrap();
NodeInfo::new(
PublicKey::default(),
Pubkey::default(),
gossip_addr,
daddr,
daddr,
@ -252,22 +252,22 @@ impl NodeInfo {
/// No attempt to keep track of timeouts or dropped requests is made, or should be.
pub struct Crdt {
/// table of everyone in the network
pub table: HashMap<PublicKey, NodeInfo>,
pub table: HashMap<Pubkey, NodeInfo>,
/// Value of my update index when entry in table was updated.
/// Nodes will ask for updates since `update_index`, and this node
/// should respond with all the identities that are greater then the
/// request's `update_index` in this list
local: HashMap<PublicKey, u64>,
local: HashMap<Pubkey, u64>,
/// The value of the remote update index that I have last seen
/// This Node will ask external nodes for updates since the value in this list
pub remote: HashMap<PublicKey, u64>,
pub remote: HashMap<Pubkey, u64>,
/// last time the public key had sent us a message
pub alive: HashMap<PublicKey, u64>,
pub alive: HashMap<Pubkey, u64>,
pub update_index: u64,
pub me: PublicKey,
pub me: Pubkey,
/// last time we heard from anyone getting a message fro this public key
/// these are rumers and shouldn't be trusted directly
external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>>,
external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>>,
}
// TODO These messages should be signed, and go through the gpu pipeline for spam filtering
#[derive(Serialize, Deserialize, Debug)]
@ -279,7 +279,7 @@ enum Protocol {
RequestUpdates(u64, NodeInfo),
//TODO might need a since?
/// from id, form's last update index, NodeInfo
ReceiveUpdates(PublicKey, u64, Vec<NodeInfo>, Vec<(PublicKey, u64)>),
ReceiveUpdates(Pubkey, u64, Vec<NodeInfo>, Vec<(Pubkey, u64)>),
/// ask for a missing index
/// (my replicated data to keep alive, missing window index)
RequestWindowIndex(NodeInfo, u64),
@ -334,14 +334,14 @@ impl Crdt {
let leader_id = self.table[&self.me].leader_id;
// leader_id can be 0s from network entry point
if leader_id == PublicKey::default() {
if leader_id == Pubkey::default() {
return None;
}
self.table.get(&leader_id)
}
pub fn set_leader(&mut self, key: PublicKey) -> () {
pub fn set_leader(&mut self, key: Pubkey) -> () {
let mut me = self.my_data().clone();
warn!(
"{:x}: LEADER_UPDATE TO {:x} from {:x}",
@ -354,11 +354,11 @@ impl Crdt {
self.insert(&me);
}
pub fn get_external_liveness_entry(&self, key: &PublicKey) -> Option<&HashMap<PublicKey, u64>> {
pub fn get_external_liveness_entry(&self, key: &Pubkey) -> Option<&HashMap<Pubkey, u64>> {
self.external_liveness.get(key)
}
pub fn insert_vote(&mut self, pubkey: &PublicKey, v: &Vote, last_id: Hash) {
pub fn insert_vote(&mut self, pubkey: &Pubkey, v: &Vote, last_id: Hash) {
if self.table.get(pubkey).is_none() {
warn!(
"{:x}: VOTE for unknown id: {:x}",
@ -408,7 +408,7 @@ impl Crdt {
self.insert(&data);
}
}
pub fn insert_votes(&mut self, votes: &[(PublicKey, Vote, Hash)]) {
pub fn insert_votes(&mut self, votes: &[(Pubkey, Vote, Hash)]) {
inc_new_counter_info!("crdt-vote-count", votes.len());
if !votes.is_empty() {
info!("{:x}: INSERTING VOTES {}", self.debug_id(), votes.len());
@ -451,7 +451,7 @@ impl Crdt {
}
}
fn update_liveness(&mut self, id: PublicKey) {
fn update_liveness(&mut self, id: Pubkey) {
//update the liveness table
let now = timestamp();
trace!(
@ -477,7 +477,7 @@ impl Crdt {
}
let leader_id = self.leader_data().unwrap().id;
let limit = GOSSIP_PURGE_MILLIS;
let dead_ids: Vec<PublicKey> = self
let dead_ids: Vec<Pubkey> = self
.alive
.iter()
.filter_map(|(&k, v)| {
@ -515,7 +515,7 @@ impl Crdt {
make_debug_id(id),
);
inc_new_counter_info!("crdt-purge-purged_leader", 1, 1);
self.set_leader(PublicKey::default());
self.set_leader(Pubkey::default());
}
}
}
@ -739,16 +739,16 @@ impl Crdt {
}
// TODO: fill in with real implmentation once staking is implemented
fn get_stake(_id: PublicKey) -> f64 {
fn get_stake(_id: Pubkey) -> f64 {
1.0
}
fn get_updates_since(&self, v: u64) -> (PublicKey, u64, Vec<NodeInfo>) {
fn get_updates_since(&self, v: u64) -> (Pubkey, u64, Vec<NodeInfo>) {
//trace!("get updates since {}", v);
let data = self
.table
.values()
.filter(|x| x.id != PublicKey::default() && self.local[&x.id] > v)
.filter(|x| x.id != Pubkey::default() && self.local[&x.id] > v)
.cloned()
.collect();
let id = self.me;
@ -855,16 +855,16 @@ impl Crdt {
Ok(())
}
/// TODO: This is obviously the wrong way to do this. Need to implement leader selection
fn top_leader(&self) -> Option<PublicKey> {
fn top_leader(&self) -> Option<Pubkey> {
let mut table = HashMap::new();
let def = PublicKey::default();
let def = Pubkey::default();
let cur = self.table.values().filter(|x| x.leader_id != def);
for v in cur {
let cnt = table.entry(&v.leader_id).or_insert(0);
*cnt += 1;
trace!("leader {:x} {}", make_debug_id(&v.leader_id), *cnt);
}
let mut sorted: Vec<(&PublicKey, usize)> = table.into_iter().collect();
let mut sorted: Vec<(&Pubkey, usize)> = table.into_iter().collect();
let my_id = self.debug_id();
for x in &sorted {
trace!(
@ -895,10 +895,10 @@ impl Crdt {
/// * `data` - the update data
fn apply_updates(
&mut self,
from: PublicKey,
from: Pubkey,
update_index: u64,
data: &[NodeInfo],
external_liveness: &[(PublicKey, u64)],
external_liveness: &[(Pubkey, u64)],
) {
trace!("got updates {}", data.len());
// TODO we need to punish/spam resist here
@ -1272,7 +1272,7 @@ impl TestNode {
let pubkey = Keypair::new().pubkey();
Self::new_localhost_with_pubkey(pubkey)
}
pub fn new_localhost_with_pubkey(pubkey: PublicKey) -> Self {
pub fn new_localhost_with_pubkey(pubkey: Pubkey) -> Self {
let transaction = UdpSocket::bind("127.0.0.1:0").unwrap();
let gossip = UdpSocket::bind("127.0.0.1:0").unwrap();
let replicate = UdpSocket::bind("127.0.0.1:0").unwrap();
@ -1381,7 +1381,7 @@ mod tests {
use logger;
use packet::BlobRecycler;
use result::Error;
use signature::{Keypair, KeypairUtil, PublicKey};
use signature::{Keypair, KeypairUtil, Pubkey};
use std::fs::remove_dir_all;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::channel;
@ -1884,7 +1884,7 @@ mod tests {
let len = crdt.table.len() as u64;
crdt.purge(now + GOSSIP_PURGE_MILLIS + 1);
assert_eq!(len as usize - 1, crdt.table.len());
assert_eq!(crdt.my_data().leader_id, PublicKey::default());
assert_eq!(crdt.my_data().leader_id, Pubkey::default());
assert!(crdt.leader_data().is_none());
}

View File

@ -7,7 +7,7 @@
use influx_db_client as influxdb;
use metrics;
use signature::Signature;
use signature::{Keypair, PublicKey};
use signature::{Keypair, Pubkey};
use std::io;
use std::io::{Error, ErrorKind};
use std::net::{IpAddr, SocketAddr, UdpSocket};
@ -23,7 +23,7 @@ pub const DRONE_PORT: u16 = 9900;
pub enum DroneRequest {
GetAirdrop {
airdrop_request_amount: u64,
client_pubkey: PublicKey,
client_pubkey: Pubkey,
},
}

View File

@ -6,7 +6,7 @@ use bincode::{serialize_into, serialized_size};
use hash::{extend_and_hash, hash, Hash};
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE};
use rayon::prelude::*;
use signature::PublicKey;
use signature::Pubkey;
use std::io::Cursor;
use std::net::SocketAddr;
use transaction::Transaction;
@ -83,7 +83,7 @@ impl Entry {
&self,
blob_recycler: &BlobRecycler,
idx: Option<u64>,
id: Option<PublicKey>,
id: Option<Pubkey>,
addr: Option<&SocketAddr>,
) -> SharedBlob {
let blob = blob_recycler.allocate();

View File

@ -3,14 +3,14 @@
use entry::Entry;
use hash::{hash, Hash};
use ring::rand::SystemRandom;
use signature::{Keypair, KeypairUtil, PublicKey};
use signature::{Keypair, KeypairUtil, Pubkey};
use transaction::Transaction;
use untrusted::Input;
#[derive(Serialize, Deserialize, Debug)]
pub struct Mint {
pub pkcs8: Vec<u8>,
pubkey: PublicKey,
pubkey: Pubkey,
pub tokens: i64,
}
@ -46,7 +46,7 @@ impl Mint {
Keypair::from_pkcs8(Input::from(&self.pkcs8)).expect("from_pkcs8 in mint pub fn keypair")
}
pub fn pubkey(&self) -> PublicKey {
pub fn pubkey(&self) -> Pubkey {
self.pubkey
}

View File

@ -5,7 +5,7 @@ use counter::Counter;
use log::Level;
use result::{Error, Result};
use serde::Serialize;
use signature::PublicKey;
use signature::Pubkey;
use std::collections::VecDeque;
use std::fmt;
use std::io;
@ -302,7 +302,7 @@ pub fn to_blobs<T: Serialize>(
}
const BLOB_INDEX_END: usize = size_of::<u64>();
const BLOB_ID_END: usize = BLOB_INDEX_END + size_of::<usize>() + size_of::<PublicKey>();
const BLOB_ID_END: usize = BLOB_INDEX_END + size_of::<usize>() + size_of::<Pubkey>();
const BLOB_FLAGS_END: usize = BLOB_ID_END + size_of::<u32>();
const BLOB_SIZE_END: usize = BLOB_FLAGS_END + size_of::<u64>();
@ -329,12 +329,12 @@ impl Blob {
}
/// sender id, we use this for identifying if its a blob from the leader that we should
/// retransmit. eventually blobs should have a signature that we can use ffor spam filtering
pub fn get_id(&self) -> Result<PublicKey> {
pub fn get_id(&self) -> Result<Pubkey> {
let e = deserialize(&self.data[BLOB_INDEX_END..BLOB_ID_END])?;
Ok(e)
}
pub fn set_id(&mut self, id: PublicKey) -> Result<()> {
pub fn set_id(&mut self, id: Pubkey) -> Result<()> {
let wtr = serialize(&id)?;
self.data[BLOB_INDEX_END..BLOB_ID_END].clone_from_slice(&wtr);
Ok(())

View File

@ -4,7 +4,7 @@
//! `Payment`, the payment is executed.
use chrono::prelude::*;
use signature::PublicKey;
use signature::Pubkey;
/// The types of events a payment plan can process.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
@ -12,18 +12,18 @@ pub enum Witness {
/// The current time.
Timestamp(DateTime<Utc>),
/// A siganture from PublicKey.
/// A siganture from Pubkey.
Signature,
}
/// Some amount of tokens that should be sent to the `to` `PublicKey`.
/// Some amount of tokens that should be sent to the `to` `Pubkey`.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Payment {
/// Amount to be paid.
pub tokens: i64,
/// The `PublicKey` that `tokens` should be paid to.
pub to: PublicKey,
/// The `Pubkey` that `tokens` should be paid to.
pub to: Pubkey,
}
/// Interface to smart contracts.
@ -36,5 +36,5 @@ pub trait PaymentPlan {
/// Apply a witness to the payment plan to see if the plan can be reduced.
/// If so, modify the plan in-place.
fn apply_witness(&mut self, witness: &Witness, from: &PublicKey);
fn apply_witness(&mut self, witness: &Witness, from: &Pubkey);
}

View File

@ -1,12 +1,12 @@
//! The `request` module defines the messages for the thin client.
use hash::Hash;
use signature::{PublicKey, Signature};
use signature::{Pubkey, Signature};
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub enum Request {
GetBalance { key: PublicKey },
GetBalance { key: Pubkey },
GetLastId,
GetTransactionCount,
GetSignature { signature: Signature },
@ -21,7 +21,7 @@ impl Request {
#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
Balance { key: PublicKey, val: i64 },
Balance { key: Pubkey, val: i64 },
LastId { id: Hash },
TransactionCount { transaction_count: u64 },
SignatureStatus { signature_status: bool },

View File

@ -15,27 +15,27 @@ use untrusted::Input;
pub type Keypair = Ed25519KeyPair;
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct PublicKey(GenericArray<u8, U32>);
pub struct Pubkey(GenericArray<u8, U32>);
impl PublicKey {
impl Pubkey {
pub fn new(pubkey_vec: &[u8]) -> Self {
PublicKey(GenericArray::clone_from_slice(&pubkey_vec))
Pubkey(GenericArray::clone_from_slice(&pubkey_vec))
}
}
impl AsRef<[u8]> for PublicKey {
impl AsRef<[u8]> for Pubkey {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl fmt::Debug for PublicKey {
impl fmt::Debug for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
impl fmt::Display for PublicKey {
impl fmt::Display for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
@ -76,7 +76,7 @@ impl fmt::Display for Signature {
pub trait KeypairUtil {
fn new() -> Self;
fn pubkey(&self) -> PublicKey;
fn pubkey(&self) -> Pubkey;
}
impl KeypairUtil for Ed25519KeyPair {
@ -88,8 +88,8 @@ impl KeypairUtil for Ed25519KeyPair {
}
/// Return the public key for the given keypair
fn pubkey(&self) -> PublicKey {
PublicKey(GenericArray::clone_from_slice(self.public_key_bytes()))
fn pubkey(&self) -> Pubkey {
Pubkey(GenericArray::clone_from_slice(self.public_key_bytes()))
}
}
@ -149,7 +149,7 @@ mod tests {
}
}
fn gen_n_pubkeys(seed: [u8; 32], n: i64) -> HashSet<PublicKey> {
fn gen_n_pubkeys(seed: [u8; 32], n: i64) -> HashSet<Pubkey> {
GenKeys::new(seed)
.gen_n_keypairs(n)
.into_iter()

View File

@ -44,14 +44,14 @@ pub fn init() {
fn verify_packet(packet: &Packet) -> u8 {
use ring::signature;
use signature::{PublicKey, Signature};
use signature::{Pubkey, Signature};
use untrusted;
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
let sig_start = TX_OFFSET + SIG_OFFSET;
let sig_end = sig_start + size_of::<Signature>();
let pubkey_start = TX_OFFSET + PUB_KEY_OFFSET;
let pubkey_end = pubkey_start + size_of::<PublicKey>();
let pubkey_end = pubkey_start + size_of::<Pubkey>();
if packet.meta.size <= msg_start {
return 0;

View File

@ -6,7 +6,7 @@
use bincode::{deserialize, serialize};
use hash::Hash;
use request::{Request, Response};
use signature::{Keypair, PublicKey, Signature};
use signature::{Keypair, Pubkey, Signature};
use std::collections::HashMap;
use std::io;
use std::net::{SocketAddr, UdpSocket};
@ -27,7 +27,7 @@ pub struct ThinClient {
transactions_socket: UdpSocket,
last_id: Option<Hash>,
transaction_count: u64,
balances: HashMap<PublicKey, i64>,
balances: HashMap<Pubkey, i64>,
signature_status: bool,
}
@ -100,7 +100,7 @@ impl ThinClient {
&self,
n: i64,
keypair: &Keypair,
to: PublicKey,
to: Pubkey,
last_id: &Hash,
) -> io::Result<Signature> {
let now = Instant::now();
@ -121,7 +121,7 @@ impl ThinClient {
/// Request the balance of the user holding `pubkey`. This method blocks
/// until the server sends a response. If the response packet is dropped
/// by the network, this method will hang indefinitely.
pub fn get_balance(&mut self, pubkey: &PublicKey) -> io::Result<i64> {
pub fn get_balance(&mut self, pubkey: &Pubkey) -> io::Result<i64> {
trace!("get_balance");
let req = Request::GetBalance { key: *pubkey };
let data = serialize(&req).expect("serialize GetBalance in pub fn get_balance");
@ -195,7 +195,7 @@ impl ThinClient {
self.last_id.expect("some last_id")
}
pub fn poll_get_balance(&mut self, pubkey: &PublicKey) -> io::Result<i64> {
pub fn poll_get_balance(&mut self, pubkey: &Pubkey) -> io::Result<i64> {
let mut balance_result;
let mut balance_value = -1;
let now = Instant::now();

View File

@ -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, Pubkey, Signature};
pub const SIGNED_DATA_OFFSET: usize = 112;
pub const SIG_OFFSET: usize = 8;
@ -32,7 +32,7 @@ impl PaymentPlan for Plan {
}
}
fn apply_witness(&mut self, witness: &Witness, from: &PublicKey) {
fn apply_witness(&mut self, witness: &Witness, from: &Pubkey) {
match self {
Plan::Budget(budget) => budget.apply_witness(witness, from),
}
@ -68,21 +68,21 @@ pub enum Instruction {
ApplyTimestamp(DateTime<Utc>),
/// Tell the payment plan that the `NewContract` with `Signature` has been
/// signed by the containing transaction's `PublicKey`.
/// signed by the containing transaction's `Pubkey`.
ApplySignature(Signature),
/// Vote for a PoH that is equal to the lastid of this transaction
NewVote(Vote),
}
/// An instruction signed by a client with `PublicKey`.
/// An instruction signed by a client with `Pubkey`.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Transaction {
/// A digital signature of `instruction`, `last_id` and `fee`, signed by `PublicKey`.
/// A digital signature of `instruction`, `last_id` and `fee`, signed by `Pubkey`.
pub sig: Signature,
/// The `PublicKey` of the entity that signed the transaction data.
pub from: PublicKey,
/// The `Pubkey` of the entity that signed the transaction data.
pub from: Pubkey,
/// The action the server should take.
pub instruction: Instruction,
@ -117,7 +117,7 @@ impl Transaction {
/// Create and sign a new Transaction. Used for unit-testing.
pub fn new_taxed(
from_keypair: &Keypair,
to: PublicKey,
to: Pubkey,
tokens: i64,
fee: i64,
last_id: Hash,
@ -133,7 +133,7 @@ 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: Pubkey, tokens: i64, last_id: Hash) -> Self {
Self::new_taxed(from_keypair, to, tokens, 0, last_id)
}
@ -156,7 +156,7 @@ impl Transaction {
/// Create and sign a postdated Transaction. Used for unit-testing.
pub fn new_on_date(
from_keypair: &Keypair,
to: PublicKey,
to: Pubkey,
dt: DateTime<Utc>,
tokens: i64,
last_id: Hash,

View File

@ -1,16 +1,16 @@
use entry::Entry;
use hash::Hash;
use signature::PublicKey;
use signature::Pubkey;
use transaction::{Instruction, Transaction, Vote};
pub fn entries_to_votes(entries: &[Entry]) -> Vec<(PublicKey, Vote, Hash)> {
pub fn entries_to_votes(entries: &[Entry]) -> Vec<(Pubkey, Vote, Hash)> {
entries
.iter()
.flat_map(|entry| entry.transactions.iter().filter_map(transaction_to_vote))
.collect()
}
pub fn transaction_to_vote(tx: &Transaction) -> Option<(PublicKey, Vote, Hash)> {
pub fn transaction_to_vote(tx: &Transaction) -> Option<(Pubkey, Vote, Hash)> {
match tx.instruction {
Instruction::NewVote(ref vote) => Some((tx.from, vote.clone(), tx.last_id)),
_ => None,

View File

@ -1,13 +1,13 @@
use bincode::serialize;
use drone::DroneRequest;
use signature::PublicKey;
use signature::Pubkey;
use std::error;
use std::io::Write;
use std::net::{SocketAddr, TcpStream};
pub fn request_airdrop(
drone_addr: &SocketAddr,
id: &PublicKey,
id: &Pubkey,
tokens: u64,
) -> Result<(), Box<error::Error>> {
let mut stream = TcpStream::connect(drone_addr)?;

View File

@ -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, Pubkey};
use solana::streamer::{default_window, WINDOW_SIZE};
use solana::thin_client::ThinClient;
use solana::timing::duration_as_s;
@ -751,7 +751,7 @@ fn mk_client(leader: &NodeInfo) -> ThinClient {
fn retry_get_balance(
client: &mut ThinClient,
bob_pubkey: &PublicKey,
bob_pubkey: &Pubkey,
expected: Option<i64>,
) -> Option<i64> {
const LAST: usize = 30;
@ -773,7 +773,7 @@ fn retry_get_balance(
fn send_tx_and_retry_get_balance(
leader: &NodeInfo,
alice: &Mint,
bob_pubkey: &PublicKey,
bob_pubkey: &Pubkey,
expected: Option<i64>,
) -> Option<i64> {
let mut client = mk_client(leader);
@ -789,7 +789,7 @@ fn send_tx_and_retry_get_balance(
fn retry_send_tx_and_retry_get_balance(
leader: &NodeInfo,
alice: &Mint,
bob_pubkey: &PublicKey,
bob_pubkey: &Pubkey,
expected: Option<i64>,
) -> Option<i64> {
let mut client = mk_client(leader);