Spelling and formatting

This commit is contained in:
Jack May
2019-01-04 16:04:31 -08:00
parent f8a67e282a
commit b7bd38744c
2 changed files with 24 additions and 4 deletions

View File

@ -94,6 +94,7 @@ impl AccountsDB {
} }
None None
} }
pub fn store(&mut self, pubkey: &Pubkey, account: &Account) { pub fn store(&mut self, pubkey: &Pubkey, account: &Account) {
if account.tokens == 0 { if account.tokens == 0 {
if self.checkpoints.is_empty() { if self.checkpoints.is_empty() {
@ -107,6 +108,7 @@ impl AccountsDB {
self.accounts.insert(pubkey.clone(), account.clone()); self.accounts.insert(pubkey.clone(), account.clone());
} }
} }
pub fn store_accounts( pub fn store_accounts(
&mut self, &mut self,
txs: &[Transaction], txs: &[Transaction],
@ -125,6 +127,7 @@ impl AccountsDB {
} }
} }
} }
fn load_account( fn load_account(
&self, &self,
tx: &Transaction, tx: &Transaction,
@ -171,6 +174,7 @@ impl AccountsDB {
Ok(called_accounts) Ok(called_accounts)
} }
} }
fn load_accounts( fn load_accounts(
&self, &self,
txs: &[Transaction], txs: &[Transaction],
@ -187,9 +191,11 @@ impl AccountsDB {
}) })
.collect() .collect()
} }
pub fn increment_transaction_count(&mut self, tx_count: usize) { pub fn increment_transaction_count(&mut self, tx_count: usize) {
self.transaction_count += tx_count as u64 self.transaction_count += tx_count as u64
} }
pub fn transaction_count(&self) -> u64 { pub fn transaction_count(&self) -> u64 {
self.transaction_count self.transaction_count
} }
@ -200,14 +206,16 @@ impl Accounts {
self.accounts_db.read().unwrap().keys() self.accounts_db.read().unwrap().keys()
} }
/// Slow because lock is held for 1 operation insted of many /// Slow because lock is held for 1 operation instead of many
pub fn load_slow(&self, pubkey: &Pubkey) -> Option<Account> { pub fn load_slow(&self, pubkey: &Pubkey) -> Option<Account> {
self.accounts_db.read().unwrap().load(pubkey).cloned() self.accounts_db.read().unwrap().load(pubkey).cloned()
} }
/// Slow because lock is held for 1 operation insted of many
/// Slow because lock is held for 1 operation instead of many
pub fn store_slow(&self, pubkey: &Pubkey, account: &Account) { pub fn store_slow(&self, pubkey: &Pubkey, account: &Account) {
self.accounts_db.write().unwrap().store(pubkey, account) self.accounts_db.write().unwrap().store(pubkey, account)
} }
fn lock_account( fn lock_account(
account_locks: &mut HashSet<Pubkey>, account_locks: &mut HashSet<Pubkey>,
keys: &[Pubkey], keys: &[Pubkey],
@ -236,6 +244,7 @@ impl Accounts {
} }
} }
} }
pub fn hash_internal_state(&self) -> Hash { pub fn hash_internal_state(&self) -> Hash {
self.accounts_db.read().unwrap().hash_internal_state() self.accounts_db.read().unwrap().hash_internal_state()
} }
@ -303,18 +312,23 @@ impl Accounts {
.unwrap() .unwrap()
.increment_transaction_count(tx_count) .increment_transaction_count(tx_count)
} }
pub fn transaction_count(&self) -> u64 { pub fn transaction_count(&self) -> u64 {
self.accounts_db.read().unwrap().transaction_count() self.accounts_db.read().unwrap().transaction_count()
} }
pub fn checkpoint(&self) { pub fn checkpoint(&self) {
self.accounts_db.write().unwrap().checkpoint() self.accounts_db.write().unwrap().checkpoint()
} }
pub fn rollback(&self) { pub fn rollback(&self) {
self.accounts_db.write().unwrap().rollback() self.accounts_db.write().unwrap().rollback()
} }
pub fn purge(&self, depth: usize) { pub fn purge(&self, depth: usize) {
self.accounts_db.write().unwrap().purge(depth) self.accounts_db.write().unwrap().purge(depth)
} }
pub fn depth(&self) -> usize { pub fn depth(&self) -> usize {
self.accounts_db.read().unwrap().depth() self.accounts_db.read().unwrap().depth()
} }
@ -328,6 +342,7 @@ impl Checkpoint for AccountsDB {
self.checkpoints self.checkpoints
.push_front((accounts, self.transaction_count())); .push_front((accounts, self.transaction_count()));
} }
fn rollback(&mut self) { fn rollback(&mut self) {
let (accounts, transaction_count) = self.checkpoints.pop_front().unwrap(); let (accounts, transaction_count) = self.checkpoints.pop_front().unwrap();
self.accounts = accounts; self.accounts = accounts;
@ -351,6 +366,7 @@ impl Checkpoint for AccountsDB {
merge(&mut self.accounts, &mut purge); merge(&mut self.accounts, &mut purge);
} }
} }
fn depth(&self) -> usize { fn depth(&self) -> usize {
self.checkpoints.len() self.checkpoints.len()
} }

