diff --git a/runtime/src/accounts_cache.rs b/runtime/src/accounts_cache.rs index ce70a3c6776481..18017814a77a5c 100644 --- a/runtime/src/accounts_cache.rs +++ b/runtime/src/accounts_cache.rs @@ -57,6 +57,7 @@ impl SlotCacheInner { pub fn get_cloned(&self, pubkey: &Pubkey) -> Option { self.cache .get(pubkey) + // Could return AccountNoData here // 1) Maybe can eventually use a Cow to avoid a clone on every read // 2) Popping is only safe if its guaranteed only replay/banking threads // are reading from the AccountsDb @@ -86,7 +87,7 @@ impl Deref for SlotCacheInner { #[derive(Debug, Clone)] pub struct CachedAccount { - pub account: Account, + pub account: Account, // would become AccountNoData pub hash: Hash, } diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 6fd302fc0356cd..317dbec2cb6e57 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -276,6 +276,7 @@ impl<'a> LoadedAccount<'a> { } } + /* would become AccountNoData */ pub fn account(self) -> Account { match self { LoadedAccount::Stored(stored_account_meta) => stored_account_meta.clone_account(), @@ -2195,7 +2196,7 @@ impl AccountsDb { bank_hashes.insert(slot, new_hash_info); } - pub fn load(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> { + pub fn load(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account /* would become AccountNoData */, Slot)> { self.do_load(ancestors, pubkey, None) } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 8dbcf5d17cff25..8f4d76358c9afc 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -111,9 +111,9 @@ impl ExecuteTimings { type BankStatusCache = StatusCache>; #[frozen_abi(digest = "3ZaEt781qwhfQSE4DZPBHhng2S6MuimchRjkR9ZWzDFs")] pub type BankSlotDelta = SlotDelta>; -type TransactionAccountRefCells = Vec>>; -type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell)>; -type TransactionLoaderRefCells = Vec)>>; +type TransactionAccountRefCells = Vec>>; /* would become AccountNoData */ +type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell)>; /* would become AccountNoData */ +type TransactionLoaderRefCells = Vec)>>; /* would become AccountNoData */ // Eager rent collection repeats in cyclic manner. // Each cycle is composed of number of tiny pubkey subranges diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 5750981b25a7e4..3c6df7de3767ec 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -58,7 +58,7 @@ impl Executors { pub struct PreAccount { key: Pubkey, is_writable: bool, - account: RefCell, + account: RefCell, /* would become AccountNoData */ } impl PreAccount { pub fn new(key: &Pubkey, account: &Account, is_writable: bool) -> Self { diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 27400b6d369a05..4263b05ee2c90a 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -1,6 +1,6 @@ use crate::{clock::Epoch, pubkey::Pubkey}; use solana_program::{account_info::AccountInfo, sysvar::Sysvar}; -use std::{cell::RefCell, cmp, fmt, rc::Rc}; +use std::{cell::RefCell, cmp, fmt, rc::Rc, sync::Arc}; /// An Account with data that is stored on chain #[repr(C)] @@ -21,6 +21,36 @@ pub struct Account { pub rent_epoch: Epoch, } +#[derive(Clone, Default, Debug, PartialEq, Eq, AbiExample)] +pub struct AccountNoData { + /// lamports in the account + pub lamports: u64, + /// data held in this account + pub data: Arc>, + /// the program that owns this account. If executable, the program that loads this account. + pub owner: Pubkey, + /// this account's data contains a loaded program (and is now read-only) + pub executable: bool, + /// the epoch at which this account will next owe rent + pub rent_epoch: Epoch, +} + +pub trait AnAccount: Default + Clone + Sized { + fn lamports(&self) -> u64; + fn set_lamports(&mut self, lamports: u64); + fn data(&self) -> &Vec; + fn set_data(&mut self, data: Vec); + fn owner(&self) -> &Pubkey; + fn set_owner(&mut self, owner: Pubkey); + fn executable(&self) -> bool; + fn rent_epoch(&self) -> Epoch; + fn set_rent_epoch(&mut self, epoch: Epoch); + fn clone_as_account_no_data(&self) -> AccountNoData; + fn clone_as_account(&self) -> Account; + fn from_account_no_data(item: AccountNoData) -> Self; + fn to_account_no_data(&mut self) -> AccountNoData; +} + impl fmt::Debug for Account { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let data_len = cmp::min(64, self.data.len()); diff --git a/sdk/src/keyed_account.rs b/sdk/src/keyed_account.rs index 9712f4c076436f..ed06ee82d37e84 100644 --- a/sdk/src/keyed_account.rs +++ b/sdk/src/keyed_account.rs @@ -14,7 +14,7 @@ pub struct KeyedAccount<'a> { is_signer: bool, // Transaction was signed by this account's key is_writable: bool, key: &'a Pubkey, - pub account: &'a RefCell, + pub account: &'a RefCell, /* would become AccountNoData */ } impl<'a> KeyedAccount<'a> {