Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptopapi997 committed Dec 13, 2022
2 parents 1808f95 + 4ae12bf commit 55a5fc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions runtime/src/accounts_db.rs
Expand Up @@ -17970,6 +17970,7 @@ pub mod tests {
db.storage.map.insert(slot0, Arc::default());
assert!(!db.bank_hashes.read().unwrap().is_empty());
db.accounts_index.add_root(slot0);
db.accounts_index.add_uncleaned_roots([slot0].into_iter());
assert!(db.accounts_index.is_uncleaned_root(slot0));
assert!(db.accounts_index.is_alive_root(slot0));
db.handle_dropped_roots_for_ancient(dropped_roots);
Expand Down
24 changes: 14 additions & 10 deletions runtime/src/accounts_db/geyser_plugin_utils.rs
Expand Up @@ -89,29 +89,33 @@ impl AccountsDb {
let slot_stores = slot_stores.read().unwrap();
let mut accounts_to_stream: HashMap<Pubkey, StoredAccountMeta> = HashMap::default();
let mut measure_filter = Measure::start("accountsdb-plugin-filtering-accounts");
let mut previous_write_version = None;
for (_, storage_entry) in slot_stores.iter() {
let mut accounts = storage_entry.all_accounts();
let account_len = accounts.len();
notify_stats.total_accounts += account_len;
accounts.drain(..).into_iter().for_each(|account| {
let accounts = storage_entry.accounts.account_iter();
let mut account_len = 0;
accounts.for_each(|account| {
account_len += 1;
if let Some(previous_write_version) = previous_write_version {
assert!(previous_write_version < account.meta.write_version);
}
previous_write_version = Some(account.meta.write_version);
if notified_accounts.contains(&account.meta.pubkey) {
notify_stats.skipped_accounts += 1;
return;
}
match accounts_to_stream.entry(account.meta.pubkey) {
Entry::Occupied(mut entry) => {
let existing_account = entry.get();
if account.meta.write_version > existing_account.meta.write_version {
entry.insert(account);
} else {
notify_stats.skipped_accounts += 1;
}
// later entries in the same slot are more recent and override earlier accounts for the same pubkey
// We can pass an incrementing number here for write_version in the future, if the storage does not have a write_version.
// As long as all accounts for this slot are in 1 append vec that can be itereated olest to newest.
entry.insert(account);
}
Entry::Vacant(entry) => {
entry.insert(account);
}
}
});
notify_stats.total_accounts += account_len;
}
measure_filter.stop();
notify_stats.elapsed_filtering_us += measure_filter.as_us() as usize;
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/accounts_index.rs
Expand Up @@ -3139,6 +3139,7 @@ pub mod tests {
assert_eq!(0, index.roots_tracker.read().unwrap().uncleaned_roots.len());
index.add_root(0);
index.add_root(1);
index.add_uncleaned_roots([0, 1].into_iter());
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());

assert_eq!(
Expand All @@ -3165,6 +3166,7 @@ pub mod tests {

index.add_root(2);
index.add_root(3);
index.add_uncleaned_roots([2, 3].into_iter());
assert_eq!(4, index.roots_tracker.read().unwrap().alive_roots.len());
assert_eq!(2, index.roots_tracker.read().unwrap().uncleaned_roots.len());
assert_eq!(
Expand Down

0 comments on commit 55a5fc7

Please sign in to comment.