Skip to content

Commit

Permalink
Fix bug with saving the latest non voting transactions (helius-labs#199)
Browse files Browse the repository at this point in the history
* Nit

* Fix bug
  • Loading branch information
pmantica11 authored Sep 10, 2024
1 parent bf455ce commit 7b3e157
Show file tree
Hide file tree
Showing 3 changed files with 619 additions and 2,454 deletions.
3 changes: 2 additions & 1 deletion src/ingester/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub async fn persist_state_update(

let non_compression_transactions_to_keep = max(
0,
MAX_LATEST_NON_VOTING_SIGNATURES as i64 - non_compression_transactions.len() as i64,
MAX_LATEST_NON_VOTING_SIGNATURES as i64 - compression_transactions.len() as i64,
);
let transactions_to_persist = compression_transactions
.into_iter()
Expand All @@ -140,6 +140,7 @@ pub async fn persist_state_update(
.take(non_compression_transactions_to_keep as usize),
)
.collect_vec();

for chunk in transactions_to_persist.chunks(MAX_SQL_INSERTS) {
persist_transactions(txn, chunk).await?;
}
Expand Down
29 changes: 15 additions & 14 deletions tests/integration_tests/e2e_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use function_name::named;
use photon_indexer::api::method::get_compressed_accounts_by_owner::GetCompressedAccountsByOwnerRequest;
use photon_indexer::api::method::get_latest_non_voting_signatures::MAX_LATEST_NON_VOTING_SIGNATURES;
use photon_indexer::api::method::get_multiple_new_address_proofs::AddressList;
use photon_indexer::api::method::get_transaction_with_compression_info::get_transaction_helper;
use photon_indexer::api::method::get_validity_proof::CompressedProof;
Expand Down Expand Up @@ -85,10 +86,7 @@ async fn test_e2e_mint_and_transfer_transactions(
for tx in txs {
index_transaction(&setup, tx).await;
}
for (person, pubkey) in [
("bob", bob_pubkey),
("charles", charles_pubkey),
] {
for (person, pubkey) in [("bob", bob_pubkey), ("charles", charles_pubkey)] {
let accounts = setup
.api
.get_compressed_token_accounts_by_owner(GetCompressedTokenAccountsByOwner {
Expand Down Expand Up @@ -297,10 +295,7 @@ async fn test_lamport_transfers(
}
}
}
for (owner, owner_name) in [
(payer_pubkey, "payer"),
(receiver_pubkey, "receiver"),
] {
for (owner, owner_name) in [(payer_pubkey, "payer"), (receiver_pubkey, "receiver")] {
let accounts = setup
.api
.get_compressed_accounts_by_owner(GetCompressedAccountsByOwnerRequest {
Expand Down Expand Up @@ -336,9 +331,13 @@ async fn test_lamport_transfers(
newAddressesWithTrees: vec![],
})
.await
.unwrap_or_else(|_| panic!("Failed to get validity proof for owner with hash list len: {} {}",
owner_name,
hash_list.0.len()));
.unwrap_or_else(|_| {
panic!(
"Failed to get validity proof for owner with hash list len: {} {}",
owner_name,
hash_list.0.len()
)
});
// The Gnark prover has some randomness.
validity_proof.value.compressedProof = CompressedProof::default();

Expand Down Expand Up @@ -500,6 +499,8 @@ async fn test_get_latest_non_voting_signatures(
async fn test_get_latest_non_voting_signatures_with_failures(
#[values(DatabaseBackend::Sqlite, DatabaseBackend::Postgres)] db_backend: DatabaseBackend,
) {
use itertools::Itertools;

let name = trim_test_name(function_name!());
let setup = setup_with_options(
name.clone(),
Expand All @@ -521,9 +522,9 @@ async fn test_get_latest_non_voting_signatures_with_failures(
})
.await
.unwrap();
assert_json_snapshot!(
format!("{}-non-voting-transactions", name.clone()),
all_nonvoting_transactions
assert_eq!(
MAX_LATEST_NON_VOTING_SIGNATURES as usize,
all_nonvoting_transactions.value.items.len()
);
}

Expand Down
Loading

0 comments on commit 7b3e157

Please sign in to comment.