Skip to content

Commit

Permalink
tracing nf queue issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed May 9, 2024
1 parent 04edd36 commit f8e437a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ node_modules
light-zk.js
/cli/.crates2.json
/cli/.crates.toml
test-programs/rnd-inf-test/**/*.txt
11 changes: 11 additions & 0 deletions merkle-tree/hash-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ where
}
unsafe {
*next_value_index = usize::from_ne_bytes(bytes[24..32].try_into().unwrap());

#[cfg(target_os = "solana")]
solana_program::msg!("next_value_index: {}", *next_value_index);
#[cfg(not(target_os = "solana"))]
println!("next_value_index: {}", *next_value_index);
}

let indices_layout = Layout::array::<Option<I>>(capacity_indices).unwrap();
Expand Down Expand Up @@ -434,7 +439,13 @@ where
value: &BigUint,
current_sequence_number: usize,
) -> Result<(), HashSetError> {
#[cfg(target_os = "solana")]
solana_program::msg!("hashset next_value_index {:?}", unsafe {
*self.next_value_index
});
for i in 0..self.capacity_values {
#[cfg(target_os = "solana")]
solana_program::msg!("hashset insert; {}", i);
let probe_index = (value.clone() + i.to_biguint().unwrap() * i.to_biguint().unwrap())
% self.capacity_values.to_biguint().unwrap();
let probe_index = probe_index.to_usize().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
RegisteredProgram, StateMerkleTreeAccount,
};
use anchor_lang::{prelude::*, solana_program::pubkey::Pubkey};
use light_heap::BumpAllocator;
use num_bigint::BigUint;

#[derive(Accounts)]
Expand Down Expand Up @@ -96,11 +97,15 @@ pub fn process_insert_into_nullifier_queues<'a, 'b, 'c: 'info, 'info>(
light_heap::bench_sbf_end!("acp_prep_insertion");
light_heap::bench_sbf_start!("acp_insert_nf_into_queue");
for element in queue_bundle.elements.iter() {
#[cfg(target_os = "solana")]
let pos = light_heap::GLOBAL_ALLOCATOR.get_heap_pos();
let element = BigUint::from_bytes_be(element.as_slice());
msg!("Inserting element {:?} into nullifier queue", element);
indexed_array
.insert(&element, sequence_number)
.map_err(ProgramError::from)?;
#[cfg(target_os = "solana")]
light_heap::GLOBAL_ALLOCATOR.free_heap(pos);
}
light_heap::bench_sbf_end!("acp_insert_nf_into_queue");
}
Expand Down
6 changes: 3 additions & 3 deletions test-programs/rnd-inf-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn test_10() {
let mut env = InfTestEnv::new(
KeypairActionConfig::spl_default(),
Default::default(),
100,
10000,
None,
)
.await;
Expand Down Expand Up @@ -529,8 +529,8 @@ pub struct GeneralActionConfig {
impl Default for GeneralActionConfig {
fn default() -> Self {
Self {
add_keypair: Some(0.3),
create_state_mt: Some(0.1),
add_keypair: Some(0.0),
create_state_mt: Some(0.0),
create_address_mt: Some(0.1),
}
}
Expand Down
30 changes: 25 additions & 5 deletions test-utils/src/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
use std::{thread, time::Duration};

use crate::{
create_account_instruction, create_and_send_transaction, test_env::EnvAccounts, AccountZeroCopy,
create_account_instruction, create_and_send_transaction, get_hash_set, test_env::EnvAccounts,
AccountZeroCopy,
};
use account_compression::{
initialize_nullifier_queue::NullifierQueueAccount,
utils::constants::{STATE_MERKLE_TREE_CANOPY_DEPTH, STATE_MERKLE_TREE_HEIGHT},
AddressMerkleTreeAccount, StateMerkleTreeAccount,
};
Expand Down Expand Up @@ -366,16 +368,34 @@ impl TestIndexer {
let merkle_tree_account =
AccountZeroCopy::<StateMerkleTreeAccount>::new(context, merkle_tree_pubkeys[i])
.await;
let fetched_merkle_tree = merkle_tree_account
.deserialized()
.copy_merkle_tree()
.unwrap();
let fetched_merkle_tree_account = merkle_tree_account.deserialized();
let fetched_merkle_tree = fetched_merkle_tree_account.copy_merkle_tree().unwrap();
assert_eq!(
merkle_tree.root(),
fetched_merkle_tree.root().unwrap(),
"Merkle tree root mismatch"
);
root_indices.push(fetched_merkle_tree.current_root_index as u16);
println!("root_indices {:?}", root_indices);
println!(
"fetched_merkle_tree changelog_index {:?}",
fetched_merkle_tree.changelog_index()
);
println!(
"fetched_merkle_tree current_root_index {:?}",
fetched_merkle_tree.current_root_index
);
let nullifier_queue = unsafe {
get_hash_set::<
u16,
account_compression::initialize_nullifier_queue::NullifierQueueAccount,
>(context, fetched_merkle_tree_account.associated_queue)
.await
};
println!(
"nullifier_queue_account {:?}",
nullifier_queue.next_value_index
);
}

let inclusion_proof_inputs = InclusionProofInputs(inclusion_proofs.as_slice());
Expand Down

0 comments on commit f8e437a

Please sign in to comment.