From 674c6894fe1b3936fbb2d955a1fc288ec34fc7e9 Mon Sep 17 00:00:00 2001 From: ananas-block Date: Thu, 23 Jan 2025 03:33:09 +0000 Subject: [PATCH] chore: rename hash_chain_store -> hash_chain_stores, small renamings and fixes --- forester-utils/src/instructions.rs | 6 +- program-libs/batched-merkle-tree/src/batch.rs | 8 +-- .../src/initialize_state_tree.rs | 2 +- .../batched-merkle-tree/src/merkle_tree.rs | 12 ++-- program-libs/batched-merkle-tree/src/queue.rs | 20 +++--- .../batched-merkle-tree/tests/merkle_tree.rs | 62 +++++++++---------- .../program-test/src/test_batch_forester.rs | 6 +- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/forester-utils/src/instructions.rs b/forester-utils/src/instructions.rs index ddb4ffec0..4f939c0f7 100644 --- a/forester-utils/src/instructions.rs +++ b/forester-utils/src/instructions.rs @@ -67,7 +67,7 @@ where let batch = &merkle_tree.queue_metadata.batches[full_batch_index as usize]; let zkp_batch_index = batch.get_num_inserted_zkps(); let leaves_hashchain = - merkle_tree.hashchain_store[full_batch_index as usize][zkp_batch_index as usize]; + merkle_tree.hashchain_stores[full_batch_index as usize][zkp_batch_index as usize]; let start_index = merkle_tree.next_index; let current_root = *merkle_tree.root_history.last().unwrap(); let batch_size = batch.zkp_batch_size as usize; @@ -235,7 +235,7 @@ pub async fn create_append_batch_ix_data>( output_queue.batch_metadata.batches[full_batch_index as usize].get_num_inserted_zkps(); let leaves_hashchain = - output_queue.hashchain_store[full_batch_index as usize][num_inserted_zkps as usize]; + output_queue.hashchain_stores[full_batch_index as usize][num_inserted_zkps as usize]; ( zkp_batch_size, @@ -343,7 +343,7 @@ pub async fn create_nullify_batch_ix_data>( let zkp_size = merkle_tree.queue_metadata.zkp_batch_size; let batch = &merkle_tree.queue_metadata.batches[batch_idx]; let zkp_idx = batch.get_num_inserted_zkps(); - let hashchain = merkle_tree.hashchain_store[batch_idx][zkp_idx as usize]; + let hashchain = merkle_tree.hashchain_stores[batch_idx][zkp_idx as usize]; let root = *merkle_tree.root_history.last().unwrap(); (zkp_size, root, hashchain) }; diff --git a/program-libs/batched-merkle-tree/src/batch.rs b/program-libs/batched-merkle-tree/src/batch.rs index ed5d190e5..819827862 100644 --- a/program-libs/batched-merkle-tree/src/batch.rs +++ b/program-libs/batched-merkle-tree/src/batch.rs @@ -379,8 +379,8 @@ impl Batch { // 2. increments the number of inserted zkps. self.num_inserted_zkps += 1; // 3. If all zkps are inserted, sets the state to inserted. - let batch_is_completly_inserted = self.num_inserted_zkps == num_zkp_batches; - if batch_is_completly_inserted { + let batch_is_completely_inserted = self.num_inserted_zkps == num_zkp_batches; + if batch_is_completely_inserted { self.advance_state_to_inserted()?; // Saving sequence number and root index for the batch. // When the batch is cleared check that sequence number is greater or equal than self.sequence_number @@ -895,7 +895,7 @@ mod tests { } // Moved BatchedQueueAccount test to this file - // to modify privated Batch variables for assertions. + // to modify private Batch variables for assertions. #[test] fn test_get_num_inserted() { let mut account_data = vec![0u8; 920]; @@ -1006,7 +1006,7 @@ mod tests { assert_eq!(account.value_vecs[0].as_slice(), [[1u8; 32]].as_slice()); assert_eq!(account.value_vecs[1].as_slice(), ref_value_array.as_slice()); assert_eq!( - account.hashchain_store[0].as_slice(), + account.hashchain_stores[0].as_slice(), [[1u8; 32]].as_slice() ); assert_eq!( diff --git a/program-libs/batched-merkle-tree/src/initialize_state_tree.rs b/program-libs/batched-merkle-tree/src/initialize_state_tree.rs index 28dc9d4e4..be375d273 100644 --- a/program-libs/batched-merkle-tree/src/initialize_state_tree.rs +++ b/program-libs/batched-merkle-tree/src/initialize_state_tree.rs @@ -353,7 +353,7 @@ fn _assert_mt_zero_copy_inited( ); } assert_eq!( - account.hashchain_store[0].capacity(), + account.hashchain_stores[0].capacity(), ref_account.queue_metadata.get_num_zkp_batches() as usize, "hashchain_store mismatch" ); diff --git a/program-libs/batched-merkle-tree/src/merkle_tree.rs b/program-libs/batched-merkle-tree/src/merkle_tree.rs index a9c2dbe0e..65c1c0211 100644 --- a/program-libs/batched-merkle-tree/src/merkle_tree.rs +++ b/program-libs/batched-merkle-tree/src/merkle_tree.rs @@ -82,7 +82,7 @@ pub struct BatchedMerkleTreeAccount<'a> { metadata: Ref<&'a mut [u8], BatchedMerkleTreeMetadata>, pub root_history: ZeroCopyCyclicVecU64<'a, [u8; 32]>, pub bloom_filter_stores: [&'a mut [u8]; 2], - pub hashchain_store: [ZeroCopyVecU64<'a, [u8; 32]>; 2], + pub hashchain_stores: [ZeroCopyVecU64<'a, [u8; 32]>; 2], } impl Discriminator for BatchedMerkleTreeAccount<'_> { @@ -202,7 +202,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> { metadata, root_history, bloom_filter_stores, - hashchain_store: [vec_1, vec_2], + hashchain_stores: [vec_1, vec_2], }) } @@ -298,7 +298,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> { metadata: account_metadata, root_history, bloom_filter_stores, - hashchain_store: [vec_1, vec_2], + hashchain_stores: [vec_1, vec_2], }) } @@ -355,7 +355,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> { // 1. Create public inputs hash. let public_input_hash = { let leaves_hashchain = - queue_account.hashchain_store[full_batch_index][num_zkps as usize]; + queue_account.hashchain_stores[full_batch_index][num_zkps as usize]; let old_root = self .root_history .last() @@ -458,7 +458,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> { // 1. Create public inputs hash. let public_input_hash = { - let leaves_hashchain = self.hashchain_store[full_batch_index][num_zkps as usize]; + let leaves_hashchain = self.hashchain_stores[full_batch_index][num_zkps as usize]; let old_root = self .root_history .last() @@ -631,7 +631,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> { &mut self.metadata.queue_metadata, &mut [], &mut self.bloom_filter_stores, - &mut self.hashchain_store, + &mut self.hashchain_stores, leaves_hash_value, Some(bloom_filter_value), None, diff --git a/program-libs/batched-merkle-tree/src/queue.rs b/program-libs/batched-merkle-tree/src/queue.rs index 2a944281b..eb4b0a24c 100644 --- a/program-libs/batched-merkle-tree/src/queue.rs +++ b/program-libs/batched-merkle-tree/src/queue.rs @@ -120,7 +120,7 @@ impl BatchedQueueMetadata { pub struct BatchedQueueAccount<'a> { metadata: Ref<&'a mut [u8], BatchedQueueMetadata>, pub value_vecs: [ZeroCopyVecU64<'a, [u8; 32]>; 2], - pub hashchain_store: [ZeroCopyVecU64<'a, [u8; 32]>; 2], + pub hashchain_stores: [ZeroCopyVecU64<'a, [u8; 32]>; 2], } impl Discriminator for BatchedQueueAccount<'_> { @@ -190,7 +190,7 @@ impl<'a> BatchedQueueAccount<'a> { Ok(BatchedQueueAccount { metadata, value_vecs: [value_vec1, value_vec2], - hashchain_store: [hashchain_store1, hashchain_store2], + hashchain_stores: [hashchain_store1, hashchain_store2], }) } @@ -244,7 +244,7 @@ impl<'a> BatchedQueueAccount<'a> { Ok(BatchedQueueAccount { metadata: account_metadata, value_vecs: [value_vecs_1, value_vecs_2], - hashchain_store: [vec_1, vec_2], + hashchain_stores: [vec_1, vec_2], }) } @@ -263,7 +263,7 @@ impl<'a> BatchedQueueAccount<'a> { &mut self.metadata.batch_metadata, &mut self.value_vecs, &mut [], - &mut self.hashchain_store, + &mut self.hashchain_stores, hash_chain_value, None, Some(current_index), @@ -419,7 +419,7 @@ pub(crate) fn insert_into_current_batch( batch_metadata: &mut BatchMetadata, value_vecs: &mut [ZeroCopyVecU64<[u8; 32]>], bloom_filter_stores: &mut [&mut [u8]], - hashchain_store: &mut [ZeroCopyVecU64<[u8; 32]>], + hashchain_stores: &mut [ZeroCopyVecU64<[u8; 32]>], hash_chain_value: &[u8; 32], bloom_filter_value: Option<&[u8; 32]>, current_index: Option, @@ -428,7 +428,7 @@ pub(crate) fn insert_into_current_batch( let mut sequence_number = None; let batch_index = batch_metadata.currently_processing_batch_index as usize; let mut value_store = value_vecs.get_mut(batch_index); - let mut hashchain_store = hashchain_store.get_mut(batch_index); + let mut hashchain_stores = hashchain_stores.get_mut(batch_index); let current_batch = batch_metadata.get_current_batch_mut(); // 1. Check that the current batch is ready. // 1.1. If the current batch is inserted, clear the batch. @@ -455,8 +455,8 @@ pub(crate) fn insert_into_current_batch( if let Some(value_store) = value_store.as_mut() { (*value_store).clear(); } - if let Some(hashchain_store) = hashchain_store.as_mut() { - (*hashchain_store).clear(); + if let Some(hashchain_stores) = hashchain_stores.as_mut() { + (*hashchain_stores).clear(); } // Advance the state to fill and reset the number of inserted elements. // If Some(current_index) set it as start index. @@ -478,13 +478,13 @@ pub(crate) fn insert_into_current_batch( bloom_filter_value.unwrap(), hash_chain_value, bloom_filter_stores, - hashchain_store.as_mut().unwrap(), + hashchain_stores.as_mut().unwrap(), batch_index, ), QueueType::BatchedOutput => current_batch.store_and_hash_value( hash_chain_value, value_store.unwrap(), - hashchain_store.unwrap(), + hashchain_stores.unwrap(), ), _ => Err(MerkleTreeMetadataError::InvalidQueueType.into()), }?; diff --git a/program-libs/batched-merkle-tree/tests/merkle_tree.rs b/program-libs/batched-merkle-tree/tests/merkle_tree.rs index 9daf5bbf2..45737530c 100644 --- a/program-libs/batched-merkle-tree/tests/merkle_tree.rs +++ b/program-libs/batched-merkle-tree/tests/merkle_tree.rs @@ -46,7 +46,7 @@ pub fn assert_nullifier_queue_insert( pre_account: BatchedMerkleTreeMetadata, pre_value_vecs: &mut [ZeroCopyVecU64<[u8; 32]>], pre_roots: Vec<[u8; 32]>, - pre_hashchains: [ZeroCopyVecU64<[u8; 32]>; 2], + pre_hash_chains: [ZeroCopyVecU64<[u8; 32]>; 2], merkle_tree_account: BatchedMerkleTreeAccount, bloom_filter_insert_values: Vec<[u8; 32]>, leaf_indices: Vec, @@ -65,7 +65,7 @@ pub fn assert_nullifier_queue_insert( pre_account, pre_value_vecs, pre_roots, - pre_hashchains, + pre_hash_chains, merkle_tree_account, bloom_filter_insert_values, leaf_hashchain_insert_values, @@ -81,7 +81,7 @@ pub fn assert_input_queue_insert( mut pre_account: BatchedMerkleTreeMetadata, pre_value_vecs: &mut [ZeroCopyVecU64<[u8; 32]>], pre_roots: Vec<[u8; 32]>, - mut pre_hashchains: [ZeroCopyVecU64<[u8; 32]>; 2], + mut pre_hash_chains: [ZeroCopyVecU64<[u8; 32]>; 2], mut merkle_tree_account: BatchedMerkleTreeAccount, bloom_filter_insert_values: Vec<[u8; 32]>, leaf_hashchain_insert_values: Vec<[u8; 32]>, @@ -160,7 +160,7 @@ pub fn assert_input_queue_insert( ); if expected_batch.get_state() == BatchState::Inserted { println!("assert input queue batch update: clearing batch"); - pre_hashchains[inserted_batch_index].clear(); + pre_hash_chains[inserted_batch_index].clear(); expected_batch.advance_state_to_fill(None).unwrap(); } println!( @@ -179,7 +179,7 @@ pub fn assert_input_queue_insert( insert_value ); assert!(bloom_filter.contains(insert_value)); - let pre_hashchain = pre_hashchains.get_mut(inserted_batch_index).unwrap(); + let pre_hashchain = pre_hash_chains.get_mut(inserted_batch_index).unwrap(); expected_batch.add_to_hash_chain(&leaf_hashchain_insert_values[i], pre_hashchain)?; let num_iters = @@ -218,7 +218,7 @@ pub fn assert_input_queue_insert( *expected_batch ); assert_eq!( - merkle_tree_account.hashchain_store[inserted_batch_index] + merkle_tree_account.hashchain_stores[inserted_batch_index] .last() .unwrap(), pre_hashchain.last().unwrap(), @@ -247,7 +247,7 @@ pub fn assert_input_queue_insert( pre_account.queue_metadata.batches[other_batch] ); assert_eq!( - merkle_tree_account.hashchain_store, pre_hashchains, + merkle_tree_account.hashchain_stores, pre_hash_chains, "Hashchain store inconsistent." ); Ok(()) @@ -261,7 +261,7 @@ pub fn assert_output_queue_insert( mut pre_account: BatchedQueueMetadata, // mut pre_batches: Vec, mut pre_value_store: [ZeroCopyVecU64<[u8; 32]>; 2], - mut pre_hashchains: [ZeroCopyVecU64<[u8; 32]>; 2], + mut pre_hash_chains: [ZeroCopyVecU64<[u8; 32]>; 2], mut output_account: BatchedQueueAccount, insert_values: Vec<[u8; 32]>, ) -> Result<(), BatchedMerkleTreeError> { @@ -280,7 +280,7 @@ pub fn assert_output_queue_insert( pre_account.batch_metadata.currently_processing_batch_index as usize; let expected_batch = &mut pre_account.batch_metadata.batches[inserted_batch_index]; let pre_value_store = pre_value_store.get_mut(inserted_batch_index).unwrap(); - let pre_hashchain = pre_hashchains.get_mut(inserted_batch_index).unwrap(); + let pre_hashchain = pre_hash_chains.get_mut(inserted_batch_index).unwrap(); if expected_batch.get_state() == BatchState::Inserted { expected_batch .advance_state_to_fill(Some(pre_account.batch_metadata.next_index)) @@ -321,7 +321,7 @@ pub fn assert_output_queue_insert( pre_account, "BatchedQueueAccount changed." ); - assert_eq!(pre_hashchains, output_account.hashchain_store); + assert_eq!(pre_hash_chains, output_account.hashchain_stores); for (i, (value_store, pre)) in output_account .value_vecs .iter() @@ -567,7 +567,7 @@ async fn test_simulate_transactions() { BatchedQueueAccount::output_from_bytes(&mut pre_account_bytes).unwrap(); let pre_output_metadata = *pre_output_account.get_metadata(); let mut pre_output_value_stores = pre_output_account.value_vecs; - let pre_output_hashchains = pre_output_account.hashchain_store; + let pre_output_hashchains = pre_output_account.hashchain_stores; let mut pre_mt_account_bytes = mt_account_data.clone(); let pre_merkle_tree_account = @@ -578,7 +578,7 @@ async fn test_simulate_transactions() { .iter() .cloned() .collect(); - let pre_mt_hashchains = pre_merkle_tree_account.hashchain_store; + let pre_mt_hashchains = pre_merkle_tree_account.hashchain_stores; if !outputs.is_empty() || !inputs.is_empty() { println!("Simulating tx with inputs: {:?}", instruction_data); @@ -679,16 +679,16 @@ async fn test_simulate_transactions() { .unwrap(); println!( "account - .hashchain_store {:?}", - account.hashchain_store + .hashchain_stores {:?}", + account.hashchain_stores ); - println!("hashchain store len {:?}", account.hashchain_store.len()); + println!("hashchain store len {:?}", account.hashchain_stores.len()); println!( "batch.get_num_inserted_zkps() as usize {:?}", batch.get_num_inserted_zkps() as usize ); let leaves_hashchain = account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -759,7 +759,7 @@ async fn test_simulate_transactions() { .get(next_full_batch as usize) .unwrap(); let leaves_hashchain = output_account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -927,7 +927,7 @@ async fn test_e2e() { BatchedQueueAccount::output_from_bytes(&mut pre_account_bytes).unwrap(); let pre_account = *pre_output_account.get_metadata(); let pre_value_store = pre_output_account.value_vecs; - let pre_hashchains = pre_output_account.hashchain_store; + let pre_hash_chains = pre_output_account.hashchain_stores; let mut output_account = BatchedQueueAccount::output_from_bytes(&mut output_queue_account_data).unwrap(); output_account @@ -936,7 +936,7 @@ async fn test_e2e() { assert_output_queue_insert( pre_account, pre_value_store, - pre_hashchains, + pre_hash_chains, BatchedQueueAccount::output_from_bytes( &mut output_queue_account_data.clone(), // clone so that data cannot be modified ) @@ -967,7 +967,7 @@ async fn test_e2e() { let pre_mt_account = BatchedMerkleTreeAccount::state_from_bytes(&mut pre_account_bytes).unwrap(); let pre_account = *pre_mt_account.get_metadata(); - let pre_hashchains = pre_mt_account.hashchain_store; + let pre_hash_chains = pre_mt_account.hashchain_stores; let pre_roots = pre_mt_account.root_history.iter().cloned().collect(); let tx_hash = create_hash_chain_from_slice(vec![leaf].as_slice()).unwrap(); let leaf_index = mock_indexer.merkle_tree.get_leaf_index(&leaf).unwrap(); @@ -996,7 +996,7 @@ async fn test_e2e() { pre_account, &mut [], pre_roots, - pre_hashchains, + pre_hash_chains, merkle_tree_account, vec![leaf], vec![leaf_index as u64], @@ -1062,7 +1062,7 @@ async fn test_e2e() { .to_vec(); println!("leaves {:?}", leaves.len()); let leaves_hashchain = output_account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -1171,7 +1171,7 @@ pub async fn perform_input_update( .get(next_full_batch as usize) .unwrap(); let leaves_hashchain = account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -1237,7 +1237,7 @@ pub async fn perform_address_update( .unwrap(); let batch_start_index = batch.start_index; let leaves_hashchain = account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -1484,7 +1484,7 @@ async fn test_fill_queues_completely() { BatchedQueueAccount::output_from_bytes(&mut pre_output_queue_account_data).unwrap(); let pre_account = *pre_output_account.get_metadata(); let pre_value_store = pre_output_account.value_vecs; - let pre_hashchains = pre_output_account.hashchain_store; + let pre_hash_chains = pre_output_account.hashchain_stores; let mut output_account = BatchedQueueAccount::output_from_bytes(&mut output_queue_account_data).unwrap(); @@ -1495,7 +1495,7 @@ async fn test_fill_queues_completely() { assert_output_queue_insert( pre_account, pre_value_store, - pre_hashchains, + pre_hash_chains, BatchedQueueAccount::output_from_bytes( &mut output_queue_account_data.clone(), // clone so that data cannot be modified ) @@ -1542,7 +1542,7 @@ async fn test_fill_queues_completely() { .unwrap(); let leaves = mock_indexer.output_queue_leaves.clone(); let leaves_hashchain = output_account - .hashchain_store + .hashchain_stores .get(next_full_batch as usize) .unwrap() .get(batch.get_num_inserted_zkps() as usize) @@ -1609,7 +1609,7 @@ async fn test_fill_queues_completely() { .iter() .cloned() .collect(); - let pre_hashchains = pre_merkle_tree_account.hashchain_store; + let pre_hash_chains = pre_merkle_tree_account.hashchain_stores; let tx_hash = create_hash_chain_from_slice(&[leaf]).unwrap(); // Index input queue insert event mock_indexer.input_queue_leaves.push((leaf, leaf_index)); @@ -1634,7 +1634,7 @@ async fn test_fill_queues_completely() { pre_account, &mut [], pre_roots, - pre_hashchains, + pre_hash_chains, merkle_tree_account, vec![leaf], vec![leaf_index as u64], @@ -1865,7 +1865,7 @@ async fn test_fill_address_tree_completely() { .iter() .cloned() .collect(); - let pre_hashchains = pre_merkle_tree_account.hashchain_store; + let pre_hash_chains = pre_merkle_tree_account.hashchain_stores; let mut merkle_tree_account = BatchedMerkleTreeAccount::address_from_bytes(&mut mt_account_data).unwrap(); merkle_tree_account @@ -1875,7 +1875,7 @@ async fn test_fill_address_tree_completely() { pre_account, &mut [], pre_roots, - pre_hashchains, + pre_hash_chains, merkle_tree_account, vec![rnd_address], vec![rnd_address], diff --git a/sdk-libs/program-test/src/test_batch_forester.rs b/sdk-libs/program-test/src/test_batch_forester.rs index c020ad776..cc7d5bdeb 100644 --- a/sdk-libs/program-test/src/test_batch_forester.rs +++ b/sdk-libs/program-test/src/test_batch_forester.rs @@ -123,7 +123,7 @@ pub async fn create_append_batch_ix_data( let num_inserted_zkps = output_queue.batch_metadata.batches[full_batch_index as usize].get_num_inserted_zkps(); let leaves_hashchain = - output_queue.hashchain_store[full_batch_index as usize][num_inserted_zkps as usize]; + output_queue.hashchain_stores[full_batch_index as usize][num_inserted_zkps as usize]; let (proof, new_root) = { let start = num_inserted_zkps as usize * zkp_batch_size as usize; let end = start + zkp_batch_size as usize; @@ -278,7 +278,7 @@ pub async fn get_batched_nullify_ix_data( let full_batch = &merkle_tree.queue_metadata.batches[full_batch_index as usize]; let zkp_batch_index = full_batch.get_num_inserted_zkps(); let leaves_hashchain = - merkle_tree.hashchain_store[full_batch_index as usize][zkp_batch_index as usize]; + merkle_tree.hashchain_stores[full_batch_index as usize][zkp_batch_index as usize]; let mut merkle_proofs = vec![]; let leaf_indices_tx_hashes = bundle.input_leaf_indices[..zkp_batch_size as usize].to_vec(); let mut leaves = Vec::new(); @@ -782,7 +782,7 @@ pub async fn create_batch_update_address_tree_instruction_data_with_proof< let batch = &merkle_tree.queue_metadata.batches[full_batch_index as usize]; let zkp_batch_index = batch.get_num_inserted_zkps(); let leaves_hashchain = - merkle_tree.hashchain_store[full_batch_index as usize][zkp_batch_index as usize]; + merkle_tree.hashchain_stores[full_batch_index as usize][zkp_batch_index as usize]; let batch_start_index = indexer .get_address_merkle_trees() .iter()