Write account path impl ReadableAccount (#16779)
This commit is contained in:
parent
783bd79e9d
commit
f533d3be77
|
@ -3338,7 +3338,7 @@ impl AccountsDb {
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
hashes: &[impl Borrow<Hash>],
|
hashes: &[impl Borrow<Hash>],
|
||||||
mut storage_finder: F,
|
mut storage_finder: F,
|
||||||
accounts_and_meta_to_store: &[(StoredMeta, Option<&AccountSharedData>)],
|
accounts_and_meta_to_store: &[(StoredMeta, Option<&impl ReadableAccount>)],
|
||||||
) -> Vec<AccountInfo> {
|
) -> Vec<AccountInfo> {
|
||||||
assert_eq!(hashes.len(), accounts_and_meta_to_store.len());
|
assert_eq!(hashes.len(), accounts_and_meta_to_store.len());
|
||||||
let mut infos: Vec<AccountInfo> = Vec::with_capacity(accounts_and_meta_to_store.len());
|
let mut infos: Vec<AccountInfo> = Vec::with_capacity(accounts_and_meta_to_store.len());
|
||||||
|
@ -3725,7 +3725,7 @@ impl AccountsDb {
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
hashes: Option<&[impl Borrow<Hash>]>,
|
hashes: Option<&[impl Borrow<Hash>]>,
|
||||||
accounts_and_meta_to_store: &[(StoredMeta, Option<&AccountSharedData>)],
|
accounts_and_meta_to_store: &[(StoredMeta, Option<&impl ReadableAccount>)],
|
||||||
) -> Vec<AccountInfo> {
|
) -> Vec<AccountInfo> {
|
||||||
let len = accounts_and_meta_to_store.len();
|
let len = accounts_and_meta_to_store.len();
|
||||||
let hashes = hashes.map(|hashes| {
|
let hashes = hashes.map(|hashes| {
|
||||||
|
@ -3739,8 +3739,9 @@ impl AccountsDb {
|
||||||
.map(|(i, (meta, account))| {
|
.map(|(i, (meta, account))| {
|
||||||
let hash = hashes.map(|hashes| hashes[i].borrow());
|
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 {
|
let account_info = AccountInfo {
|
||||||
store_id: CACHE_VIRTUAL_STORAGE_ID,
|
store_id: CACHE_VIRTUAL_STORAGE_ID,
|
||||||
offset: CACHE_VIRTUAL_OFFSET,
|
offset: CACHE_VIRTUAL_OFFSET,
|
||||||
|
@ -3767,13 +3768,13 @@ impl AccountsDb {
|
||||||
>(
|
>(
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &AccountSharedData)],
|
accounts: &[(&Pubkey, &impl ReadableAccount)],
|
||||||
hashes: Option<&[impl Borrow<Hash>]>,
|
hashes: Option<&[impl Borrow<Hash>]>,
|
||||||
storage_finder: F,
|
storage_finder: F,
|
||||||
mut write_version_producer: P,
|
mut write_version_producer: P,
|
||||||
is_cached_store: bool,
|
is_cached_store: bool,
|
||||||
) -> Vec<AccountInfo> {
|
) -> Vec<AccountInfo> {
|
||||||
let accounts_and_meta_to_store: Vec<(StoredMeta, Option<&AccountSharedData>)> = accounts
|
let accounts_and_meta_to_store: Vec<_> = accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pubkey, account)| {
|
.map(|(pubkey, account)| {
|
||||||
self.read_only_accounts_cache.remove(pubkey, slot);
|
self.read_only_accounts_cache.remove(pubkey, slot);
|
||||||
|
@ -4322,7 +4323,7 @@ impl AccountsDb {
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
infos: Vec<AccountInfo>,
|
infos: Vec<AccountInfo>,
|
||||||
accounts: &[(&Pubkey, &AccountSharedData)],
|
accounts: &[(&Pubkey, &impl ReadableAccount)],
|
||||||
) -> SlotList<AccountInfo> {
|
) -> SlotList<AccountInfo> {
|
||||||
let mut reclaims = SlotList::<AccountInfo>::with_capacity(infos.len() * 2);
|
let mut reclaims = SlotList::<AccountInfo>::with_capacity(infos.len() * 2);
|
||||||
for (info, pubkey_account) in infos.into_iter().zip(accounts.iter()) {
|
for (info, pubkey_account) in infos.into_iter().zip(accounts.iter()) {
|
||||||
|
@ -4743,7 +4744,7 @@ impl AccountsDb {
|
||||||
fn store_accounts_frozen<'a>(
|
fn store_accounts_frozen<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &AccountSharedData)],
|
accounts: &[(&Pubkey, &impl ReadableAccount)],
|
||||||
hashes: Option<&[impl Borrow<Hash>]>,
|
hashes: Option<&[impl Borrow<Hash>]>,
|
||||||
storage_finder: Option<StorageFinder<'a>>,
|
storage_finder: Option<StorageFinder<'a>>,
|
||||||
write_version_producer: Option<Box<dyn Iterator<Item = u64>>>,
|
write_version_producer: Option<Box<dyn Iterator<Item = u64>>>,
|
||||||
|
@ -4767,7 +4768,7 @@ impl AccountsDb {
|
||||||
fn store_accounts_custom<'a>(
|
fn store_accounts_custom<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
accounts: &[(&Pubkey, &AccountSharedData)],
|
accounts: &[(&Pubkey, &impl ReadableAccount)],
|
||||||
hashes: Option<&[impl Borrow<Hash>]>,
|
hashes: Option<&[impl Borrow<Hash>]>,
|
||||||
storage_finder: Option<StorageFinder<'a>>,
|
storage_finder: Option<StorageFinder<'a>>,
|
||||||
write_version_producer: Option<Box<dyn Iterator<Item = u64>>>,
|
write_version_producer: Option<Box<dyn Iterator<Item = u64>>>,
|
||||||
|
|
|
@ -462,7 +462,7 @@ impl AppendVec {
|
||||||
/// and will be available to other threads.
|
/// and will be available to other threads.
|
||||||
pub fn append_accounts(
|
pub fn append_accounts(
|
||||||
&self,
|
&self,
|
||||||
accounts: &[(StoredMeta, Option<&AccountSharedData>)],
|
accounts: &[(StoredMeta, Option<&impl ReadableAccount>)],
|
||||||
hashes: &[impl Borrow<Hash>],
|
hashes: &[impl Borrow<Hash>],
|
||||||
) -> Vec<usize> {
|
) -> Vec<usize> {
|
||||||
let _lock = self.append_lock.lock().unwrap();
|
let _lock = self.append_lock.lock().unwrap();
|
||||||
|
|
|
@ -116,6 +116,15 @@ pub trait ReadableAccount: Sized {
|
||||||
fn owner(&self) -> &Pubkey;
|
fn owner(&self) -> &Pubkey;
|
||||||
fn executable(&self) -> bool;
|
fn executable(&self) -> bool;
|
||||||
fn rent_epoch(&self) -> Epoch;
|
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 {
|
impl ReadableAccount for Account {
|
||||||
|
@ -668,6 +677,17 @@ pub mod tests {
|
||||||
account2.serialize_data(&"hello world").unwrap();
|
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]
|
#[test]
|
||||||
fn test_account_shared_data() {
|
fn test_account_shared_data() {
|
||||||
let key = Pubkey::new_unique();
|
let key = Pubkey::new_unique();
|
||||||
|
|
Loading…
Reference in New Issue