Changes after groovies comments
This commit is contained in:
parent
ff0163d05f
commit
ce3a4d47c3
|
@ -2,17 +2,20 @@ use dashmap::DashMap;
|
|||
use itertools::Itertools;
|
||||
use solana_address_lookup_table_program::state::AddressLookupTable;
|
||||
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
||||
use solana_sdk::{pubkey::Pubkey, slot_hashes::SlotHashes, slot_history::Slot, commitment_config::CommitmentConfig};
|
||||
use solana_sdk::{
|
||||
commitment_config::CommitmentConfig, pubkey::Pubkey, slot_hashes::SlotHashes,
|
||||
slot_history::Slot,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::block_info::TransactionAccount;
|
||||
|
||||
pub struct ATLStore {
|
||||
pub struct ALTStore {
|
||||
rpc_client: Arc<RpcClient>,
|
||||
pub map: Arc<DashMap<String, Vec<u8>>>,
|
||||
pub map: Arc<DashMap<Pubkey, Vec<u8>>>,
|
||||
}
|
||||
|
||||
impl ATLStore {
|
||||
impl ALTStore {
|
||||
pub fn new(rpc_client: Arc<RpcClient>) -> Self {
|
||||
Self {
|
||||
rpc_client,
|
||||
|
@ -20,35 +23,37 @@ impl ATLStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn load_atl_from_rpc(&self, atl: &Pubkey) {
|
||||
if !self.map.contains_key(&atl.to_string()) {
|
||||
self.reload_atl_from_rpc(&atl).await;
|
||||
pub async fn load_alt_from_rpc(&self, alt: &Pubkey) {
|
||||
if !self.map.contains_key(&alt) {
|
||||
self.reload_alt_from_rpc(&alt).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn reload_atl_from_rpc(&self, atl:&Pubkey) {
|
||||
let response = self.rpc_client.get_account_with_commitment(atl, CommitmentConfig::processed()).await;
|
||||
pub async fn reload_alt_from_rpc(&self, alt: &Pubkey) {
|
||||
let response = self
|
||||
.rpc_client
|
||||
.get_account_with_commitment(alt, CommitmentConfig::processed())
|
||||
.await;
|
||||
if let Ok(account_res) = response {
|
||||
if let Some(account) = account_res.value {
|
||||
self.map.insert(atl.to_string(), account.data);
|
||||
self.map.insert(*alt, account.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn load_accounts(
|
||||
&self,
|
||||
current_slot: Slot,
|
||||
atl: Pubkey,
|
||||
slot: Slot,
|
||||
alt: &Pubkey,
|
||||
write_accounts: &Vec<u8>,
|
||||
read_account: &Vec<u8>,
|
||||
) -> Option<Vec<TransactionAccount>> {
|
||||
match self.map.get(&atl.to_string()) {
|
||||
match self.map.get(&alt) {
|
||||
Some(account) => {
|
||||
let lookup_table = AddressLookupTable::deserialize(&account.value()).unwrap();
|
||||
let write_accounts = lookup_table
|
||||
.lookup(current_slot, write_accounts, &SlotHashes::default());
|
||||
let read_account = lookup_table
|
||||
.lookup(current_slot, read_account, &SlotHashes::default());
|
||||
let write_accounts =
|
||||
lookup_table.lookup(slot, write_accounts, &SlotHashes::default());
|
||||
let read_account = lookup_table.lookup(slot, read_account, &SlotHashes::default());
|
||||
|
||||
let write_accounts = if let Ok(write_accounts) = write_accounts {
|
||||
write_accounts
|
||||
|
@ -67,7 +72,7 @@ impl ATLStore {
|
|||
key: key.to_string(),
|
||||
is_writable: true,
|
||||
is_signer: false,
|
||||
is_atl: true,
|
||||
is_alt: true,
|
||||
})
|
||||
.collect_vec();
|
||||
let ra = read_account
|
||||
|
@ -76,37 +81,41 @@ impl ATLStore {
|
|||
key: key.to_string(),
|
||||
is_writable: false,
|
||||
is_signer: false,
|
||||
is_atl: true,
|
||||
is_alt: true,
|
||||
})
|
||||
.collect_vec();
|
||||
Some([wa, ra].concat())
|
||||
}
|
||||
None => {
|
||||
Some(vec![])
|
||||
}
|
||||
None => Some(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_accounts(
|
||||
&self,
|
||||
current_slot: Slot,
|
||||
atl: Pubkey,
|
||||
alt: &Pubkey,
|
||||
write_accounts: &Vec<u8>,
|
||||
read_account: &Vec<u8>,
|
||||
) -> Vec<TransactionAccount> {
|
||||
self.load_atl_from_rpc(&atl).await;
|
||||
match self.load_accounts(current_slot, atl, write_accounts, read_account).await {
|
||||
self.load_alt_from_rpc(&alt).await;
|
||||
match self
|
||||
.load_accounts(current_slot, alt, write_accounts, read_account)
|
||||
.await
|
||||
{
|
||||
Some(x) => x,
|
||||
None => {
|
||||
//load atl
|
||||
self.reload_atl_from_rpc(&atl).await;
|
||||
match self.load_accounts(current_slot, atl, write_accounts, read_account).await {
|
||||
//load alt
|
||||
self.reload_alt_from_rpc(&alt).await;
|
||||
match self
|
||||
.load_accounts(current_slot, alt, write_accounts, read_account)
|
||||
.await
|
||||
{
|
||||
Some(x) => x,
|
||||
None => {
|
||||
// reloading did not work
|
||||
log::error!("cannot load atl even after");
|
||||
log::error!("cannot load alt even after");
|
||||
vec![]
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ use solana_sdk::{
|
|||
};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use crate::atl_store::ATLStore;
|
||||
use crate::alt_store::ALTStore;
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct PrioFeeData {
|
||||
|
@ -84,7 +84,7 @@ pub struct TransactionAccount {
|
|||
pub key: String,
|
||||
pub is_writable: bool,
|
||||
pub is_signer: bool,
|
||||
pub is_atl: bool,
|
||||
pub is_alt: bool,
|
||||
}
|
||||
|
||||
pub struct BlockTransactionInfo {
|
||||
|
@ -113,7 +113,7 @@ pub struct BlockInfo {
|
|||
|
||||
impl BlockInfo {
|
||||
pub async fn process_versioned_message(
|
||||
atl_store: Arc<ATLStore>,
|
||||
atl_store: Arc<ALTStore>,
|
||||
signature: String,
|
||||
slot: Slot,
|
||||
message: &VersionedMessage,
|
||||
|
@ -182,7 +182,7 @@ impl BlockInfo {
|
|||
key: account.to_string(),
|
||||
is_writable: message.is_maybe_writable(index),
|
||||
is_signer: message.is_signer(index),
|
||||
is_atl: false,
|
||||
is_alt: false,
|
||||
})
|
||||
.collect_vec();
|
||||
if let Some(atl_messages) = message.address_table_lookups() {
|
||||
|
@ -191,7 +191,7 @@ impl BlockInfo {
|
|||
let mut atl_accs = atl_store
|
||||
.get_accounts(
|
||||
slot,
|
||||
atl_acc,
|
||||
&atl_acc,
|
||||
&atl_message.writable_indexes,
|
||||
&atl_message.readonly_indexes,
|
||||
)
|
||||
|
@ -303,7 +303,7 @@ impl BlockInfo {
|
|||
}
|
||||
|
||||
pub async fn new(
|
||||
atl_store: Arc<ATLStore>,
|
||||
atl_store: Arc<ALTStore>,
|
||||
block: &yellowstone_grpc_proto_original::prelude::SubscribeUpdateBlock,
|
||||
) -> BlockInfo {
|
||||
let block_hash = block.blockhash.clone();
|
||||
|
|
|
@ -17,7 +17,7 @@ use log::{debug, error, info};
|
|||
use prometheus::{opts, register_int_counter, register_int_gauge, IntCounter, IntGauge};
|
||||
use transaction_info::TransactionInfo;
|
||||
|
||||
mod atl_store;
|
||||
mod alt_store;
|
||||
mod block_info;
|
||||
mod cli;
|
||||
mod postgres;
|
||||
|
@ -159,7 +159,7 @@ async fn start_tracking_blocks(
|
|||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let atl_store = Arc::new(atl_store::ATLStore::new(rpc_client));
|
||||
let atl_store = Arc::new(alt_store::ALTStore::new(rpc_client));
|
||||
|
||||
loop {
|
||||
let mut blocks_subs = HashMap::new();
|
||||
|
@ -247,7 +247,7 @@ async fn start_tracking_blocks(
|
|||
if let Some(account) = account_update.account {
|
||||
let bytes: [u8; 32] = account.pubkey.try_into().unwrap_or(Pubkey::default().to_bytes());
|
||||
let pubkey = Pubkey::new_from_array(bytes);
|
||||
atl_store.map.insert( pubkey.to_string(), account.data);
|
||||
atl_store.map.insert( pubkey, account.data);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
|
|
@ -680,7 +680,7 @@ impl PostgresSession {
|
|||
key: acc.key.clone(),
|
||||
writable: acc.is_writable,
|
||||
is_signer: acc.is_signer,
|
||||
is_atl: acc.is_atl,
|
||||
is_atl: acc.is_alt,
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue