2021-12-13 15:35:07 -08:00
|
|
|
use crate::{
|
|
|
|
accounts_db::{AppendVecId, CACHE_VIRTUAL_OFFSET, CACHE_VIRTUAL_STORAGE_ID},
|
|
|
|
accounts_index::{IsCached, ZeroLamport},
|
|
|
|
};
|
|
|
|
|
|
|
|
/// offset within an append vec to account data
|
|
|
|
pub type Offset = usize;
|
|
|
|
|
|
|
|
/// specify where account data is located
|
|
|
|
pub enum StorageLocation {
|
|
|
|
AppendVec(AppendVecId, Offset),
|
|
|
|
Cached,
|
|
|
|
}
|
2021-12-11 09:47:05 -08:00
|
|
|
|
|
|
|
#[derive(Default, Debug, PartialEq, Clone, Copy)]
|
|
|
|
pub struct AccountInfo {
|
|
|
|
/// index identifying the append storage
|
2021-12-13 19:35:30 -08:00
|
|
|
store_id: AppendVecId,
|
2021-12-11 09:47:05 -08:00
|
|
|
|
|
|
|
/// offset into the storage
|
2021-12-13 15:35:07 -08:00
|
|
|
offset: Offset,
|
2021-12-11 09:47:05 -08:00
|
|
|
|
|
|
|
/// needed to track shrink candidacy in bytes. Used to update the number
|
|
|
|
/// of alive bytes in an AppendVec as newer slots purge outdated entries
|
2021-12-13 08:10:06 -08:00
|
|
|
stored_size: usize,
|
2021-12-11 09:47:05 -08:00
|
|
|
|
|
|
|
/// lamports in the account used when squashing kept for optimization
|
|
|
|
/// purposes to remove accounts with zero balance.
|
2021-12-13 08:59:33 -08:00
|
|
|
lamports: u64,
|
2021-12-11 09:47:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ZeroLamport for AccountInfo {
|
|
|
|
fn is_zero_lamport(&self) -> bool {
|
|
|
|
self.lamports == 0
|
|
|
|
}
|
|
|
|
}
|
2021-12-12 12:36:05 -08:00
|
|
|
|
2021-12-13 15:35:07 -08:00
|
|
|
impl IsCached for AccountInfo {
|
|
|
|
fn is_cached(&self) -> bool {
|
|
|
|
self.store_id == CACHE_VIRTUAL_STORAGE_ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 12:36:05 -08:00
|
|
|
impl AccountInfo {
|
2021-12-13 15:35:07 -08:00
|
|
|
pub fn new(storage_location: StorageLocation, stored_size: usize, lamports: u64) -> Self {
|
|
|
|
let (store_id, offset) = match storage_location {
|
|
|
|
StorageLocation::AppendVec(store_id, offset) => (store_id, offset),
|
|
|
|
StorageLocation::Cached => (CACHE_VIRTUAL_STORAGE_ID, CACHE_VIRTUAL_OFFSET),
|
|
|
|
};
|
2021-12-12 12:36:05 -08:00
|
|
|
Self {
|
|
|
|
store_id,
|
|
|
|
offset,
|
|
|
|
stored_size,
|
|
|
|
lamports,
|
|
|
|
}
|
|
|
|
}
|
2021-12-13 08:10:06 -08:00
|
|
|
|
2021-12-13 19:35:30 -08:00
|
|
|
pub fn store_id(&self) -> usize {
|
|
|
|
self.store_id
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:43:26 -08:00
|
|
|
pub fn offset(&self) -> usize {
|
|
|
|
self.offset
|
|
|
|
}
|
|
|
|
|
2021-12-13 08:10:06 -08:00
|
|
|
pub fn stored_size(&self) -> usize {
|
|
|
|
self.stored_size
|
|
|
|
}
|
2021-12-12 12:36:05 -08:00
|
|
|
}
|