diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 763c347e8a..96b7c4c417 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -3338,7 +3338,7 @@ impl AccountsDb { slot: Slot, hashes: &[impl Borrow], mut storage_finder: F, - accounts_and_meta_to_store: &[(StoredMeta, Option<&AccountSharedData>)], + accounts_and_meta_to_store: &[(StoredMeta, Option<&impl ReadableAccount>)], ) -> Vec { assert_eq!(hashes.len(), accounts_and_meta_to_store.len()); let mut infos: Vec = Vec::with_capacity(accounts_and_meta_to_store.len()); @@ -3725,7 +3725,7 @@ impl AccountsDb { &self, slot: Slot, hashes: Option<&[impl Borrow]>, - accounts_and_meta_to_store: &[(StoredMeta, Option<&AccountSharedData>)], + accounts_and_meta_to_store: &[(StoredMeta, Option<&impl ReadableAccount>)], ) -> Vec { let len = accounts_and_meta_to_store.len(); let hashes = hashes.map(|hashes| { @@ -3739,8 +3739,9 @@ impl AccountsDb { .map(|(i, (meta, account))| { let hash = hashes.map(|hashes| hashes[i].borrow()); - let account = account.cloned().unwrap_or_default(); - + let account = account + .map(|account| account.to_account_shared_data()) + .unwrap_or_default(); let account_info = AccountInfo { store_id: CACHE_VIRTUAL_STORAGE_ID, offset: CACHE_VIRTUAL_OFFSET, @@ -3767,13 +3768,13 @@ impl AccountsDb { >( &self, slot: Slot, - accounts: &[(&Pubkey, &AccountSharedData)], + accounts: &[(&Pubkey, &impl ReadableAccount)], hashes: Option<&[impl Borrow]>, storage_finder: F, mut write_version_producer: P, is_cached_store: bool, ) -> Vec { - let accounts_and_meta_to_store: Vec<(StoredMeta, Option<&AccountSharedData>)> = accounts + let accounts_and_meta_to_store: Vec<_> = accounts .iter() .map(|(pubkey, account)| { self.read_only_accounts_cache.remove(pubkey, slot); @@ -4322,7 +4323,7 @@ impl AccountsDb { &self, slot: Slot, infos: Vec, - accounts: &[(&Pubkey, &AccountSharedData)], + accounts: &[(&Pubkey, &impl ReadableAccount)], ) -> SlotList { let mut reclaims = SlotList::::with_capacity(infos.len() * 2); for (info, pubkey_account) in infos.into_iter().zip(accounts.iter()) { @@ -4743,7 +4744,7 @@ impl AccountsDb { fn store_accounts_frozen<'a>( &'a self, slot: Slot, - accounts: &[(&Pubkey, &AccountSharedData)], + accounts: &[(&Pubkey, &impl ReadableAccount)], hashes: Option<&[impl Borrow]>, storage_finder: Option>, write_version_producer: Option>>, @@ -4767,7 +4768,7 @@ impl AccountsDb { fn store_accounts_custom<'a>( &'a self, slot: Slot, - accounts: &[(&Pubkey, &AccountSharedData)], + accounts: &[(&Pubkey, &impl ReadableAccount)], hashes: Option<&[impl Borrow]>, storage_finder: Option>, write_version_producer: Option>>, diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index 18541e37ba..f0d7a74e35 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -462,7 +462,7 @@ impl AppendVec { /// and will be available to other threads. pub fn append_accounts( &self, - accounts: &[(StoredMeta, Option<&AccountSharedData>)], + accounts: &[(StoredMeta, Option<&impl ReadableAccount>)], hashes: &[impl Borrow], ) -> Vec { let _lock = self.append_lock.lock().unwrap(); diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 559621589c..72ef7902d5 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -116,6 +116,15 @@ pub trait ReadableAccount: Sized { fn owner(&self) -> &Pubkey; fn executable(&self) -> bool; fn rent_epoch(&self) -> Epoch; + fn to_account_shared_data(&self) -> AccountSharedData { + AccountSharedData::create( + self.lamports(), + self.data().to_vec(), + *self.owner(), + self.executable(), + self.rent_epoch(), + ) + } } impl ReadableAccount for Account { @@ -668,6 +677,17 @@ pub mod tests { account2.serialize_data(&"hello world").unwrap(); } + #[test] + fn test_to_account_shared_data() { + let key = Pubkey::new_unique(); + let (account1, account2) = make_two_accounts(&key); + assert!(accounts_equal(&account1, &account2)); + let account3 = account1.to_account_shared_data(); + let account4 = account2.to_account_shared_data(); + assert!(accounts_equal(&account1, &account3)); + assert!(accounts_equal(&account1, &account4)); + } + #[test] fn test_account_shared_data() { let key = Pubkey::new_unique();