From a00284c727aa5ed7b45f780c3aaa762c33f928da Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Fri, 9 Nov 2018 14:22:13 -0700 Subject: [PATCH] Remove userdata diff and make helper fn --- src/bank.rs | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index e28d33f7d9..4bf3c4dd58 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -982,31 +982,6 @@ impl Bank { let mut loaded_accounts = self.load_accounts(txs, locked_accounts.clone(), max_age, &mut error_counters); - // Check account subscriptions, then store data for notifications - let pre_userdata: Vec<_>; - { - let subscriptions = self.account_subscriptions.read().unwrap(); - let accounts = self.accounts.read().unwrap(); - pre_userdata = txs - .iter() - .zip(locked_accounts.into_iter()) - .map(|(tx, result)| match result { - Ok(()) => { - let key_map: Vec<(&Pubkey, Account)> = tx - .account_keys - .iter() - .map(|key| (key, accounts.load(key).cloned().unwrap_or_default())) - .collect(); - Ok(key_map) - } - Err(e) => Err(e), - }).filter(|result| result.is_ok()) - .flat_map(|result| result.unwrap()) - .filter(|(pubkey, _)| subscriptions.get(&pubkey).is_some()) - .map(|(pubkey, a)| (pubkey, a.userdata.clone())) - .collect(); - } - let load_elapsed = now.elapsed(); let now = Instant::now(); let executed: Vec> = loaded_accounts @@ -1020,16 +995,8 @@ impl Bank { let now = Instant::now(); self.store_accounts(txs, &executed, &loaded_accounts); - // Send notifications - { - let accounts = self.accounts.read().unwrap(); - for (pubkey, userdata) in &pre_userdata { - let account = accounts.load(pubkey).cloned().unwrap_or_default(); - if userdata != &account.userdata { - self.check_account_subscriptions(&pubkey, &account); - } - } - } + // Check account subscriptions and send notifications + self.send_account_notifications(txs, locked_accounts); // once committed there is no way to unroll let write_elapsed = now.elapsed(); @@ -1407,6 +1374,17 @@ impl Bank { self.finality_time.store(finality, Ordering::Relaxed); } + fn send_account_notifications(&self, txs: &[Transaction], locked_accounts: Vec>) { + let accounts = self.accounts.read().unwrap(); + txs.iter() + .zip(locked_accounts.into_iter()) + .filter(|(_, result)| result.is_ok()) + .flat_map(|(tx, _)| &tx.account_keys) + .for_each(|pubkey| { + let account = accounts.load(pubkey).cloned().unwrap_or_default(); + self.check_account_subscriptions(&pubkey, &account); + }); + } pub fn add_account_subscription( &self, bank_sub_id: Pubkey,