diff --git a/Cargo.lock b/Cargo.lock index a60e772c897070..212e523ae1b96f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2410,9 +2410,9 @@ dependencies = [ [[package]] name = "ouroboros" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "776469997c56d7130b691a5edea1cbe63d7fef495f98b1b0ced0f3a5571c37aa" +checksum = "cc04551635026d3ac7bc646698ea1836a85ed2a26b7094fe1d15d8b14854c4a2" dependencies = [ "ouroboros_macro", "stable_deref_trait", @@ -2420,9 +2420,9 @@ dependencies = [ [[package]] name = "ouroboros_macro" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85165ba45bb44e86ddb86e33ad92640522d572229c5c326eb7eb81ef31b06ce7" +checksum = "cec33dfceabec83cd0e95a5ce9d20e76ab3a5cbfef59659b8c927f69b93ed8ae" dependencies = [ "Inflector", "proc-macro2 1.0.24", diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index 9e7f0e82bce96b..3b50e4038f340d 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -1259,9 +1259,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "ouroboros" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "776469997c56d7130b691a5edea1cbe63d7fef495f98b1b0ced0f3a5571c37aa" +checksum = "cc04551635026d3ac7bc646698ea1836a85ed2a26b7094fe1d15d8b14854c4a2" dependencies = [ "ouroboros_macro", "stable_deref_trait", @@ -1269,9 +1269,9 @@ dependencies = [ [[package]] name = "ouroboros_macro" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85165ba45bb44e86ddb86e33ad92640522d572229c5c326eb7eb81ef31b06ce7" +checksum = "cec33dfceabec83cd0e95a5ce9d20e76ab3a5cbfef59659b8c927f69b93ed8ae" dependencies = [ "Inflector", "proc-macro2 1.0.24", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 4507b479980303..4f6e488a192738 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -29,7 +29,7 @@ memmap = "0.7.0" num-derive = { version = "0.3" } num-traits = { version = "0.2" } num_cpus = "1.13.0" -ouroboros = "0.4.0" +ouroboros = "0.5.1" rand = "0.7.0" rayon = "1.4.1" regex = "1.3.9" diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 9100e685f3fa06..ee5ece068199ec 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -32,9 +32,9 @@ pub struct AccountMapEntryInner { #[self_referencing] pub struct ReadAccountMapEntry { - pub owned_entry: AccountMapEntry, + owned_entry: AccountMapEntry, #[borrows(owned_entry)] - pub slot_list_guard: RwLockReadGuard<'this, SlotList>, + slot_list_guard: RwLockReadGuard<'this, SlotList>, } impl ReadAccountMapEntry { @@ -47,19 +47,19 @@ impl ReadAccountMapEntry { } pub fn slot_list(&self) -> &SlotList { - &*self.slot_list_guard + &*self.borrow_slot_list_guard() } pub fn ref_count(&self) -> &AtomicU64 { - &self.owned_entry.ref_count + &self.borrow_owned_entry_contents().ref_count } } #[self_referencing] pub struct WriteAccountMapEntry { - pub owned_entry: AccountMapEntry, + owned_entry: AccountMapEntry, #[borrows(owned_entry)] - pub slot_list_guard: RwLockWriteGuard<'this, SlotList>, + slot_list_guard: RwLockWriteGuard<'this, SlotList>, } impl WriteAccountMapEntry { @@ -72,15 +72,18 @@ impl WriteAccountMapEntry { } pub fn slot_list(&mut self) -> &SlotList { - &*self.slot_list_guard + &*self.borrow_slot_list_guard() } - pub fn slot_list_mut(&mut self) -> &mut SlotList { - &mut *self.slot_list_guard + pub fn slot_list_mut( + &mut self, + user: impl for<'this> FnOnce(&mut RwLockWriteGuard<'this, SlotList>) -> RT, + ) -> RT { + self.with_slot_list_guard_mut(user) } pub fn ref_count(&self) -> &AtomicU64 { - &self.owned_entry.ref_count + &self.borrow_owned_entry_contents().ref_count } // Try to update an item in the slot list the given `slot` If an item for the slot @@ -97,12 +100,12 @@ impl WriteAccountMapEntry { assert!(same_slot_previous_updates.len() <= 1); if let Some((list_index, (s, previous_update_value))) = same_slot_previous_updates.pop() { reclaims.push((*s, previous_update_value.clone())); - self.slot_list_mut().remove(list_index); + self.slot_list_mut(|list| list.remove(list_index)); } else { // Only increment ref count if the account was not prevously updated in this slot self.ref_count().fetch_add(1, Ordering::Relaxed); } - self.slot_list_mut().push((slot, account_info)); + self.slot_list_mut(|list| list.push((slot, account_info))); } } @@ -301,22 +304,24 @@ impl AccountsIndex { // if this account has no more entries. pub fn purge(&self, pubkey: &Pubkey) -> (SlotList, bool) { let mut write_account_map_entry = self.get_account_write_entry(pubkey).unwrap(); - let slot_list = write_account_map_entry.slot_list_mut(); - let reclaims = self.get_rooted_entries(&slot_list); - slot_list.retain(|(slot, _)| !self.is_root(*slot)); - (reclaims, slot_list.is_empty()) + write_account_map_entry.slot_list_mut(|slot_list| { + let reclaims = self.get_rooted_entries(slot_list); + slot_list.retain(|(slot, _)| !self.is_root(*slot)); + (reclaims, slot_list.is_empty()) + }) } pub fn purge_exact(&self, pubkey: &Pubkey, slots: HashSet) -> (SlotList, bool) { let mut write_account_map_entry = self.get_account_write_entry(pubkey).unwrap(); - let slot_list = write_account_map_entry.slot_list_mut(); - let reclaims = slot_list - .iter() - .filter(|(slot, _)| slots.contains(&slot)) - .cloned() - .collect(); - slot_list.retain(|(slot, _)| !slots.contains(slot)); - (reclaims, slot_list.is_empty()) + write_account_map_entry.slot_list_mut(|slot_list| { + let reclaims = slot_list + .iter() + .filter(|(slot, _)| slots.contains(&slot)) + .cloned() + .collect(); + slot_list.retain(|(slot, _)| !slots.contains(slot)); + (reclaims, slot_list.is_empty()) + }) } // Given a SlotSlice `L`, a list of ancestors and a maximum slot, find the latest element @@ -442,7 +447,9 @@ impl AccountsIndex { max_clean_root: Option, ) { if let Some(mut locked_entry) = self.get_account_write_entry(pubkey) { - self.purge_older_root_entries(locked_entry.slot_list_mut(), reclaims, max_clean_root); + locked_entry.slot_list_mut(|slot_list| { + self.purge_older_root_entries(slot_list, reclaims, max_clean_root); + }); } } @@ -453,12 +460,13 @@ impl AccountsIndex { reclaims: &mut SlotList, ) { if let Some(mut locked_entry) = self.get_account_write_entry(pubkey) { - let slot_list = locked_entry.slot_list_mut(); - slot_list.retain(|(slot, entry)| { - if *slot == purge_slot { - reclaims.push((*slot, entry.clone())); - } - *slot != purge_slot + locked_entry.slot_list_mut(|slot_list| { + slot_list.retain(|(slot, entry)| { + if *slot == purge_slot { + reclaims.push((*slot, entry.clone())); + } + *slot != purge_slot + }); }); } }