diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index d5175f4aec..432f0cdcb7 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -24,7 +24,7 @@ use std::{ Range, RangeBounds, }, sync::{ - atomic::{AtomicU64, Ordering}, + atomic::{AtomicBool, AtomicU64, Ordering}, Arc, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard, }, }; @@ -116,10 +116,24 @@ impl AccountSecondaryIndexes { } } +#[derive(Debug, Default)] +pub struct AccountMapEntryMeta { + pub dirty: AtomicBool, +} + +impl AccountMapEntryMeta { + pub fn new_dirty() -> Self { + AccountMapEntryMeta { + dirty: AtomicBool::new(true), + } + } +} + #[derive(Debug, Default)] pub struct AccountMapEntryInner { ref_count: AtomicU64, pub slot_list: RwLock>, + pub meta: AccountMapEntryMeta, } impl AccountMapEntryInner { @@ -133,6 +147,15 @@ impl AccountMapEntryInner { } else { self.ref_count.fetch_sub(1, Ordering::Relaxed); } + self.set_dirty(true); + } + + pub fn dirty(&self) -> bool { + self.meta.dirty.load(Ordering::Relaxed) + } + + pub fn set_dirty(&self, value: bool) -> bool { + self.meta.dirty.swap(value, Ordering::Relaxed) } } @@ -207,7 +230,9 @@ impl WriteAccountMapEntry { &mut self, user: impl for<'this> FnOnce(&mut RwLockWriteGuard<'this, SlotList>) -> RT, ) -> RT { - self.with_slot_list_guard_mut(user) + let result = self.with_slot_list_guard_mut(user); + self.borrow_owned_entry().set_dirty(true); + result } // create an entry that is equivalent to this process: @@ -219,6 +244,7 @@ impl WriteAccountMapEntry { Arc::new(AccountMapEntryInner { ref_count: AtomicU64::new(ref_count), slot_list: RwLock::new(vec![(slot, account_info)]), + meta: AccountMapEntryMeta::new_dirty(), }) } diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 1c86be2f24..b2c2229b16 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -153,6 +153,7 @@ impl InMemAccountsIndex { if addref { current.add_un_ref(true); } + new_value.set_dirty(true); } // modifies slot_list