solana_accounts_db/account_storage/
meta.rsuse {
crate::{
account_info::AccountInfo,
accounts_hash::AccountHash,
append_vec::AppendVecStoredAccountMeta,
tiered_storage::hot::{HotAccount, HotAccountMeta},
},
solana_sdk::{account::ReadableAccount, hash::Hash, pubkey::Pubkey, stake_history::Epoch},
};
pub type StoredMetaWriteVersion = u64;
lazy_static! {
static ref DEFAULT_ACCOUNT_HASH: AccountHash = AccountHash(Hash::default());
}
#[derive(PartialEq, Eq, Debug)]
pub enum StoredAccountMeta<'storage> {
AppendVec(AppendVecStoredAccountMeta<'storage>),
Hot(HotAccount<'storage, HotAccountMeta>),
}
impl<'storage> StoredAccountMeta<'storage> {
pub fn pubkey(&self) -> &'storage Pubkey {
match self {
Self::AppendVec(av) => av.pubkey(),
Self::Hot(hot) => hot.address(),
}
}
pub fn hash(&self) -> &'storage AccountHash {
match self {
Self::AppendVec(av) => av.hash(),
Self::Hot(_) => &DEFAULT_ACCOUNT_HASH,
}
}
pub fn stored_size(&self) -> usize {
match self {
Self::AppendVec(av) => av.stored_size(),
Self::Hot(hot) => hot.stored_size(),
}
}
pub fn offset(&self) -> usize {
match self {
Self::AppendVec(av) => av.offset(),
Self::Hot(hot) => AccountInfo::reduced_offset_to_offset(hot.index().0),
}
}
pub fn data(&self) -> &'storage [u8] {
match self {
Self::AppendVec(av) => av.data(),
Self::Hot(hot) => hot.data(),
}
}
pub fn data_len(&self) -> usize {
match self {
Self::AppendVec(av) => av.data_len() as usize,
Self::Hot(hot) => hot.data().len(),
}
}
pub fn meta(&self) -> &StoredMeta {
match self {
Self::AppendVec(av) => av.meta(),
Self::Hot(_) => unreachable!(),
}
}
pub(crate) fn sanitize(&self) -> bool {
match self {
Self::AppendVec(av) => av.sanitize(),
Self::Hot(_) => unimplemented!(),
}
}
}
impl<'storage> ReadableAccount for StoredAccountMeta<'storage> {
fn lamports(&self) -> u64 {
match self {
Self::AppendVec(av) => av.lamports(),
Self::Hot(hot) => hot.lamports(),
}
}
fn data(&self) -> &[u8] {
match self {
Self::AppendVec(av) => av.data(),
Self::Hot(hot) => hot.data(),
}
}
fn owner(&self) -> &Pubkey {
match self {
Self::AppendVec(av) => av.owner(),
Self::Hot(hot) => hot.owner(),
}
}
fn executable(&self) -> bool {
match self {
Self::AppendVec(av) => av.executable(),
Self::Hot(hot) => hot.executable(),
}
}
fn rent_epoch(&self) -> Epoch {
match self {
Self::AppendVec(av) => av.rent_epoch(),
Self::Hot(hot) => hot.rent_epoch(),
}
}
}
#[derive(Clone, PartialEq, Eq, Debug)]
#[repr(C)]
pub struct StoredMeta {
pub write_version_obsolete: StoredMetaWriteVersion,
pub data_len: u64,
pub pubkey: Pubkey,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)]
#[repr(C)]
pub struct AccountMeta {
pub lamports: u64,
pub rent_epoch: Epoch,
pub owner: Pubkey,
pub executable: bool,
}
impl<'a, T: ReadableAccount> From<&'a T> for AccountMeta {
fn from(account: &'a T) -> Self {
Self {
lamports: account.lamports(),
owner: *account.owner(),
executable: account.executable(),
rent_epoch: account.rent_epoch(),
}
}
}
impl<'a, T: ReadableAccount> From<Option<&'a T>> for AccountMeta {
fn from(account: Option<&'a T>) -> Self {
match account {
Some(account) => AccountMeta::from(account),
None => AccountMeta::default(),
}
}
}