Skip to content

Commit

Permalink
chore: rename hash_chain_store -> hash_chain_stores, small renamings …
Browse files Browse the repository at this point in the history
…and fixes
  • Loading branch information
ananas-block committed Jan 23, 2025
1 parent 5f2a27b commit 674c689
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 58 deletions.
6 changes: 3 additions & 3 deletions forester-utils/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -235,7 +235,7 @@ pub async fn create_append_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
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,
Expand Down Expand Up @@ -343,7 +343,7 @@ pub async fn create_nullify_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
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)
};
Expand Down
8 changes: 4 additions & 4 deletions program-libs/batched-merkle-tree/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn _assert_mt_zero_copy_inited<const TREE_TYPE: u64>(
);
}
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"
);
Expand Down
12 changes: 6 additions & 6 deletions program-libs/batched-merkle-tree/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {
Expand Down Expand Up @@ -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],
})
}

Expand Down Expand Up @@ -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],
})
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions program-libs/batched-merkle-tree/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {
Expand Down Expand Up @@ -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],
})
}

Expand Down Expand Up @@ -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],
})
}

Expand All @@ -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),
Expand Down Expand Up @@ -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<u64>,
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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()),
}?;
Expand Down
Loading

0 comments on commit 674c689

Please sign in to comment.