Rename PublicKey type to Pubkey
Recognize pubkey as a noun meaning the public key of a keypair.
This commit is contained in:
32
src/bank.rs
32
src/bank.rs
@ -14,7 +14,7 @@ use ledger::Block;
|
|||||||
use log::Level;
|
use log::Level;
|
||||||
use mint::Mint;
|
use mint::Mint;
|
||||||
use payment_plan::{Payment, PaymentPlan, Witness};
|
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::hash_map::Entry::Occupied;
|
||||||
use std::collections::{HashMap, HashSet, VecDeque};
|
use std::collections::{HashMap, HashSet, VecDeque};
|
||||||
use std::result;
|
use std::result;
|
||||||
@ -38,13 +38,13 @@ pub const VERIFY_BLOCK_SIZE: usize = 16;
|
|||||||
/// Reasons a transaction might be rejected.
|
/// Reasons a transaction might be rejected.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum BankError {
|
pub enum BankError {
|
||||||
/// Attempt to debit from `PublicKey`, but no found no record of a prior credit.
|
/// Attempt to debit from `Pubkey`, but no found no record of a prior credit.
|
||||||
AccountNotFound(PublicKey),
|
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.
|
/// 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.
|
/// 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
|
/// 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
|
/// 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.
|
/// The state of all accounts and contracts after processing its entries.
|
||||||
pub struct Bank {
|
pub struct Bank {
|
||||||
/// A map of account public keys to the balance in that account.
|
/// 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
|
/// 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.
|
/// 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.
|
/// 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;
|
*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
|
/// Deduct tokens from the 'from' address the account has sufficient
|
||||||
/// funds and isn't a duplicate.
|
/// 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 mut purge = false;
|
||||||
{
|
{
|
||||||
let option = bals.get_mut(&tx.from);
|
let option = bals.get_mut(&tx.from);
|
||||||
@ -260,7 +260,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// Apply only a transaction's credits.
|
/// Apply only a transaction's credits.
|
||||||
/// Note: It is safe to apply credits from multiple transactions in parallel.
|
/// 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 {
|
match &tx.instruction {
|
||||||
Instruction::NewContract(contract) => {
|
Instruction::NewContract(contract) => {
|
||||||
let plan = contract.plan.clone();
|
let plan = contract.plan.clone();
|
||||||
@ -470,7 +470,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// Process a Witness Signature. Any payment plans waiting on this signature
|
/// Process a Witness Signature. Any payment plans waiting on this signature
|
||||||
/// will progress one step.
|
/// 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
|
if let Occupied(mut e) = self
|
||||||
.pending
|
.pending
|
||||||
.write()
|
.write()
|
||||||
@ -489,7 +489,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// Process a Witness Timestamp. Any payment plans waiting on this timestamp
|
/// Process a Witness Timestamp. Any payment plans waiting on this timestamp
|
||||||
/// will progress one step.
|
/// 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.
|
// Check to see if any timelocked transactions can be completed.
|
||||||
let mut completed = vec![];
|
let mut completed = vec![];
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ impl Bank {
|
|||||||
&self,
|
&self,
|
||||||
n: i64,
|
n: i64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let tx = Transaction::new(keypair, to, n, last_id);
|
let tx = Transaction::new(keypair, to, n, last_id);
|
||||||
@ -535,7 +535,7 @@ impl Bank {
|
|||||||
&self,
|
&self,
|
||||||
n: i64,
|
n: i64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
@ -544,7 +544,7 @@ impl Bank {
|
|||||||
self.process_transaction(&tx).map(|_| sig)
|
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
|
let bals = self
|
||||||
.balances
|
.balances
|
||||||
.read()
|
.read()
|
||||||
@ -868,14 +868,14 @@ mod tests {
|
|||||||
|
|
||||||
fn create_sample_ledger_with_next_entries(
|
fn create_sample_ledger_with_next_entries(
|
||||||
length: usize,
|
length: usize,
|
||||||
) -> (impl Iterator<Item = Entry>, PublicKey) {
|
) -> (impl Iterator<Item = Entry>, Pubkey) {
|
||||||
let mint = Mint::new((length * length) as i64);
|
let mint = Mint::new((length * length) as i64);
|
||||||
let genesis = mint.create_entries();
|
let genesis = mint.create_entries();
|
||||||
let block = create_sample_block_with_next_entries(&mint, length);
|
let block = create_sample_block_with_next_entries(&mint, length);
|
||||||
(genesis.into_iter().chain(block), mint.pubkey())
|
(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 mint = Mint::new(1 + length as i64);
|
||||||
let genesis = mint.create_entries();
|
let genesis = mint.create_entries();
|
||||||
let block = create_sample_block(&mint, length);
|
let block = create_sample_block(&mint, length);
|
||||||
|
@ -13,7 +13,7 @@ use solana::crdt::NodeInfo;
|
|||||||
use solana::drone::DRONE_PORT;
|
use solana::drone::DRONE_PORT;
|
||||||
use solana::fullnode::Config;
|
use solana::fullnode::Config;
|
||||||
use solana::logger;
|
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::thin_client::ThinClient;
|
||||||
use solana::wallet::request_airdrop;
|
use solana::wallet::request_airdrop;
|
||||||
use std::error;
|
use std::error;
|
||||||
@ -27,7 +27,7 @@ enum WalletCommand {
|
|||||||
Address,
|
Address,
|
||||||
Balance,
|
Balance,
|
||||||
AirDrop(i64),
|
AirDrop(i64),
|
||||||
Pay(i64, PublicKey),
|
Pay(i64, Pubkey),
|
||||||
Confirm(Signature),
|
Confirm(Signature),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,11 +177,11 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
|
|||||||
.into_vec()
|
.into_vec()
|
||||||
.expect("base58-encoded public key");
|
.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());
|
eprintln!("{}", pay_matches.usage());
|
||||||
Err(WalletError::BadParameter("Invalid public key".to_string()))?;
|
Err(WalletError::BadParameter("Invalid public key".to_string()))?;
|
||||||
}
|
}
|
||||||
PublicKey::new(&pubkey_vec)
|
Pubkey::new(&pubkey_vec)
|
||||||
} else {
|
} else {
|
||||||
id.pubkey()
|
id.pubkey()
|
||||||
};
|
};
|
||||||
|
@ -5,22 +5,22 @@
|
|||||||
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use payment_plan::{Payment, PaymentPlan, Witness};
|
use payment_plan::{Payment, PaymentPlan, Witness};
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
/// A data type representing a `Witness` that the payment plan is waiting on.
|
/// A data type representing a `Witness` that the payment plan is waiting on.
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum Condition {
|
pub enum Condition {
|
||||||
/// Wait for a `Timestamp` `Witness` at or after the given `DateTime`.
|
/// 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`.
|
/// Wait for a `Signature` `Witness` from `Pubkey`.
|
||||||
Signature(PublicKey),
|
Signature(Pubkey),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Condition {
|
impl Condition {
|
||||||
/// Return true if the given Witness satisfies this 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) {
|
match (self, witness) {
|
||||||
(Condition::Signature(pubkey), Witness::Signature) => pubkey == from,
|
(Condition::Signature(pubkey), Witness::Signature) => pubkey == from,
|
||||||
(Condition::Timestamp(dt, pubkey), Witness::Timestamp(last_time)) => {
|
(Condition::Timestamp(dt, pubkey), Witness::Timestamp(last_time)) => {
|
||||||
@ -47,22 +47,22 @@ pub enum Budget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Budget {
|
impl Budget {
|
||||||
/// Create the simplest budget - one that pays `tokens` to PublicKey.
|
/// Create the simplest budget - one that pays `tokens` to Pubkey.
|
||||||
pub fn new_payment(tokens: i64, to: PublicKey) -> Self {
|
pub fn new_payment(tokens: i64, to: Pubkey) -> Self {
|
||||||
Budget::Pay(Payment { tokens, to })
|
Budget::Pay(Payment { tokens, to })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a budget that pays `tokens` to `to` after being witnessed by `from`.
|
/// 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 })
|
Budget::After(Condition::Signature(from), Payment { tokens, to })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a budget that pays `tokens` to `to` after the given DateTime.
|
/// Create a budget that pays `tokens` to `to` after the given DateTime.
|
||||||
pub fn new_future_payment(
|
pub fn new_future_payment(
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
from: PublicKey,
|
from: Pubkey,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Budget::After(Condition::Timestamp(dt, from), Payment { tokens, to })
|
Budget::After(Condition::Timestamp(dt, from), Payment { tokens, to })
|
||||||
}
|
}
|
||||||
@ -71,9 +71,9 @@ impl Budget {
|
|||||||
/// unless cancelled by `from`.
|
/// unless cancelled by `from`.
|
||||||
pub fn new_cancelable_future_payment(
|
pub fn new_cancelable_future_payment(
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
from: PublicKey,
|
from: Pubkey,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Budget::Or(
|
Budget::Or(
|
||||||
(Condition::Timestamp(dt, from), Payment { tokens, to }),
|
(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.
|
/// Apply a witness to the budget to see if the budget can be reduced.
|
||||||
/// If so, modify the budget in-place.
|
/// 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 {
|
let new_payment = match self {
|
||||||
Budget::After(cond, payment) if cond.is_satisfied(witness, from) => Some(payment),
|
Budget::After(cond, payment) if cond.is_satisfied(witness, from) => Some(payment),
|
||||||
Budget::Or((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]
|
#[test]
|
||||||
fn test_signature_satisfied() {
|
fn test_signature_satisfied() {
|
||||||
let from = PublicKey::default();
|
let from = Pubkey::default();
|
||||||
assert!(Condition::Signature(from).is_satisfied(&Witness::Signature, &from));
|
assert!(Condition::Signature(from).is_satisfied(&Witness::Signature, &from));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ mod tests {
|
|||||||
fn test_timestamp_satisfied() {
|
fn test_timestamp_satisfied() {
|
||||||
let dt1 = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
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 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(dt1), &from));
|
||||||
assert!(Condition::Timestamp(dt1, from).is_satisfied(&Witness::Timestamp(dt2), &from));
|
assert!(Condition::Timestamp(dt1, from).is_satisfied(&Witness::Timestamp(dt2), &from));
|
||||||
assert!(!Condition::Timestamp(dt2, from).is_satisfied(&Witness::Timestamp(dt1), &from));
|
assert!(!Condition::Timestamp(dt2, from).is_satisfied(&Witness::Timestamp(dt1), &from));
|
||||||
@ -139,8 +139,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_verify() {
|
fn test_verify() {
|
||||||
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
||||||
let from = PublicKey::default();
|
let from = Pubkey::default();
|
||||||
let to = PublicKey::default();
|
let to = Pubkey::default();
|
||||||
assert!(Budget::new_payment(42, to).verify(42));
|
assert!(Budget::new_payment(42, to).verify(42));
|
||||||
assert!(Budget::new_authorized_payment(from, 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));
|
assert!(Budget::new_future_payment(dt, from, 42, to).verify(42));
|
||||||
@ -149,8 +149,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_authorized_payment() {
|
fn test_authorized_payment() {
|
||||||
let from = PublicKey::default();
|
let from = Pubkey::default();
|
||||||
let to = PublicKey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let mut budget = Budget::new_authorized_payment(from, 42, to);
|
let mut budget = Budget::new_authorized_payment(from, 42, to);
|
||||||
budget.apply_witness(&Witness::Signature, &from);
|
budget.apply_witness(&Witness::Signature, &from);
|
||||||
@ -185,8 +185,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_cancelable_future_payment() {
|
fn test_cancelable_future_payment() {
|
||||||
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
||||||
let from = PublicKey::default();
|
let from = Pubkey::default();
|
||||||
let to = PublicKey::default();
|
let to = Pubkey::default();
|
||||||
|
|
||||||
let mut budget = Budget::new_cancelable_future_payment(dt, from, 42, to);
|
let mut budget = Budget::new_cancelable_future_payment(dt, from, 42, to);
|
||||||
budget.apply_witness(&Witness::Timestamp(dt), &from);
|
budget.apply_witness(&Witness::Timestamp(dt), &from);
|
||||||
|
@ -2,7 +2,7 @@ use crdt::{CrdtError, NodeInfo};
|
|||||||
use rand::distributions::{Distribution, Weighted, WeightedChoice};
|
use rand::distributions::{Distribution, Weighted, WeightedChoice};
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use std;
|
use std;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@ -61,21 +61,21 @@ impl<'a> ChooseGossipPeerStrategy for ChooseRandomPeerStrategy<'a> {
|
|||||||
pub struct ChooseWeightedPeerStrategy<'a> {
|
pub struct ChooseWeightedPeerStrategy<'a> {
|
||||||
// The map of last directly observed update_index for each active validator.
|
// The map of last directly observed update_index for each active validator.
|
||||||
// This is how we get observed(v) from the formula above.
|
// 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,
|
// 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
|
// 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]
|
// "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
|
// A function returning the size of the stake for a particular validator, corresponds
|
||||||
// to stake(i) in the formula above.
|
// to stake(i) in the formula above.
|
||||||
get_stake: &'a Fn(PublicKey) -> f64,
|
get_stake: &'a Fn(Pubkey) -> f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ChooseWeightedPeerStrategy<'a> {
|
impl<'a> ChooseWeightedPeerStrategy<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
remote: &'a HashMap<PublicKey, u64>,
|
remote: &'a HashMap<Pubkey, u64>,
|
||||||
external_liveness: &'a HashMap<PublicKey, HashMap<PublicKey, u64>>,
|
external_liveness: &'a HashMap<Pubkey, HashMap<Pubkey, u64>>,
|
||||||
get_stake: &'a Fn(PublicKey) -> f64,
|
get_stake: &'a Fn(Pubkey) -> f64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ChooseWeightedPeerStrategy {
|
ChooseWeightedPeerStrategy {
|
||||||
remote,
|
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;
|
let mut last_seen_index = 0;
|
||||||
// If the peer is not in our remote table, then we leave last_seen_index as zero.
|
// 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,
|
// 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 {
|
mod tests {
|
||||||
use choose_gossip_peer_strategy::{ChooseWeightedPeerStrategy, DEFAULT_WEIGHT};
|
use choose_gossip_peer_strategy::{ChooseWeightedPeerStrategy, DEFAULT_WEIGHT};
|
||||||
use logger;
|
use logger;
|
||||||
use signature::{Keypair, KeypairUtil, PublicKey};
|
use signature::{Keypair, KeypairUtil, Pubkey};
|
||||||
use std;
|
use std;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn get_stake(_id: PublicKey) -> f64 {
|
fn get_stake(_id: Pubkey) -> f64 {
|
||||||
1.0
|
1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +207,8 @@ mod tests {
|
|||||||
// Initialize the filler keys
|
// Initialize the filler keys
|
||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
|
|
||||||
let remote: HashMap<PublicKey, u64> = HashMap::new();
|
let remote: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
let external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
|
let external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
|
||||||
|
|
||||||
let weighted_strategy =
|
let weighted_strategy =
|
||||||
ChooseWeightedPeerStrategy::new(&remote, &external_liveness, &get_stake);
|
ChooseWeightedPeerStrategy::new(&remote, &external_liveness, &get_stake);
|
||||||
@ -227,13 +227,13 @@ mod tests {
|
|||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
let key2 = Keypair::new().pubkey();
|
let key2 = Keypair::new().pubkey();
|
||||||
|
|
||||||
let remote: HashMap<PublicKey, u64> = HashMap::new();
|
let remote: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, 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
|
// If only the liveness table contains the entry, should return the
|
||||||
// weighted liveness entries
|
// weighted liveness entries
|
||||||
let test_value: u32 = 5;
|
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);
|
rumors.insert(key2, test_value as u64);
|
||||||
external_liveness.insert(key1, rumors);
|
external_liveness.insert(key1, rumors);
|
||||||
|
|
||||||
@ -252,12 +252,12 @@ mod tests {
|
|||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
let key2 = Keypair::new().pubkey();
|
let key2 = Keypair::new().pubkey();
|
||||||
|
|
||||||
let remote: HashMap<PublicKey, u64> = HashMap::new();
|
let remote: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, 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
|
// If the vote index is greater than u32::MAX, default to u32::MAX
|
||||||
let test_value = (std::u32::MAX as u64) + 10;
|
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);
|
rumors.insert(key2, test_value);
|
||||||
external_liveness.insert(key1, rumors);
|
external_liveness.insert(key1, rumors);
|
||||||
|
|
||||||
@ -275,12 +275,12 @@ mod tests {
|
|||||||
// Initialize the filler keys
|
// Initialize the filler keys
|
||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
|
|
||||||
let mut remote: HashMap<PublicKey, u64> = HashMap::new();
|
let mut remote: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
|
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
|
||||||
|
|
||||||
// Test many validators' rumors in external_liveness
|
// Test many validators' rumors in external_liveness
|
||||||
let num_peers = 10;
|
let num_peers = 10;
|
||||||
let mut rumors: HashMap<PublicKey, u64> = HashMap::new();
|
let mut rumors: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
|
|
||||||
remote.insert(key1, 0);
|
remote.insert(key1, 0);
|
||||||
|
|
||||||
@ -305,13 +305,13 @@ mod tests {
|
|||||||
// Initialize the filler keys
|
// Initialize the filler keys
|
||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
|
|
||||||
let mut remote: HashMap<PublicKey, u64> = HashMap::new();
|
let mut remote: HashMap<Pubkey, u64> = HashMap::new();
|
||||||
let mut external_liveness: HashMap<PublicKey, HashMap<PublicKey, u64>> = HashMap::new();
|
let mut external_liveness: HashMap<Pubkey, HashMap<Pubkey, u64>> = HashMap::new();
|
||||||
|
|
||||||
// Test many validators' rumors in external_liveness
|
// Test many validators' rumors in external_liveness
|
||||||
let num_peers = 10;
|
let num_peers = 10;
|
||||||
let old_index = 20;
|
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);
|
remote.insert(key1, old_index);
|
||||||
|
|
||||||
|
70
src/crdt.rs
70
src/crdt.rs
@ -2,7 +2,7 @@
|
|||||||
//! a gossip control plane. The goal is to share small bits of off-chain information and detect and
|
//! a gossip control plane. The goal is to share small bits of off-chain information and detect and
|
||||||
//! repair partitions.
|
//! 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 last version is always picked during an update.
|
||||||
//!
|
//!
|
||||||
//! The network is arranged in layers:
|
//! The network is arranged in layers:
|
||||||
@ -25,7 +25,7 @@ use pnet_datalink as datalink;
|
|||||||
use rand::{thread_rng, RngCore};
|
use rand::{thread_rng, RngCore};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use result::{Error, Result};
|
use result::{Error, Result};
|
||||||
use signature::{Keypair, KeypairUtil, PublicKey};
|
use signature::{Keypair, KeypairUtil, Pubkey};
|
||||||
use std;
|
use std;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
@ -126,18 +126,18 @@ pub struct LedgerState {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct NodeInfo {
|
pub struct NodeInfo {
|
||||||
pub id: PublicKey,
|
pub id: Pubkey,
|
||||||
/// If any of the bits change, update increment this value
|
/// If any of the bits change, update increment this value
|
||||||
pub version: u64,
|
pub version: u64,
|
||||||
/// network addresses
|
/// network addresses
|
||||||
pub contact_info: ContactInfo,
|
pub contact_info: ContactInfo,
|
||||||
/// current leader identity
|
/// current leader identity
|
||||||
pub leader_id: PublicKey,
|
pub leader_id: Pubkey,
|
||||||
/// information about the state of the ledger
|
/// information about the state of the ledger
|
||||||
pub ledger_state: LedgerState,
|
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 buf: &[u8] = &key.as_ref();
|
||||||
let mut rdr = Cursor::new(&buf[..8]);
|
let mut rdr = Cursor::new(&buf[..8]);
|
||||||
rdr.read_u64::<LittleEndian>()
|
rdr.read_u64::<LittleEndian>()
|
||||||
@ -146,7 +146,7 @@ fn make_debug_id(key: &PublicKey) -> u64 {
|
|||||||
|
|
||||||
impl NodeInfo {
|
impl NodeInfo {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: PublicKey,
|
id: Pubkey,
|
||||||
ncp: SocketAddr,
|
ncp: SocketAddr,
|
||||||
tvu: SocketAddr,
|
tvu: SocketAddr,
|
||||||
rpu: SocketAddr,
|
rpu: SocketAddr,
|
||||||
@ -164,7 +164,7 @@ impl NodeInfo {
|
|||||||
tvu_window,
|
tvu_window,
|
||||||
version: 0,
|
version: 0,
|
||||||
},
|
},
|
||||||
leader_id: PublicKey::default(),
|
leader_id: Pubkey::default(),
|
||||||
ledger_state: LedgerState {
|
ledger_state: LedgerState {
|
||||||
last_id: Hash::default(),
|
last_id: Hash::default(),
|
||||||
},
|
},
|
||||||
@ -207,7 +207,7 @@ impl NodeInfo {
|
|||||||
nxt_addr.set_port(addr.port() + nxt);
|
nxt_addr.set_port(addr.port() + nxt);
|
||||||
nxt_addr
|
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 transactions_addr = *bind_addr;
|
||||||
let gossip_addr = Self::next_port(&bind_addr, 1);
|
let gossip_addr = Self::next_port(&bind_addr, 1);
|
||||||
let replicate_addr = Self::next_port(&bind_addr, 2);
|
let replicate_addr = Self::next_port(&bind_addr, 2);
|
||||||
@ -229,7 +229,7 @@ impl NodeInfo {
|
|||||||
pub fn new_entry_point(gossip_addr: SocketAddr) -> Self {
|
pub fn new_entry_point(gossip_addr: SocketAddr) -> Self {
|
||||||
let daddr: SocketAddr = "0.0.0.0:0".parse().unwrap();
|
let daddr: SocketAddr = "0.0.0.0:0".parse().unwrap();
|
||||||
NodeInfo::new(
|
NodeInfo::new(
|
||||||
PublicKey::default(),
|
Pubkey::default(),
|
||||||
gossip_addr,
|
gossip_addr,
|
||||||
daddr,
|
daddr,
|
||||||
daddr,
|
daddr,
|
||||||
@ -252,22 +252,22 @@ impl NodeInfo {
|
|||||||
/// No attempt to keep track of timeouts or dropped requests is made, or should be.
|
/// No attempt to keep track of timeouts or dropped requests is made, or should be.
|
||||||
pub struct Crdt {
|
pub struct Crdt {
|
||||||
/// table of everyone in the network
|
/// 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.
|
/// Value of my update index when entry in table was updated.
|
||||||
/// Nodes will ask for updates since `update_index`, and this node
|
/// Nodes will ask for updates since `update_index`, and this node
|
||||||
/// should respond with all the identities that are greater then the
|
/// should respond with all the identities that are greater then the
|
||||||
/// request's `update_index` in this list
|
/// 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
|
/// 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
|
/// 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
|
/// 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 update_index: u64,
|
||||||
pub me: PublicKey,
|
pub me: Pubkey,
|
||||||
/// last time we heard from anyone getting a message fro this public key
|
/// last time we heard from anyone getting a message fro this public key
|
||||||
/// these are rumers and shouldn't be trusted directly
|
/// 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
|
// TODO These messages should be signed, and go through the gpu pipeline for spam filtering
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -279,7 +279,7 @@ enum Protocol {
|
|||||||
RequestUpdates(u64, NodeInfo),
|
RequestUpdates(u64, NodeInfo),
|
||||||
//TODO might need a since?
|
//TODO might need a since?
|
||||||
/// from id, form's last update index, NodeInfo
|
/// 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
|
/// ask for a missing index
|
||||||
/// (my replicated data to keep alive, missing window index)
|
/// (my replicated data to keep alive, missing window index)
|
||||||
RequestWindowIndex(NodeInfo, u64),
|
RequestWindowIndex(NodeInfo, u64),
|
||||||
@ -334,14 +334,14 @@ impl Crdt {
|
|||||||
let leader_id = self.table[&self.me].leader_id;
|
let leader_id = self.table[&self.me].leader_id;
|
||||||
|
|
||||||
// leader_id can be 0s from network entry point
|
// leader_id can be 0s from network entry point
|
||||||
if leader_id == PublicKey::default() {
|
if leader_id == Pubkey::default() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.table.get(&leader_id)
|
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();
|
let mut me = self.my_data().clone();
|
||||||
warn!(
|
warn!(
|
||||||
"{:x}: LEADER_UPDATE TO {:x} from {:x}",
|
"{:x}: LEADER_UPDATE TO {:x} from {:x}",
|
||||||
@ -354,11 +354,11 @@ impl Crdt {
|
|||||||
self.insert(&me);
|
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)
|
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() {
|
if self.table.get(pubkey).is_none() {
|
||||||
warn!(
|
warn!(
|
||||||
"{:x}: VOTE for unknown id: {:x}",
|
"{:x}: VOTE for unknown id: {:x}",
|
||||||
@ -408,7 +408,7 @@ impl Crdt {
|
|||||||
self.insert(&data);
|
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());
|
inc_new_counter_info!("crdt-vote-count", votes.len());
|
||||||
if !votes.is_empty() {
|
if !votes.is_empty() {
|
||||||
info!("{:x}: INSERTING VOTES {}", self.debug_id(), votes.len());
|
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
|
//update the liveness table
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
trace!(
|
trace!(
|
||||||
@ -477,7 +477,7 @@ impl Crdt {
|
|||||||
}
|
}
|
||||||
let leader_id = self.leader_data().unwrap().id;
|
let leader_id = self.leader_data().unwrap().id;
|
||||||
let limit = GOSSIP_PURGE_MILLIS;
|
let limit = GOSSIP_PURGE_MILLIS;
|
||||||
let dead_ids: Vec<PublicKey> = self
|
let dead_ids: Vec<Pubkey> = self
|
||||||
.alive
|
.alive
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(&k, v)| {
|
.filter_map(|(&k, v)| {
|
||||||
@ -515,7 +515,7 @@ impl Crdt {
|
|||||||
make_debug_id(id),
|
make_debug_id(id),
|
||||||
);
|
);
|
||||||
inc_new_counter_info!("crdt-purge-purged_leader", 1, 1);
|
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
|
// TODO: fill in with real implmentation once staking is implemented
|
||||||
fn get_stake(_id: PublicKey) -> f64 {
|
fn get_stake(_id: Pubkey) -> f64 {
|
||||||
1.0
|
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);
|
//trace!("get updates since {}", v);
|
||||||
let data = self
|
let data = self
|
||||||
.table
|
.table
|
||||||
.values()
|
.values()
|
||||||
.filter(|x| x.id != PublicKey::default() && self.local[&x.id] > v)
|
.filter(|x| x.id != Pubkey::default() && self.local[&x.id] > v)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
let id = self.me;
|
let id = self.me;
|
||||||
@ -855,16 +855,16 @@ impl Crdt {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
/// TODO: This is obviously the wrong way to do this. Need to implement leader selection
|
/// 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 mut table = HashMap::new();
|
||||||
let def = PublicKey::default();
|
let def = Pubkey::default();
|
||||||
let cur = self.table.values().filter(|x| x.leader_id != def);
|
let cur = self.table.values().filter(|x| x.leader_id != def);
|
||||||
for v in cur {
|
for v in cur {
|
||||||
let cnt = table.entry(&v.leader_id).or_insert(0);
|
let cnt = table.entry(&v.leader_id).or_insert(0);
|
||||||
*cnt += 1;
|
*cnt += 1;
|
||||||
trace!("leader {:x} {}", make_debug_id(&v.leader_id), *cnt);
|
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();
|
let my_id = self.debug_id();
|
||||||
for x in &sorted {
|
for x in &sorted {
|
||||||
trace!(
|
trace!(
|
||||||
@ -895,10 +895,10 @@ impl Crdt {
|
|||||||
/// * `data` - the update data
|
/// * `data` - the update data
|
||||||
fn apply_updates(
|
fn apply_updates(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: PublicKey,
|
from: Pubkey,
|
||||||
update_index: u64,
|
update_index: u64,
|
||||||
data: &[NodeInfo],
|
data: &[NodeInfo],
|
||||||
external_liveness: &[(PublicKey, u64)],
|
external_liveness: &[(Pubkey, u64)],
|
||||||
) {
|
) {
|
||||||
trace!("got updates {}", data.len());
|
trace!("got updates {}", data.len());
|
||||||
// TODO we need to punish/spam resist here
|
// TODO we need to punish/spam resist here
|
||||||
@ -1272,7 +1272,7 @@ impl TestNode {
|
|||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
Self::new_localhost_with_pubkey(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 transaction = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
let gossip = 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();
|
let replicate = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
@ -1381,7 +1381,7 @@ mod tests {
|
|||||||
use logger;
|
use logger;
|
||||||
use packet::BlobRecycler;
|
use packet::BlobRecycler;
|
||||||
use result::Error;
|
use result::Error;
|
||||||
use signature::{Keypair, KeypairUtil, PublicKey};
|
use signature::{Keypair, KeypairUtil, Pubkey};
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
@ -1884,7 +1884,7 @@ mod tests {
|
|||||||
let len = crdt.table.len() as u64;
|
let len = crdt.table.len() as u64;
|
||||||
crdt.purge(now + GOSSIP_PURGE_MILLIS + 1);
|
crdt.purge(now + GOSSIP_PURGE_MILLIS + 1);
|
||||||
assert_eq!(len as usize - 1, crdt.table.len());
|
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());
|
assert!(crdt.leader_data().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
use influx_db_client as influxdb;
|
use influx_db_client as influxdb;
|
||||||
use metrics;
|
use metrics;
|
||||||
use signature::Signature;
|
use signature::Signature;
|
||||||
use signature::{Keypair, PublicKey};
|
use signature::{Keypair, Pubkey};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||||
@ -23,7 +23,7 @@ pub const DRONE_PORT: u16 = 9900;
|
|||||||
pub enum DroneRequest {
|
pub enum DroneRequest {
|
||||||
GetAirdrop {
|
GetAirdrop {
|
||||||
airdrop_request_amount: u64,
|
airdrop_request_amount: u64,
|
||||||
client_pubkey: PublicKey,
|
client_pubkey: Pubkey,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use bincode::{serialize_into, serialized_size};
|
|||||||
use hash::{extend_and_hash, hash, Hash};
|
use hash::{extend_and_hash, hash, Hash};
|
||||||
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE};
|
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
@ -83,7 +83,7 @@ impl Entry {
|
|||||||
&self,
|
&self,
|
||||||
blob_recycler: &BlobRecycler,
|
blob_recycler: &BlobRecycler,
|
||||||
idx: Option<u64>,
|
idx: Option<u64>,
|
||||||
id: Option<PublicKey>,
|
id: Option<Pubkey>,
|
||||||
addr: Option<&SocketAddr>,
|
addr: Option<&SocketAddr>,
|
||||||
) -> SharedBlob {
|
) -> SharedBlob {
|
||||||
let blob = blob_recycler.allocate();
|
let blob = blob_recycler.allocate();
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use hash::{hash, Hash};
|
use hash::{hash, Hash};
|
||||||
use ring::rand::SystemRandom;
|
use ring::rand::SystemRandom;
|
||||||
use signature::{Keypair, KeypairUtil, PublicKey};
|
use signature::{Keypair, KeypairUtil, Pubkey};
|
||||||
use transaction::Transaction;
|
use transaction::Transaction;
|
||||||
use untrusted::Input;
|
use untrusted::Input;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Mint {
|
pub struct Mint {
|
||||||
pub pkcs8: Vec<u8>,
|
pub pkcs8: Vec<u8>,
|
||||||
pubkey: PublicKey,
|
pubkey: Pubkey,
|
||||||
pub tokens: i64,
|
pub tokens: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ impl Mint {
|
|||||||
Keypair::from_pkcs8(Input::from(&self.pkcs8)).expect("from_pkcs8 in mint pub fn keypair")
|
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
|
self.pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use counter::Counter;
|
|||||||
use log::Level;
|
use log::Level;
|
||||||
use result::{Error, Result};
|
use result::{Error, Result};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -302,7 +302,7 @@ pub fn to_blobs<T: Serialize>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BLOB_INDEX_END: usize = size_of::<u64>();
|
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_FLAGS_END: usize = BLOB_ID_END + size_of::<u32>();
|
||||||
const BLOB_SIZE_END: usize = BLOB_FLAGS_END + size_of::<u64>();
|
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
|
/// 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
|
/// 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])?;
|
let e = deserialize(&self.data[BLOB_INDEX_END..BLOB_ID_END])?;
|
||||||
Ok(e)
|
Ok(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_id(&mut self, id: PublicKey) -> Result<()> {
|
pub fn set_id(&mut self, id: Pubkey) -> Result<()> {
|
||||||
let wtr = serialize(&id)?;
|
let wtr = serialize(&id)?;
|
||||||
self.data[BLOB_INDEX_END..BLOB_ID_END].clone_from_slice(&wtr);
|
self.data[BLOB_INDEX_END..BLOB_ID_END].clone_from_slice(&wtr);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
//! `Payment`, the payment is executed.
|
//! `Payment`, the payment is executed.
|
||||||
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
|
|
||||||
/// The types of events a payment plan can process.
|
/// The types of events a payment plan can process.
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
@ -12,18 +12,18 @@ pub enum Witness {
|
|||||||
/// The current time.
|
/// The current time.
|
||||||
Timestamp(DateTime<Utc>),
|
Timestamp(DateTime<Utc>),
|
||||||
|
|
||||||
/// A siganture from PublicKey.
|
/// A siganture from Pubkey.
|
||||||
Signature,
|
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)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Payment {
|
pub struct Payment {
|
||||||
/// Amount to be paid.
|
/// Amount to be paid.
|
||||||
pub tokens: i64,
|
pub tokens: i64,
|
||||||
|
|
||||||
/// The `PublicKey` that `tokens` should be paid to.
|
/// The `Pubkey` that `tokens` should be paid to.
|
||||||
pub to: PublicKey,
|
pub to: Pubkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interface to smart contracts.
|
/// 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.
|
/// Apply a witness to the payment plan to see if the plan can be reduced.
|
||||||
/// If so, modify the plan in-place.
|
/// 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);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
//! The `request` module defines the messages for the thin client.
|
//! The `request` module defines the messages for the thin client.
|
||||||
|
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use signature::{PublicKey, Signature};
|
use signature::{Pubkey, Signature};
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
|
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
GetBalance { key: PublicKey },
|
GetBalance { key: Pubkey },
|
||||||
GetLastId,
|
GetLastId,
|
||||||
GetTransactionCount,
|
GetTransactionCount,
|
||||||
GetSignature { signature: Signature },
|
GetSignature { signature: Signature },
|
||||||
@ -21,7 +21,7 @@ impl Request {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
Balance { key: PublicKey, val: i64 },
|
Balance { key: Pubkey, val: i64 },
|
||||||
LastId { id: Hash },
|
LastId { id: Hash },
|
||||||
TransactionCount { transaction_count: u64 },
|
TransactionCount { transaction_count: u64 },
|
||||||
SignatureStatus { signature_status: bool },
|
SignatureStatus { signature_status: bool },
|
||||||
|
@ -15,27 +15,27 @@ use untrusted::Input;
|
|||||||
|
|
||||||
pub type Keypair = Ed25519KeyPair;
|
pub type Keypair = Ed25519KeyPair;
|
||||||
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[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 {
|
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] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0[..]
|
&self.0[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for PublicKey {
|
impl fmt::Debug for Pubkey {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", bs58::encode(self.0).into_string())
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", bs58::encode(self.0).into_string())
|
write!(f, "{}", bs58::encode(self.0).into_string())
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ impl fmt::Display for Signature {
|
|||||||
|
|
||||||
pub trait KeypairUtil {
|
pub trait KeypairUtil {
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
fn pubkey(&self) -> PublicKey;
|
fn pubkey(&self) -> Pubkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeypairUtil for Ed25519KeyPair {
|
impl KeypairUtil for Ed25519KeyPair {
|
||||||
@ -88,8 +88,8 @@ impl KeypairUtil for Ed25519KeyPair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the public key for the given keypair
|
/// Return the public key for the given keypair
|
||||||
fn pubkey(&self) -> PublicKey {
|
fn pubkey(&self) -> Pubkey {
|
||||||
PublicKey(GenericArray::clone_from_slice(self.public_key_bytes()))
|
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)
|
GenKeys::new(seed)
|
||||||
.gen_n_keypairs(n)
|
.gen_n_keypairs(n)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -44,14 +44,14 @@ pub fn init() {
|
|||||||
|
|
||||||
fn verify_packet(packet: &Packet) -> u8 {
|
fn verify_packet(packet: &Packet) -> u8 {
|
||||||
use ring::signature;
|
use ring::signature;
|
||||||
use signature::{PublicKey, Signature};
|
use signature::{Pubkey, Signature};
|
||||||
use untrusted;
|
use untrusted;
|
||||||
|
|
||||||
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
||||||
let sig_start = TX_OFFSET + SIG_OFFSET;
|
let sig_start = TX_OFFSET + SIG_OFFSET;
|
||||||
let sig_end = sig_start + size_of::<Signature>();
|
let sig_end = sig_start + size_of::<Signature>();
|
||||||
let pubkey_start = TX_OFFSET + PUB_KEY_OFFSET;
|
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 {
|
if packet.meta.size <= msg_start {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use request::{Request, Response};
|
use request::{Request, Response};
|
||||||
use signature::{Keypair, PublicKey, Signature};
|
use signature::{Keypair, Pubkey, Signature};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::{SocketAddr, UdpSocket};
|
use std::net::{SocketAddr, UdpSocket};
|
||||||
@ -27,7 +27,7 @@ pub struct ThinClient {
|
|||||||
transactions_socket: UdpSocket,
|
transactions_socket: UdpSocket,
|
||||||
last_id: Option<Hash>,
|
last_id: Option<Hash>,
|
||||||
transaction_count: u64,
|
transaction_count: u64,
|
||||||
balances: HashMap<PublicKey, i64>,
|
balances: HashMap<Pubkey, i64>,
|
||||||
signature_status: bool,
|
signature_status: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ impl ThinClient {
|
|||||||
&self,
|
&self,
|
||||||
n: i64,
|
n: i64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
last_id: &Hash,
|
last_id: &Hash,
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
@ -121,7 +121,7 @@ impl ThinClient {
|
|||||||
/// Request the balance of the user holding `pubkey`. This method blocks
|
/// Request the balance of the user holding `pubkey`. This method blocks
|
||||||
/// until the server sends a response. If the response packet is dropped
|
/// until the server sends a response. If the response packet is dropped
|
||||||
/// by the network, this method will hang indefinitely.
|
/// 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");
|
trace!("get_balance");
|
||||||
let req = Request::GetBalance { key: *pubkey };
|
let req = Request::GetBalance { key: *pubkey };
|
||||||
let data = serialize(&req).expect("serialize GetBalance in pub fn get_balance");
|
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")
|
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_result;
|
||||||
let mut balance_value = -1;
|
let mut balance_value = -1;
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
@ -5,7 +5,7 @@ use budget::{Budget, Condition};
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use payment_plan::{Payment, PaymentPlan, Witness};
|
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 SIGNED_DATA_OFFSET: usize = 112;
|
||||||
pub const SIG_OFFSET: usize = 8;
|
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 {
|
match self {
|
||||||
Plan::Budget(budget) => budget.apply_witness(witness, from),
|
Plan::Budget(budget) => budget.apply_witness(witness, from),
|
||||||
}
|
}
|
||||||
@ -68,21 +68,21 @@ pub enum Instruction {
|
|||||||
ApplyTimestamp(DateTime<Utc>),
|
ApplyTimestamp(DateTime<Utc>),
|
||||||
|
|
||||||
/// Tell the payment plan that the `NewContract` with `Signature` has been
|
/// 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),
|
ApplySignature(Signature),
|
||||||
|
|
||||||
/// Vote for a PoH that is equal to the lastid of this transaction
|
/// Vote for a PoH that is equal to the lastid of this transaction
|
||||||
NewVote(Vote),
|
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)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Transaction {
|
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,
|
pub sig: Signature,
|
||||||
|
|
||||||
/// The `PublicKey` of the entity that signed the transaction data.
|
/// The `Pubkey` of the entity that signed the transaction data.
|
||||||
pub from: PublicKey,
|
pub from: Pubkey,
|
||||||
|
|
||||||
/// The action the server should take.
|
/// The action the server should take.
|
||||||
pub instruction: Instruction,
|
pub instruction: Instruction,
|
||||||
@ -117,7 +117,7 @@ impl Transaction {
|
|||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// Create and sign a new Transaction. Used for unit-testing.
|
||||||
pub fn new_taxed(
|
pub fn new_taxed(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
fee: i64,
|
fee: i64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
@ -133,7 +133,7 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// 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)
|
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.
|
/// Create and sign a postdated Transaction. Used for unit-testing.
|
||||||
pub fn new_on_date(
|
pub fn new_on_date(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: PublicKey,
|
to: Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
tokens: i64,
|
tokens: i64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use entry::Entry;
|
use entry::Entry;
|
||||||
use hash::Hash;
|
use hash::Hash;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use transaction::{Instruction, Transaction, Vote};
|
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
|
entries
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|entry| entry.transactions.iter().filter_map(transaction_to_vote))
|
.flat_map(|entry| entry.transactions.iter().filter_map(transaction_to_vote))
|
||||||
.collect()
|
.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 {
|
match tx.instruction {
|
||||||
Instruction::NewVote(ref vote) => Some((tx.from, vote.clone(), tx.last_id)),
|
Instruction::NewVote(ref vote) => Some((tx.from, vote.clone(), tx.last_id)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use drone::DroneRequest;
|
use drone::DroneRequest;
|
||||||
use signature::PublicKey;
|
use signature::Pubkey;
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net::{SocketAddr, TcpStream};
|
use std::net::{SocketAddr, TcpStream};
|
||||||
|
|
||||||
pub fn request_airdrop(
|
pub fn request_airdrop(
|
||||||
drone_addr: &SocketAddr,
|
drone_addr: &SocketAddr,
|
||||||
id: &PublicKey,
|
id: &Pubkey,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
) -> Result<(), Box<error::Error>> {
|
) -> Result<(), Box<error::Error>> {
|
||||||
let mut stream = TcpStream::connect(drone_addr)?;
|
let mut stream = TcpStream::connect(drone_addr)?;
|
||||||
|
@ -15,7 +15,7 @@ use solana::mint::Mint;
|
|||||||
use solana::ncp::Ncp;
|
use solana::ncp::Ncp;
|
||||||
use solana::result;
|
use solana::result;
|
||||||
use solana::service::Service;
|
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::streamer::{default_window, WINDOW_SIZE};
|
||||||
use solana::thin_client::ThinClient;
|
use solana::thin_client::ThinClient;
|
||||||
use solana::timing::duration_as_s;
|
use solana::timing::duration_as_s;
|
||||||
@ -751,7 +751,7 @@ fn mk_client(leader: &NodeInfo) -> ThinClient {
|
|||||||
|
|
||||||
fn retry_get_balance(
|
fn retry_get_balance(
|
||||||
client: &mut ThinClient,
|
client: &mut ThinClient,
|
||||||
bob_pubkey: &PublicKey,
|
bob_pubkey: &Pubkey,
|
||||||
expected: Option<i64>,
|
expected: Option<i64>,
|
||||||
) -> Option<i64> {
|
) -> Option<i64> {
|
||||||
const LAST: usize = 30;
|
const LAST: usize = 30;
|
||||||
@ -773,7 +773,7 @@ fn retry_get_balance(
|
|||||||
fn send_tx_and_retry_get_balance(
|
fn send_tx_and_retry_get_balance(
|
||||||
leader: &NodeInfo,
|
leader: &NodeInfo,
|
||||||
alice: &Mint,
|
alice: &Mint,
|
||||||
bob_pubkey: &PublicKey,
|
bob_pubkey: &Pubkey,
|
||||||
expected: Option<i64>,
|
expected: Option<i64>,
|
||||||
) -> Option<i64> {
|
) -> Option<i64> {
|
||||||
let mut client = mk_client(leader);
|
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(
|
fn retry_send_tx_and_retry_get_balance(
|
||||||
leader: &NodeInfo,
|
leader: &NodeInfo,
|
||||||
alice: &Mint,
|
alice: &Mint,
|
||||||
bob_pubkey: &PublicKey,
|
bob_pubkey: &Pubkey,
|
||||||
expected: Option<i64>,
|
expected: Option<i64>,
|
||||||
) -> Option<i64> {
|
) -> Option<i64> {
|
||||||
let mut client = mk_client(leader);
|
let mut client = mk_client(leader);
|
||||||
|
Reference in New Issue
Block a user