Avoiding setting compression type for empty accounts

This commit is contained in:
godmodegalactus 2024-07-15 16:41:53 +02:00
parent 4f02f0a966
commit 5850536fc8
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
4 changed files with 23 additions and 10 deletions

1
Cargo.lock generated
View File

@ -1874,6 +1874,7 @@ dependencies = [
"base64 0.21.7",
"bs58",
"itertools",
"log",
"lz4",
"serde",
"serde_json",

View File

@ -220,11 +220,11 @@ impl AccountStorageInterface for InmemoryAccountStore {
) -> Result<Option<AccountData>, AccountLoadingError> {
match self.account_store.entry(account_pk) {
dashmap::mapref::entry::Entry::Occupied(occ) => {
let acc = occ.get();
let acc = acc.get_account_data(commitment);
if let Some(account) = &acc {
if account.account.lamports > 0 {
Ok(acc)
let account = occ.get().get_account_data(commitment);
drop(occ);
if let Some(account_data) = &account {
if account_data.account.lamports > 0 {
Ok(account)
} else {
Ok(None)
}
@ -256,9 +256,10 @@ impl AccountStorageInterface for InmemoryAccountStore {
match self.accounts_by_owner.entry(program_pubkey) {
dashmap::mapref::entry::Entry::Occupied(occ) => {
let mut return_vec = vec![];
for program_account in occ.get().iter() {
let account_data = self.get_account(*program_account, commitment).await;
if let Ok(Some(account_data)) = account_data {
let program_pubkeys = occ.get();
for program_account in program_pubkeys.iter() {
let account_data = self.get_account(*program_account, commitment).await?;
if let Some(account_data) = account_data {
// recheck program owner and filters
if account_data.account.owner.eq(&program_pubkey) {
match &account_filters {

View File

@ -15,4 +15,5 @@ serde = {workspace = true}
serde_json = {workspace = true}
bs58 = {workspace = true}
base64 = {workspace = true}
anyhow = {workspace = true}
anyhow = {workspace = true}
log = {workspace = true}

View File

@ -45,7 +45,17 @@ impl Data {
pub fn data(&self) -> Vec<u8> {
match self {
Data::Uncompressed(d) => d.clone(),
Data::Lz4 { binary, .. } => lz4::block::decompress(binary, None).unwrap(),
Data::Lz4 { binary, len } => match lz4::block::decompress(binary, None) {
Ok(res) => res,
Err(e) => {
log::error!(
"error {e:?} decompressing data of size {}, data_size_set: {}",
binary.len(),
len
);
panic!()
}
},
Data::Zstd { binary, .. } => zstd::bulk::decompress(binary, MAX_ACCOUNT_SIZE).unwrap(),
}
}