Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Jan 23, 2025
1 parent 37d09e1 commit 5f2a27b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
7 changes: 0 additions & 7 deletions program-libs/batched-merkle-tree/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,14 @@ impl Batch {

// 2. increments the number of inserted zkps.
self.num_inserted_zkps += 1;
msg!("num_inserted_zkps: {}", self.num_inserted_zkps);
// 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 {
msg!("Setting state to 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
// if not advance current root index to root index
self.sequence_number = sequence_number + root_history_length as u64;
msg!("root_history_length as u64: {}", root_history_length as u64);
msg!("sequence_number: {}", sequence_number);
msg!("recorded sequence_number: {}", self.sequence_number);
msg!("current root index {}", root_index);

self.root_index = root_index;
}

Expand Down
25 changes: 10 additions & 15 deletions program-libs/batched-merkle-tree/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,17 @@ impl<'a> BatchedMerkleTreeAccount<'a> {

// Update metadata and batch.
{
println!("pre mark_as_inserted_in_merkle_tree -------------------------------");
// 3. Mark zkp batch as inserted in the merkle tree.
let full_batch_state = queue_account.batch_metadata.batches[full_batch_index]
.mark_as_inserted_in_merkle_tree(
self.metadata.sequence_number,
root_index,
self.root_history_capacity,
)?;
msg!("full_batch_state: {:?}", full_batch_state);
msg!(
"next_full_batch_index: {:?}",
queue_account.batch_metadata.next_full_batch_index
);
// 4. Increment next full batch index if inserted.
queue_account
.batch_metadata
.increment_next_full_batch_index_if_inserted(full_batch_state);
msg!(
"next_full_batch_index: {:?}",
queue_account.batch_metadata.next_full_batch_index
);
}
// 5. Return the batch append event.
Ok(BatchAppendEvent {
Expand Down Expand Up @@ -840,12 +830,17 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
Ok(())
}

/// Return whether the tree is full.
/// For address trees it is based on the queue next index.
/// For state trees it is based on the tree next index.
pub fn tree_is_full(&self) -> bool {
println!(
"self.next_index: {} self.capacity: {}",
self.next_index, self.capacity
);
self.queue_metadata.next_index == self.capacity
if self.tree_type == TreeType::BatchedState as u64 {
self.next_index == self.capacity
} else if self.tree_type == TreeType::BatchedAddress as u64 {
self.queue_metadata.next_index == self.capacity
} else {
unreachable!("Invalid tree type.")
}
}

pub fn check_tree_is_full(&self) -> Result<(), BatchedMerkleTreeError> {
Expand Down
6 changes: 0 additions & 6 deletions program-libs/batched-merkle-tree/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,7 @@ pub(crate) fn insert_into_current_batch(
if current_batch.get_state() == BatchState::Fill {
// Do nothing, checking most often case first.
} else if clear_batch {
msg!("clear_batch");

if let Some(blomfilter_stores) = bloom_filter_stores.get_mut(batch_index) {
println!(
"current_batch.bloom_filter_is_zeroed() {:?}",
current_batch.bloom_filter_is_zeroed()
);
// Bloom filters should by default be zeroed by foresters
// because zeroing bytes is CU intensive.
// This is a safeguard to ensure queue lifeness
Expand Down
10 changes: 0 additions & 10 deletions program-libs/batched-merkle-tree/src/rollover_state_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@ pub fn batched_tree_is_ready_for_rollover(
if metadata.metadata.rollover_metadata.rollover_threshold == u64::MAX {
return Err(MerkleTreeMetadataError::RolloverNotConfigured.into());
}
println!("metadata.next_index: {}", metadata.next_index);
println!("metadata.height: {}", metadata.height);
println!(
"metadata.metadata.rollover_metadata.rollover_threshold: {}",
metadata.metadata.rollover_metadata.rollover_threshold
);
println!(
"threshold: {}",
(1 << metadata.height) * metadata.metadata.rollover_metadata.rollover_threshold / 100
);
if metadata.next_index
< ((1 << metadata.height) * metadata.metadata.rollover_metadata.rollover_threshold / 100)
{
Expand Down

0 comments on commit 5f2a27b

Please sign in to comment.