Cleanup: use full words for field names
and optionally for variable names
This commit is contained in:
@ -69,9 +69,9 @@ impl Accountant {
|
|||||||
to: mint.pubkey(),
|
to: mint.pubkey(),
|
||||||
tokens: mint.tokens,
|
tokens: mint.tokens,
|
||||||
};
|
};
|
||||||
let acc = Self::new_from_deposit(&deposit);
|
let accountant = Self::new_from_deposit(&deposit);
|
||||||
acc.register_entry_id(&mint.last_id());
|
accountant.register_entry_id(&mint.last_id());
|
||||||
acc
|
accountant
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the last entry ID registered
|
/// Return the last entry ID registered
|
||||||
@ -339,24 +339,26 @@ mod tests {
|
|||||||
fn test_accountant() {
|
fn test_accountant() {
|
||||||
let alice = Mint::new(10_000);
|
let alice = Mint::new(10_000);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
assert_eq!(acc.last_id(), alice.last_id());
|
assert_eq!(accountant.last_id(), alice.last_id());
|
||||||
|
|
||||||
acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
|
accountant
|
||||||
|
.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000);
|
assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_000);
|
||||||
|
|
||||||
acc.transfer(500, &alice.keypair(), bob_pubkey, alice.last_id())
|
accountant
|
||||||
|
.transfer(500, &alice.keypair(), bob_pubkey, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_500);
|
assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_account_not_found() {
|
fn test_account_not_found() {
|
||||||
let mint = Mint::new(1);
|
let mint = Mint::new(1);
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
acc.transfer(1, &KeyPair::new(), mint.pubkey(), mint.last_id()),
|
accountant.transfer(1, &KeyPair::new(), mint.pubkey(), mint.last_id()),
|
||||||
Err(AccountingError::AccountNotFound)
|
Err(AccountingError::AccountNotFound)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -364,141 +366,156 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_transfer() {
|
fn test_invalid_transfer() {
|
||||||
let alice = Mint::new(11_000);
|
let alice = Mint::new(11_000);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
|
accountant
|
||||||
|
.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
acc.transfer(10_001, &alice.keypair(), bob_pubkey, alice.last_id()),
|
accountant.transfer(10_001, &alice.keypair(), bob_pubkey, alice.last_id()),
|
||||||
Err(AccountingError::InsufficientFunds)
|
Err(AccountingError::InsufficientFunds)
|
||||||
);
|
);
|
||||||
|
|
||||||
let alice_pubkey = alice.keypair().pubkey();
|
let alice_pubkey = alice.keypair().pubkey();
|
||||||
assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), 10_000);
|
assert_eq!(accountant.get_balance(&alice_pubkey).unwrap(), 10_000);
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000);
|
assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_to_newb() {
|
fn test_transfer_to_newb() {
|
||||||
let alice = Mint::new(10_000);
|
let alice = Mint::new(10_000);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let alice_keypair = alice.keypair();
|
let alice_keypair = alice.keypair();
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
acc.transfer(500, &alice_keypair, bob_pubkey, alice.last_id())
|
accountant
|
||||||
|
.transfer(500, &alice_keypair, bob_pubkey, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 500);
|
assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_on_date() {
|
fn test_transfer_on_date() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let alice_keypair = alice.keypair();
|
let alice_keypair = alice.keypair();
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
accountant
|
||||||
|
.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Alice's balance will be zero because all funds are locked up.
|
// Alice's balance will be zero because all funds are locked up.
|
||||||
assert_eq!(acc.get_balance(&alice.pubkey()), Some(0));
|
assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0));
|
||||||
|
|
||||||
// Bob's balance will be None because the funds have not been
|
// Bob's balance will be None because the funds have not been
|
||||||
// sent.
|
// sent.
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey), None);
|
assert_eq!(accountant.get_balance(&bob_pubkey), None);
|
||||||
|
|
||||||
// Now, acknowledge the time in the condition occurred and
|
// Now, acknowledge the time in the condition occurred and
|
||||||
// that bob's funds are now available.
|
// that bob's funds are now available.
|
||||||
acc.process_verified_timestamp(alice.pubkey(), dt).unwrap();
|
accountant
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey), Some(1));
|
.process_verified_timestamp(alice.pubkey(), dt)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(accountant.get_balance(&bob_pubkey), Some(1));
|
||||||
|
|
||||||
acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); // <-- Attack! Attempt to process completed transaction.
|
accountant
|
||||||
assert_ne!(acc.get_balance(&bob_pubkey), Some(2));
|
.process_verified_timestamp(alice.pubkey(), dt)
|
||||||
|
.unwrap(); // <-- Attack! Attempt to process completed transaction.
|
||||||
|
assert_ne!(accountant.get_balance(&bob_pubkey), Some(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_after_date() {
|
fn test_transfer_after_date() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let alice_keypair = alice.keypair();
|
let alice_keypair = alice.keypair();
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
acc.process_verified_timestamp(alice.pubkey(), dt).unwrap();
|
accountant
|
||||||
|
.process_verified_timestamp(alice.pubkey(), dt)
|
||||||
// It's now past now, so this transfer should be processed immediately.
|
|
||||||
acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(acc.get_balance(&alice.pubkey()), Some(0));
|
// It's now past now, so this transfer should be processed immediately.
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey), Some(1));
|
accountant
|
||||||
|
.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0));
|
||||||
|
assert_eq!(accountant.get_balance(&bob_pubkey), Some(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cancel_transfer() {
|
fn test_cancel_transfer() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let alice_keypair = alice.keypair();
|
let alice_keypair = alice.keypair();
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let sig = acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
let sig = accountant
|
||||||
|
.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Alice's balance will be zero because all funds are locked up.
|
// Alice's balance will be zero because all funds are locked up.
|
||||||
assert_eq!(acc.get_balance(&alice.pubkey()), Some(0));
|
assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0));
|
||||||
|
|
||||||
// Bob's balance will be None because the funds have not been
|
// Bob's balance will be None because the funds have not been
|
||||||
// sent.
|
// sent.
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey), None);
|
assert_eq!(accountant.get_balance(&bob_pubkey), None);
|
||||||
|
|
||||||
// Now, cancel the trancaction. Alice gets her funds back, Bob never sees them.
|
// Now, cancel the trancaction. Alice gets her funds back, Bob never sees them.
|
||||||
acc.process_verified_sig(alice.pubkey(), sig).unwrap();
|
accountant
|
||||||
assert_eq!(acc.get_balance(&alice.pubkey()), Some(1));
|
.process_verified_sig(alice.pubkey(), sig)
|
||||||
assert_eq!(acc.get_balance(&bob_pubkey), None);
|
.unwrap();
|
||||||
|
assert_eq!(accountant.get_balance(&alice.pubkey()), Some(1));
|
||||||
|
assert_eq!(accountant.get_balance(&bob_pubkey), None);
|
||||||
|
|
||||||
acc.process_verified_sig(alice.pubkey(), sig).unwrap(); // <-- Attack! Attempt to cancel completed transaction.
|
accountant
|
||||||
assert_ne!(acc.get_balance(&alice.pubkey()), Some(2));
|
.process_verified_sig(alice.pubkey(), sig)
|
||||||
|
.unwrap(); // <-- Attack! Attempt to cancel completed transaction.
|
||||||
|
assert_ne!(accountant.get_balance(&alice.pubkey()), Some(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_duplicate_event_signature() {
|
fn test_duplicate_event_signature() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
assert!(acc.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
assert!(accountant.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
||||||
assert!(!acc.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
assert!(!accountant.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_forget_signature() {
|
fn test_forget_signature() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
acc.reserve_signature_with_last_id(&sig, &alice.last_id());
|
accountant.reserve_signature_with_last_id(&sig, &alice.last_id());
|
||||||
assert!(acc.forget_signature_with_last_id(&sig, &alice.last_id()));
|
assert!(accountant.forget_signature_with_last_id(&sig, &alice.last_id()));
|
||||||
assert!(!acc.forget_signature_with_last_id(&sig, &alice.last_id()));
|
assert!(!accountant.forget_signature_with_last_id(&sig, &alice.last_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_max_entry_ids() {
|
fn test_max_entry_ids() {
|
||||||
let alice = Mint::new(1);
|
let alice = Mint::new(1);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
for i in 0..MAX_ENTRY_IDS {
|
for i in 0..MAX_ENTRY_IDS {
|
||||||
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
|
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
|
||||||
acc.register_entry_id(&last_id);
|
accountant.register_entry_id(&last_id);
|
||||||
}
|
}
|
||||||
// Assert we're no longer able to use the oldest entry ID.
|
// Assert we're no longer able to use the oldest entry ID.
|
||||||
assert!(!acc.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
assert!(!accountant.reserve_signature_with_last_id(&sig, &alice.last_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_debits_before_credits() {
|
fn test_debits_before_credits() {
|
||||||
let mint = Mint::new(2);
|
let mint = Mint::new(2);
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
let alice = KeyPair::new();
|
let alice = KeyPair::new();
|
||||||
let tr0 = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id());
|
let tr0 = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id());
|
||||||
let tr1 = Transaction::new(&alice, mint.pubkey(), 1, mint.last_id());
|
let tr1 = Transaction::new(&alice, mint.pubkey(), 1, mint.last_id());
|
||||||
let trs = vec![tr0, tr1];
|
let trs = vec![tr0, tr1];
|
||||||
assert!(acc.process_verified_transactions(trs)[1].is_err());
|
assert!(accountant.process_verified_transactions(trs)[1].is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,7 +531,7 @@ mod bench {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn process_verified_event_bench(bencher: &mut Bencher) {
|
fn process_verified_event_bench(bencher: &mut Bencher) {
|
||||||
let mint = Mint::new(100_000_000);
|
let mint = Mint::new(100_000_000);
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
// Create transactions between unrelated parties.
|
// Create transactions between unrelated parties.
|
||||||
let transactions: Vec<_> = (0..4096)
|
let transactions: Vec<_> = (0..4096)
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
@ -522,15 +539,15 @@ mod bench {
|
|||||||
// Seed the 'from' account.
|
// Seed the 'from' account.
|
||||||
let rando0 = KeyPair::new();
|
let rando0 = KeyPair::new();
|
||||||
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, mint.last_id());
|
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, mint.last_id());
|
||||||
acc.process_verified_transaction(&tr).unwrap();
|
accountant.process_verified_transaction(&tr).unwrap();
|
||||||
|
|
||||||
// Seed the 'to' account and a cell for its signature.
|
// Seed the 'to' account and a cell for its signature.
|
||||||
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
|
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
|
||||||
acc.register_entry_id(&last_id);
|
accountant.register_entry_id(&last_id);
|
||||||
|
|
||||||
let rando1 = KeyPair::new();
|
let rando1 = KeyPair::new();
|
||||||
let tr = Transaction::new(&rando0, rando1.pubkey(), 1, last_id);
|
let tr = Transaction::new(&rando0, rando1.pubkey(), 1, last_id);
|
||||||
acc.process_verified_transaction(&tr).unwrap();
|
accountant.process_verified_transaction(&tr).unwrap();
|
||||||
|
|
||||||
// Finally, return a transaction that's unique
|
// Finally, return a transaction that's unique
|
||||||
Transaction::new(&rando0, rando1.pubkey(), 1, last_id)
|
Transaction::new(&rando0, rando1.pubkey(), 1, last_id)
|
||||||
@ -538,12 +555,13 @@ mod bench {
|
|||||||
.collect();
|
.collect();
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
// Since benchmarker runs this multiple times, we need to clear the signatures.
|
// Since benchmarker runs this multiple times, we need to clear the signatures.
|
||||||
for sigs in acc.last_ids.read().unwrap().iter() {
|
for sigs in accountant.last_ids.read().unwrap().iter() {
|
||||||
sigs.1.write().unwrap().clear();
|
sigs.1.write().unwrap().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
acc.process_verified_transactions(transactions.clone())
|
accountant
|
||||||
|
.process_verified_transactions(transactions.clone())
|
||||||
.iter()
|
.iter()
|
||||||
.all(|x| x.is_ok())
|
.all(|x| x.is_ok())
|
||||||
);
|
);
|
||||||
|
@ -13,21 +13,21 @@ use std::sync::{Arc, Mutex};
|
|||||||
pub struct AccountingStage {
|
pub struct AccountingStage {
|
||||||
pub output: Mutex<Receiver<Entry>>,
|
pub output: Mutex<Receiver<Entry>>,
|
||||||
entry_sender: Mutex<Sender<Entry>>,
|
entry_sender: Mutex<Sender<Entry>>,
|
||||||
pub acc: Arc<Accountant>,
|
pub accountant: Arc<Accountant>,
|
||||||
historian_input: Mutex<Sender<Signal>>,
|
historian_input: Mutex<Sender<Signal>>,
|
||||||
historian: Mutex<Historian>,
|
historian: Mutex<Historian>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountingStage {
|
impl AccountingStage {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(acc: Accountant, start_hash: &Hash, ms_per_tick: Option<u64>) -> Self {
|
pub fn new(accountant: Accountant, start_hash: &Hash, ms_per_tick: Option<u64>) -> Self {
|
||||||
let (historian_input, event_receiver) = channel();
|
let (historian_input, event_receiver) = channel();
|
||||||
let historian = Historian::new(event_receiver, start_hash, ms_per_tick);
|
let historian = Historian::new(event_receiver, start_hash, ms_per_tick);
|
||||||
let (entry_sender, output) = channel();
|
let (entry_sender, output) = channel();
|
||||||
AccountingStage {
|
AccountingStage {
|
||||||
output: Mutex::new(output),
|
output: Mutex::new(output),
|
||||||
entry_sender: Mutex::new(entry_sender),
|
entry_sender: Mutex::new(entry_sender),
|
||||||
acc: Arc::new(acc),
|
accountant: Arc::new(accountant),
|
||||||
historian_input: Mutex::new(historian_input),
|
historian_input: Mutex::new(historian_input),
|
||||||
historian: Mutex::new(historian),
|
historian: Mutex::new(historian),
|
||||||
}
|
}
|
||||||
@ -36,14 +36,14 @@ impl AccountingStage {
|
|||||||
/// Process the transactions in parallel and then log the successful ones.
|
/// Process the transactions in parallel and then log the successful ones.
|
||||||
pub fn process_events(&self, events: Vec<Event>) -> Result<()> {
|
pub fn process_events(&self, events: Vec<Event>) -> Result<()> {
|
||||||
let historian = self.historian.lock().unwrap();
|
let historian = self.historian.lock().unwrap();
|
||||||
let results = self.acc.process_verified_events(events);
|
let results = self.accountant.process_verified_events(events);
|
||||||
let events = results.into_iter().filter_map(|x| x.ok()).collect();
|
let events = results.into_iter().filter_map(|x| x.ok()).collect();
|
||||||
let sender = self.historian_input.lock().unwrap();
|
let sender = self.historian_input.lock().unwrap();
|
||||||
sender.send(Signal::Events(events))?;
|
sender.send(Signal::Events(events))?;
|
||||||
|
|
||||||
// Wait for the historian to tag our Events with an ID and then register it.
|
// Wait for the historian to tag our Events with an ID and then register it.
|
||||||
let entry = historian.output.lock().unwrap().recv()?;
|
let entry = historian.output.lock().unwrap().recv()?;
|
||||||
self.acc.register_entry_id(&entry.id);
|
self.accountant.register_entry_id(&entry.id);
|
||||||
self.entry_sender.lock().unwrap().send(entry)?;
|
self.entry_sender.lock().unwrap().send(entry)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -65,8 +65,8 @@ mod tests {
|
|||||||
// differently if either the server doesn't signal the ledger to add an
|
// differently if either the server doesn't signal the ledger to add an
|
||||||
// Entry OR if the verifier tries to parallelize across multiple Entries.
|
// Entry OR if the verifier tries to parallelize across multiple Entries.
|
||||||
let mint = Mint::new(2);
|
let mint = Mint::new(2);
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None);
|
let accounting_stage = AccountingStage::new(accountant, &mint.last_id(), None);
|
||||||
|
|
||||||
// Process a batch that includes a transaction that receives two tokens.
|
// Process a batch that includes a transaction that receives two tokens.
|
||||||
let alice = KeyPair::new();
|
let alice = KeyPair::new();
|
||||||
@ -86,15 +86,16 @@ mod tests {
|
|||||||
// Assert the user holds one token, not two. If the server only output one
|
// Assert the user holds one token, not two. If the server only output one
|
||||||
// entry, then the second transaction will be rejected, because it drives
|
// entry, then the second transaction will be rejected, because it drives
|
||||||
// the account balance below zero before the credit is added.
|
// the account balance below zero before the credit is added.
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
assert!(
|
assert!(
|
||||||
acc.process_verified_events(entry.events)
|
accountant
|
||||||
|
.process_verified_events(entry.events)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.all(|x| x.is_ok())
|
.all(|x| x.is_ok())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
assert_eq!(acc.get_balance(&alice.pubkey()), Some(1));
|
assert_eq!(accountant.get_balance(&alice.pubkey()), Some(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ mod bench {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn process_events_bench(_bencher: &mut Bencher) {
|
fn process_events_bench(_bencher: &mut Bencher) {
|
||||||
let mint = Mint::new(100_000_000);
|
let mint = Mint::new(100_000_000);
|
||||||
let acc = Accountant::new(&mint);
|
let accountant = Accountant::new(&mint);
|
||||||
// Create transactions between unrelated parties.
|
// Create transactions between unrelated parties.
|
||||||
let txs = 100_000;
|
let txs = 100_000;
|
||||||
let last_ids: Mutex<HashSet<Hash>> = Mutex::new(HashSet::new());
|
let last_ids: Mutex<HashSet<Hash>> = Mutex::new(HashSet::new());
|
||||||
@ -132,18 +133,18 @@ mod bench {
|
|||||||
let mut last_ids = last_ids.lock().unwrap();
|
let mut last_ids = last_ids.lock().unwrap();
|
||||||
if !last_ids.contains(&last_id) {
|
if !last_ids.contains(&last_id) {
|
||||||
last_ids.insert(last_id);
|
last_ids.insert(last_id);
|
||||||
acc.register_entry_id(&last_id);
|
accountant.register_entry_id(&last_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed the 'from' account.
|
// Seed the 'from' account.
|
||||||
let rando0 = KeyPair::new();
|
let rando0 = KeyPair::new();
|
||||||
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, last_id);
|
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, last_id);
|
||||||
acc.process_verified_transaction(&tr).unwrap();
|
accountant.process_verified_transaction(&tr).unwrap();
|
||||||
|
|
||||||
let rando1 = KeyPair::new();
|
let rando1 = KeyPair::new();
|
||||||
let tr = Transaction::new(&rando0, rando1.pubkey(), 2, last_id);
|
let tr = Transaction::new(&rando0, rando1.pubkey(), 2, last_id);
|
||||||
acc.process_verified_transaction(&tr).unwrap();
|
accountant.process_verified_transaction(&tr).unwrap();
|
||||||
|
|
||||||
// Finally, return a transaction that's unique
|
// Finally, return a transaction that's unique
|
||||||
Transaction::new(&rando0, rando1.pubkey(), 1, last_id)
|
Transaction::new(&rando0, rando1.pubkey(), 1, last_id)
|
||||||
@ -156,7 +157,7 @@ mod bench {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let (input, event_receiver) = channel();
|
let (input, event_receiver) = channel();
|
||||||
let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None);
|
let accounting_stage = AccountingStage::new(accountant, &mint.last_id(), None);
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
assert!(accounting_stage.process_events(events).is_ok());
|
assert!(accounting_stage.process_events(events).is_ok());
|
||||||
|
@ -87,10 +87,10 @@ fn main() {
|
|||||||
println!("Binding to {}", client_addr);
|
println!("Binding to {}", client_addr);
|
||||||
let socket = UdpSocket::bind(&client_addr).unwrap();
|
let socket = UdpSocket::bind(&client_addr).unwrap();
|
||||||
socket.set_read_timeout(Some(Duration::new(5, 0))).unwrap();
|
socket.set_read_timeout(Some(Duration::new(5, 0))).unwrap();
|
||||||
let mut acc = ThinClient::new(addr.parse().unwrap(), socket);
|
let mut accountant = ThinClient::new(addr.parse().unwrap(), socket);
|
||||||
|
|
||||||
println!("Get last ID...");
|
println!("Get last ID...");
|
||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = accountant.get_last_id().wait().unwrap();
|
||||||
println!("Got last ID {:?}", last_id);
|
println!("Got last ID {:?}", last_id);
|
||||||
|
|
||||||
println!("Creating keypairs...");
|
println!("Creating keypairs...");
|
||||||
@ -117,7 +117,7 @@ fn main() {
|
|||||||
nsps / 1_000_f64
|
nsps / 1_000_f64
|
||||||
);
|
);
|
||||||
|
|
||||||
let initial_tx_count = acc.transaction_count();
|
let initial_tx_count = accountant.transaction_count();
|
||||||
println!("initial count {}", initial_tx_count);
|
println!("initial count {}", initial_tx_count);
|
||||||
|
|
||||||
println!("Transfering {} transactions in {} batches", txs, threads);
|
println!("Transfering {} transactions in {} batches", txs, threads);
|
||||||
@ -129,16 +129,16 @@ fn main() {
|
|||||||
let mut client_addr: SocketAddr = client_addr.parse().unwrap();
|
let mut client_addr: SocketAddr = client_addr.parse().unwrap();
|
||||||
client_addr.set_port(0);
|
client_addr.set_port(0);
|
||||||
let socket = UdpSocket::bind(client_addr).unwrap();
|
let socket = UdpSocket::bind(client_addr).unwrap();
|
||||||
let acc = ThinClient::new(addr.parse().unwrap(), socket);
|
let accountant = ThinClient::new(addr.parse().unwrap(), socket);
|
||||||
for tr in trs {
|
for tr in trs {
|
||||||
acc.transfer_signed(tr.clone()).unwrap();
|
accountant.transfer_signed(tr.clone()).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("Waiting for transactions to complete...",);
|
println!("Waiting for transactions to complete...",);
|
||||||
let mut tx_count;
|
let mut tx_count;
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
tx_count = acc.transaction_count();
|
tx_count = accountant.transaction_count();
|
||||||
duration = now.elapsed();
|
duration = now.elapsed();
|
||||||
let txs = tx_count - initial_tx_count;
|
let txs = tx_count - initial_tx_count;
|
||||||
println!("Transactions processed {}", txs);
|
println!("Transactions processed {}", txs);
|
||||||
|
@ -94,28 +94,28 @@ fn main() {
|
|||||||
|
|
||||||
eprintln!("creating accountant...");
|
eprintln!("creating accountant...");
|
||||||
|
|
||||||
let acc = Accountant::new_from_deposit(&deposit.unwrap());
|
let accountant = Accountant::new_from_deposit(&deposit.unwrap());
|
||||||
acc.register_entry_id(&entry0.id);
|
accountant.register_entry_id(&entry0.id);
|
||||||
acc.register_entry_id(&entry1.id);
|
accountant.register_entry_id(&entry1.id);
|
||||||
|
|
||||||
eprintln!("processing entries...");
|
eprintln!("processing entries...");
|
||||||
|
|
||||||
let mut last_id = entry1.id;
|
let mut last_id = entry1.id;
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
last_id = entry.id;
|
last_id = entry.id;
|
||||||
let results = acc.process_verified_events(entry.events);
|
let results = accountant.process_verified_events(entry.events);
|
||||||
for result in results {
|
for result in results {
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
eprintln!("failed to process event {:?}", e);
|
eprintln!("failed to process event {:?}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
acc.register_entry_id(&last_id);
|
accountant.register_entry_id(&last_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("creating networking stack...");
|
eprintln!("creating networking stack...");
|
||||||
|
|
||||||
let accounting_stage = AccountingStage::new(acc, &last_id, Some(1000));
|
let accounting_stage = AccountingStage::new(accountant, &last_id, Some(1000));
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let tpu = Arc::new(Tpu::new(accounting_stage));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let serve_sock = UdpSocket::bind(&serve_addr).unwrap();
|
let serve_sock = UdpSocket::bind(&serve_addr).unwrap();
|
||||||
|
@ -179,24 +179,26 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let alice = Mint::new(10_000);
|
let alice = Mint::new(10_000);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30));
|
||||||
let acc = Arc::new(Tpu::new(accounting_stage));
|
let accountant = Arc::new(Tpu::new(accounting_stage));
|
||||||
let threads = Tpu::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
|
let threads =
|
||||||
|
Tpu::serve(&accountant, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
|
||||||
sleep(Duration::from_millis(300));
|
sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
|
|
||||||
let mut acc = ThinClient::new(addr, socket);
|
let mut accountant = ThinClient::new(addr, socket);
|
||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = accountant.get_last_id().wait().unwrap();
|
||||||
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
let _sig = accountant
|
||||||
|
.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut balance;
|
let mut balance;
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
balance = acc.get_balance(&bob_pubkey);
|
balance = accountant.get_balance(&bob_pubkey);
|
||||||
if balance.is_ok() {
|
if balance.is_ok() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -215,10 +217,10 @@ mod tests {
|
|||||||
fn test_bad_sig() {
|
fn test_bad_sig() {
|
||||||
let (leader_data, leader_gossip, _, leader_serve, leader_skinny) = tpu::test_node();
|
let (leader_data, leader_gossip, _, leader_serve, leader_skinny) = tpu::test_node();
|
||||||
let alice = Mint::new(10_000);
|
let alice = Mint::new(10_000);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30));
|
||||||
let tpu = Arc::new(Tpu::new(accounting_stage));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let serve_addr = leader_serve.local_addr().unwrap();
|
let serve_addr = leader_serve.local_addr().unwrap();
|
||||||
let threads = Tpu::serve(
|
let threads = Tpu::serve(
|
||||||
@ -286,14 +288,14 @@ mod tests {
|
|||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let leader_acc = {
|
let leader_acc = {
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30));
|
||||||
Arc::new(Tpu::new(accounting_stage))
|
Arc::new(Tpu::new(accounting_stage))
|
||||||
};
|
};
|
||||||
|
|
||||||
let replicant_acc = {
|
let replicant_acc = {
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30));
|
||||||
Arc::new(Tpu::new(accounting_stage))
|
Arc::new(Tpu::new(accounting_stage))
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -358,14 +360,15 @@ mod tests {
|
|||||||
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();
|
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();
|
||||||
|
|
||||||
let mut acc = ThinClient::new(leader.0.serve_addr, socket);
|
let mut accountant = ThinClient::new(leader.0.serve_addr, socket);
|
||||||
info!("getting leader last_id");
|
info!("getting leader last_id");
|
||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = accountant.get_last_id().wait().unwrap();
|
||||||
info!("executing leader transer");
|
info!("executing leader transer");
|
||||||
let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
let _sig = accountant
|
||||||
|
.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
info!("getting leader balance");
|
info!("getting leader balance");
|
||||||
acc.get_balance(&bob_pubkey).unwrap()
|
accountant.get_balance(&bob_pubkey).unwrap()
|
||||||
};
|
};
|
||||||
assert_eq!(leader_balance, 500);
|
assert_eq!(leader_balance, 500);
|
||||||
//verify replicant has the same balance
|
//verify replicant has the same balance
|
||||||
@ -374,9 +377,9 @@ mod tests {
|
|||||||
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();
|
socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap();
|
||||||
|
|
||||||
let mut acc = ThinClient::new(replicant.0.serve_addr, socket);
|
let mut accountant = ThinClient::new(replicant.0.serve_addr, socket);
|
||||||
info!("getting replicant balance");
|
info!("getting replicant balance");
|
||||||
if let Ok(bal) = acc.get_balance(&bob_pubkey) {
|
if let Ok(bal) = accountant.get_balance(&bob_pubkey) {
|
||||||
replicant_balance = bal;
|
replicant_balance = bal;
|
||||||
}
|
}
|
||||||
info!("replicant balance {}", replicant_balance);
|
info!("replicant balance {}", replicant_balance);
|
||||||
|
@ -14,18 +14,18 @@ use transaction::Transaction;
|
|||||||
pub struct ThinClientService {
|
pub struct ThinClientService {
|
||||||
//pub output: Mutex<Receiver<Response>>,
|
//pub output: Mutex<Receiver<Response>>,
|
||||||
//response_sender: Mutex<Sender<Response>>,
|
//response_sender: Mutex<Sender<Response>>,
|
||||||
pub acc: Arc<Accountant>,
|
accountant: Arc<Accountant>,
|
||||||
entry_info_subscribers: Mutex<Vec<SocketAddr>>,
|
entry_info_subscribers: Mutex<Vec<SocketAddr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThinClientService {
|
impl ThinClientService {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(acc: Arc<Accountant>) -> Self {
|
pub fn new(accountant: Arc<Accountant>) -> Self {
|
||||||
//let (response_sender, output) = channel();
|
//let (response_sender, output) = channel();
|
||||||
ThinClientService {
|
ThinClientService {
|
||||||
//output: Mutex::new(output),
|
//output: Mutex::new(output),
|
||||||
//response_sender: Mutex::new(response_sender),
|
//response_sender: Mutex::new(response_sender),
|
||||||
acc,
|
accountant,
|
||||||
entry_info_subscribers: Mutex::new(vec![]),
|
entry_info_subscribers: Mutex::new(vec![]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ impl ThinClientService {
|
|||||||
) -> Option<(Response, SocketAddr)> {
|
) -> Option<(Response, SocketAddr)> {
|
||||||
match msg {
|
match msg {
|
||||||
Request::GetBalance { key } => {
|
Request::GetBalance { key } => {
|
||||||
let val = self.acc.get_balance(&key);
|
let val = self.accountant.get_balance(&key);
|
||||||
let rsp = (Response::Balance { key, val }, rsp_addr);
|
let rsp = (Response::Balance { key, val }, rsp_addr);
|
||||||
info!("Response::Balance {:?}", rsp);
|
info!("Response::Balance {:?}", rsp);
|
||||||
Some(rsp)
|
Some(rsp)
|
||||||
|
39
src/tpu.rs
39
src/tpu.rs
@ -39,7 +39,7 @@ type SharedTpu = Arc<Tpu>;
|
|||||||
impl Tpu {
|
impl Tpu {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(accounting_stage: AccountingStage) -> Self {
|
pub fn new(accounting_stage: AccountingStage) -> Self {
|
||||||
let thin_client_service = ThinClientService::new(accounting_stage.acc.clone());
|
let thin_client_service = ThinClientService::new(accounting_stage.accountant.clone());
|
||||||
Tpu {
|
Tpu {
|
||||||
accounting_stage,
|
accounting_stage,
|
||||||
thin_client_service,
|
thin_client_service,
|
||||||
@ -48,7 +48,7 @@ impl Tpu {
|
|||||||
|
|
||||||
fn update_entry<W: Write>(obj: &Tpu, writer: &Mutex<W>, entry: &Entry) {
|
fn update_entry<W: Write>(obj: &Tpu, writer: &Mutex<W>, entry: &Entry) {
|
||||||
trace!("update_entry entry");
|
trace!("update_entry entry");
|
||||||
obj.accounting_stage.acc.register_entry_id(&entry.id);
|
obj.accounting_stage.accountant.register_entry_id(&entry.id);
|
||||||
writeln!(
|
writeln!(
|
||||||
writer.lock().unwrap(),
|
writer.lock().unwrap(),
|
||||||
"{}",
|
"{}",
|
||||||
@ -153,12 +153,12 @@ impl Tpu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn thin_client_service(
|
fn thin_client_service(
|
||||||
acc: Arc<Accountant>,
|
accountant: Arc<Accountant>,
|
||||||
exit: Arc<AtomicBool>,
|
exit: Arc<AtomicBool>,
|
||||||
socket: UdpSocket,
|
socket: UdpSocket,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
spawn(move || loop {
|
spawn(move || loop {
|
||||||
let _ = Self::process_thin_client_requests(&acc, &socket);
|
let _ = Self::process_thin_client_requests(&accountant, &socket);
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
info!("sync_service exiting");
|
info!("sync_service exiting");
|
||||||
break;
|
break;
|
||||||
@ -378,10 +378,10 @@ impl Tpu {
|
|||||||
for msgs in &blobs {
|
for msgs in &blobs {
|
||||||
let blob = msgs.read().unwrap();
|
let blob = msgs.read().unwrap();
|
||||||
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size]).unwrap();
|
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size]).unwrap();
|
||||||
let acc = &obj.accounting_stage.acc;
|
let accountant = &obj.accounting_stage.accountant;
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
acc.register_entry_id(&entry.id);
|
accountant.register_entry_id(&entry.id);
|
||||||
for result in acc.process_verified_events(entry.events) {
|
for result in accountant.process_verified_events(entry.events) {
|
||||||
result?;
|
result?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,8 +463,11 @@ impl Tpu {
|
|||||||
Mutex::new(writer),
|
Mutex::new(writer),
|
||||||
);
|
);
|
||||||
|
|
||||||
let t_skinny =
|
let t_skinny = Self::thin_client_service(
|
||||||
Self::thin_client_service(obj.accounting_stage.acc.clone(), exit.clone(), skinny);
|
obj.accounting_stage.accountant.clone(),
|
||||||
|
exit.clone(),
|
||||||
|
skinny,
|
||||||
|
);
|
||||||
|
|
||||||
let tpu = obj.clone();
|
let tpu = obj.clone();
|
||||||
let t_server = spawn(move || loop {
|
let t_server = spawn(move || loop {
|
||||||
@ -787,8 +790,8 @@ mod tests {
|
|||||||
|
|
||||||
let starting_balance = 10_000;
|
let starting_balance = 10_000;
|
||||||
let alice = Mint::new(starting_balance);
|
let alice = Mint::new(starting_balance);
|
||||||
let acc = Accountant::new(&alice);
|
let accountant = Accountant::new(&alice);
|
||||||
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30));
|
||||||
let tpu = Arc::new(Tpu::new(accounting_stage));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let replicate_addr = target1_data.replicate_addr;
|
let replicate_addr = target1_data.replicate_addr;
|
||||||
let threads = Tpu::replicate(
|
let threads = Tpu::replicate(
|
||||||
@ -814,11 +817,11 @@ mod tests {
|
|||||||
w.set_index(i).unwrap();
|
w.set_index(i).unwrap();
|
||||||
w.set_id(leader_id).unwrap();
|
w.set_id(leader_id).unwrap();
|
||||||
|
|
||||||
let acc = &tpu.accounting_stage.acc;
|
let accountant = &tpu.accounting_stage.accountant;
|
||||||
|
|
||||||
let tr0 = Event::new_timestamp(&bob_keypair, Utc::now());
|
let tr0 = Event::new_timestamp(&bob_keypair, Utc::now());
|
||||||
let entry0 = entry::create_entry(&cur_hash, i, vec![tr0]);
|
let entry0 = entry::create_entry(&cur_hash, i, vec![tr0]);
|
||||||
acc.register_entry_id(&cur_hash);
|
accountant.register_entry_id(&cur_hash);
|
||||||
cur_hash = hash(&cur_hash);
|
cur_hash = hash(&cur_hash);
|
||||||
|
|
||||||
let tr1 = Transaction::new(
|
let tr1 = Transaction::new(
|
||||||
@ -827,11 +830,11 @@ mod tests {
|
|||||||
transfer_amount,
|
transfer_amount,
|
||||||
cur_hash,
|
cur_hash,
|
||||||
);
|
);
|
||||||
acc.register_entry_id(&cur_hash);
|
accountant.register_entry_id(&cur_hash);
|
||||||
cur_hash = hash(&cur_hash);
|
cur_hash = hash(&cur_hash);
|
||||||
let entry1 =
|
let entry1 =
|
||||||
entry::create_entry(&cur_hash, i + num_blobs, vec![Event::Transaction(tr1)]);
|
entry::create_entry(&cur_hash, i + num_blobs, vec![Event::Transaction(tr1)]);
|
||||||
acc.register_entry_id(&cur_hash);
|
accountant.register_entry_id(&cur_hash);
|
||||||
cur_hash = hash(&cur_hash);
|
cur_hash = hash(&cur_hash);
|
||||||
|
|
||||||
alice_ref_balance -= transfer_amount;
|
alice_ref_balance -= transfer_amount;
|
||||||
@ -856,11 +859,11 @@ mod tests {
|
|||||||
msgs.push(msg);
|
msgs.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
let acc = &tpu.accounting_stage.acc;
|
let accountant = &tpu.accounting_stage.accountant;
|
||||||
let alice_balance = acc.get_balance(&alice.keypair().pubkey()).unwrap();
|
let alice_balance = accountant.get_balance(&alice.keypair().pubkey()).unwrap();
|
||||||
assert_eq!(alice_balance, alice_ref_balance);
|
assert_eq!(alice_balance, alice_ref_balance);
|
||||||
|
|
||||||
let bob_balance = acc.get_balance(&bob_keypair.pubkey()).unwrap();
|
let bob_balance = accountant.get_balance(&bob_keypair.pubkey()).unwrap();
|
||||||
assert_eq!(bob_balance, starting_balance - alice_ref_balance);
|
assert_eq!(bob_balance, starting_balance - alice_ref_balance);
|
||||||
|
|
||||||
exit.store(true, Ordering::Relaxed);
|
exit.store(true, Ordering::Relaxed);
|
||||||
|
Reference in New Issue
Block a user