rename InmemoryTokenAccount to TokenProgramAccounts

This commit is contained in:
godmodegalactus 2024-07-11 11:17:01 +02:00
parent 3693f00d1e
commit f815147a2d
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
5 changed files with 36 additions and 10 deletions

View File

@ -22,13 +22,13 @@ use tokio::sync::Mutex;
lazy_static::lazy_static! {
static ref ACCOUNT_STORED_IN_MEMORY: IntGauge =
register_int_gauge!(opts!("literpc_accounts_in_memory", "Account InMemory")).unwrap();
register_int_gauge!(opts!("lite_accounts_accounts_in_memory", "Account InMemory")).unwrap();
static ref TOTAL_PROCESSED_ACCOUNTS: IntGauge =
register_int_gauge!(opts!("literpc_total_processed_accounts_in_memory", "Account processed accounts InMemory")).unwrap();
register_int_gauge!(opts!("lite_accounts_total_processed_accounts_in_memory", "Account processed accounts InMemory")).unwrap();
static ref SLOT_FOR_LATEST_ACCOUNT_UPDATE: IntGauge =
register_int_gauge!(opts!("literpc_slot_for_latest_account_update", "Slot of latest account update")).unwrap();
register_int_gauge!(opts!("lite_accounts_slot_for_latest_account_update", "Slot of latest account update")).unwrap();
}
struct SlotStatus {

View File

@ -9,6 +9,7 @@ use itertools::Itertools;
use lite_account_manager_common::{
account_store_interface::AccountLoadingError, pubkey_container_utils::PartialPubkey,
};
use prometheus::{opts, register_int_gauge, IntGauge};
use solana_sdk::pubkey::Pubkey;
use tokio::sync::RwLock;
@ -17,6 +18,14 @@ use crate::{
token_account_storage_interface::TokenAccountStorageInterface,
};
lazy_static::lazy_static! {
static ref TOKEN_ACCOUNT_STORED_IN_MEMORY: IntGauge =
register_int_gauge!(opts!("lite_account_token_accounts_in_memory", "Account InMemory")).unwrap();
static ref TOKEN_ACCOUNT_DELETED_IN_MEMORY: IntGauge =
register_int_gauge!(opts!("lite_account_token_accounts_deleted_in_memory", "Account InMemory")).unwrap();
}
const PARTIAL_PUBKEY_SIZE: usize = 8;
type InmemoryPubkey = PartialPubkey<PARTIAL_PUBKEY_SIZE>;
@ -72,6 +81,7 @@ impl TokenAccountStorageInterface for InmemoryTokenAccountStorage {
let token_index = write_lk.len() as TokenAccountIndex;
write_lk.push_back(token_account.to_bytes());
token_indexes.push(token_index);
TOKEN_ACCOUNT_STORED_IN_MEMORY.inc();
(token_index as TokenAccountIndex, false)
}
dashmap::mapref::entry::Entry::Vacant(v) => {
@ -81,6 +91,7 @@ impl TokenAccountStorageInterface for InmemoryTokenAccountStorage {
write_lk.push_back(token_account.to_bytes());
v.insert(vec![token_index as TokenAccountIndex]);
drop(write_lk);
TOKEN_ACCOUNT_STORED_IN_MEMORY.inc();
(token_index, true)
}
}
@ -137,6 +148,7 @@ impl TokenAccountStorageInterface for InmemoryTokenAccountStorage {
for index in indexes {
let binary = write_lk.get_mut(index as usize).unwrap();
if TokenAccount::get_pubkey_from_binary(binary) == *pubkey {
TOKEN_ACCOUNT_DELETED_IN_MEMORY.inc();
*binary = deleted_account;
return;
}

View File

@ -17,6 +17,7 @@ use lite_account_manager_common::{
pubkey_container_utils::PartialPubkey,
slot_info::SlotInfo,
};
use prometheus::{opts, register_int_gauge, IntGauge};
use serde::{Deserialize, Serialize};
use solana_sdk::{clock::Slot, pubkey::Pubkey};
use tokio::sync::RwLock;
@ -32,6 +33,14 @@ use crate::{
},
};
lazy_static::lazy_static! {
static ref TOKEN_PROGRAM_TOTAL_PROCESSED_ACCOUNTS: IntGauge =
register_int_gauge!(opts!("lite_accounts_token_processed_accounts_in_memory", "Account processed accounts InMemory")).unwrap();
static ref TOKEN_MINTS_IN_MEMORY: IntGauge =
register_int_gauge!(opts!("lite_accounts_token_mints_in_memory", "Slot of latest account update")).unwrap();
}
const PARTIAL_PUBKEY_SIZE: usize = 6;
type InmemoryPubkey = PartialPubkey<PARTIAL_PUBKEY_SIZE>;
#[derive(Clone)]
@ -81,6 +90,7 @@ impl ProcessedAccountStore {
}
None => {
log::debug!("Adding a new account {account_pk:?} to slot {slot}");
TOKEN_PROGRAM_TOTAL_PROCESSED_ACCOUNTS.inc();
processed_account_by_slot.processed_accounts.insert(
account_pk,
ProcessedAccount {
@ -94,6 +104,7 @@ impl ProcessedAccountStore {
}
None => {
log::debug!("Adding a new slot {slot} with new account {account_pk:?}");
TOKEN_PROGRAM_TOTAL_PROCESSED_ACCOUNTS.inc();
let mut processed_accounts = HashMap::new();
processed_accounts.insert(
account_pk,
@ -177,6 +188,7 @@ impl ProcessedAccountStore {
std::collections::btree_map::Entry::Occupied(mut occ) => {
let value = occ.get_mut();
for (pk, acc) in value.processed_accounts.drain() {
TOKEN_PROGRAM_TOTAL_PROCESSED_ACCOUNTS.dec();
// as we are going from most recent slot to least recent slot
// if the key already exists then we do not insert in the map
match map_of_accounts.entry(pk) {
@ -292,7 +304,7 @@ impl ProcessedAccountStore {
}
}
pub struct InMemoryTokenStorage {
pub struct TokenProgramAccountsStorage {
mints_by_index: Arc<DashMap<MintIndex, MintAccount>>,
mints_index_by_pubkey: Arc<DashMap<Pubkey, MintIndex>>,
multisigs: Arc<DashMap<Pubkey, MultiSig>>,
@ -305,7 +317,7 @@ pub struct InMemoryTokenStorage {
mint_counter: Arc<AtomicU32>,
}
impl InMemoryTokenStorage {
impl TokenProgramAccountsStorage {
#[allow(clippy::new_without_default)]
pub fn new(token_accounts_storage: Arc<dyn TokenAccountStorageInterface>) -> Self {
Self {
@ -366,6 +378,7 @@ impl InMemoryTokenStorage {
self.mints_by_index.insert(*occ.get(), mint_data);
}
dashmap::mapref::entry::Entry::Vacant(v) => {
TOKEN_MINTS_IN_MEMORY.inc();
let index = self
.mint_counter
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@ -379,6 +392,7 @@ impl InMemoryTokenStorage {
}
TokenProgramAccountType::Deleted(account_pk) => {
if let Some((_, index)) = self.mints_index_by_pubkey.remove(&account_pk) {
TOKEN_MINTS_IN_MEMORY.dec();
self.mints_by_index.remove(&index);
self.accounts_index_by_mint.remove(&index);
} else if self.mints_index_by_pubkey.remove(&account_pk).is_some() {
@ -544,7 +558,7 @@ struct TokenProgramSnapshot {
}
#[async_trait]
impl AccountStorageInterface for InMemoryTokenStorage {
impl AccountStorageInterface for TokenProgramAccountsStorage {
async fn update_account(&self, account_data: AccountData, commitment: Commitment) -> bool {
if !self.is_token_program_account(&account_data).await {
return false;

View File

@ -2,7 +2,7 @@ use std::sync::Arc;
use lite_token_account_storage::{
inmemory_token_account_storage::InmemoryTokenAccountStorage,
inmemory_token_storage::InMemoryTokenStorage,
inmemory_token_storage::TokenProgramAccountsStorage,
};
use solana_sdk::pubkey::Pubkey;
mod utils;
@ -16,7 +16,7 @@ use lite_account_manager_common::{
#[tokio::test]
pub async fn test_gpa_token_account() {
let inmemory_token_storage = Arc::new(InmemoryTokenAccountStorage::default());
let token_store = InMemoryTokenStorage::new(inmemory_token_storage);
let token_store = TokenProgramAccountsStorage::new(inmemory_token_storage);
let mint_1: Pubkey = Pubkey::new_unique();
let mint_creation_params = utils::MintCreationParams::create_default(100);

View File

@ -8,7 +8,7 @@ use lite_account_manager_common::{
};
use lite_token_account_storage::{
inmemory_token_account_storage::InmemoryTokenAccountStorage,
inmemory_token_storage::InMemoryTokenStorage,
inmemory_token_storage::TokenProgramAccountsStorage,
};
use solana_sdk::pubkey::Pubkey;
@ -18,7 +18,7 @@ mod utils;
pub async fn test_saving_and_loading_token_account() {
tracing_subscriber::fmt::init();
let inmemory_token_storage = Arc::new(InmemoryTokenAccountStorage::default());
let token_store = InMemoryTokenStorage::new(inmemory_token_storage);
let token_store = TokenProgramAccountsStorage::new(inmemory_token_storage);
let mint: Pubkey = Pubkey::new_unique();
let mint_creation_params = utils::MintCreationParams::create_default(100);