View File

@ -394,6 +394,7 @@ impl Bank {
fn lock_accounts(&self, txs: &[Transaction]) -> Vec<Result<()>> { fn lock_accounts(&self, txs: &[Transaction]) -> Vec<Result<()>> {
self.accounts.lock_accounts(txs) self.accounts.lock_accounts(txs)
} }
fn unlock_accounts(&self, txs: &[Transaction], results: &[Result<()>]) { fn unlock_accounts(&self, txs: &[Transaction], results: &[Result<()>]) {
self.accounts.unlock_accounts(txs, results) self.accounts.unlock_accounts(txs, results)
} }
@ -410,7 +411,7 @@ impl Bank {
let lock_time = now.elapsed(); let lock_time = now.elapsed();
let now = Instant::now(); let now = Instant::now();
// Use a shorter maximum age when adding transactions into the pipeline. This will reduce // Use a shorter maximum age when adding transactions into the pipeline. This will reduce
// the likelyhood of any single thread getting starved and processing old ids. // the likelihood of any single thread getting starved and processing old ids.
// TODO: Banking stage threads should be prioritized to complete faster then this queue // TODO: Banking stage threads should be prioritized to complete faster then this queue
// expires. // expires.
let results = let results =
@ -463,6 +464,7 @@ impl Bank {
} }
Ok(()) Ok(())
} }
fn load_accounts( fn load_accounts(
&self, &self,
txs: &[Transaction], txs: &[Transaction],
@ -507,6 +509,7 @@ impl Bank {
} }
}) })
.collect(); .collect();
let execution_elapsed = now.elapsed(); let execution_elapsed = now.elapsed();
let now = Instant::now(); let now = Instant::now();
self.accounts self.accounts
@ -900,6 +903,7 @@ impl Bank {
} }
} }
} }
pub fn add_account_subscription( pub fn add_account_subscription(
&self, &self,
bank_sub_id: Pubkey, bank_sub_id: Pubkey,
@ -1432,7 +1436,7 @@ mod tests {
bank.transfer(1, &mint.keypair(), bob.pubkey(), mint.last_id()), bank.transfer(1, &mint.keypair(), bob.pubkey(), mint.last_id()),
Err(BankError::AccountInUse) Err(BankError::AccountInUse)
); );
// the second time shoudl fail as well // the second time should fail as well
// this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts // this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts
assert_eq!( assert_eq!(
bank.transfer(1, &mint.keypair(), bob.pubkey(), mint.last_id()), bank.transfer(1, &mint.keypair(), bob.pubkey(), mint.last_id()),