Skip to content

Commit

Permalink
remove unused imports in system-cpi-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jan 6, 2025
1 parent 3462eb5 commit a3c5f20
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
79 changes: 58 additions & 21 deletions forester/src/batch_processor/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::Arc;

use forester_utils::{forester_epoch::TreeType, indexer::Indexer};
use light_batched_merkle_tree::{batch::BatchState, merkle_tree::BatchedMerkleTreeAccount};
use light_batched_merkle_tree::{
batch::BatchState, merkle_tree::BatchedMerkleTreeAccount, queue::BatchedQueueAccount,
};
use light_client::{rpc::RpcConnection, rpc_pool::SolanaRpcPool};
use solana_program::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
Expand Down Expand Up @@ -60,32 +62,67 @@ impl<R: RpcConnection, I: Indexer<R>> BatchProcessor<R, I> {
Err(_) => return false,
};

if self.tree_type == TreeType::BatchedAddress {
return self.verify_input_queue_batch_ready(&mut rpc).await;
}

let input_queue_ready = self.verify_input_queue_batch_ready(&mut rpc).await;
let output_queue_ready = self.verify_output_queue_batch_ready(&mut rpc).await;

input_queue_ready && output_queue_ready
}

async fn verify_input_queue_batch_ready(&self, rpc: &mut R) -> bool {
let mut account = match rpc.get_account(self.context.merkle_tree).await {
Ok(Some(account)) => account,
_ => return false,
};

let is_ready = {
let merkle_tree = match self.tree_type {
TreeType::BatchedAddress => BatchedMerkleTreeAccount::address_tree_from_bytes_mut(
account.data.as_mut_slice(),
),
TreeType::BatchedState => {
BatchedMerkleTreeAccount::state_tree_from_bytes_mut(account.data.as_mut_slice())
}
_ => return false,
};

if let Ok(tree) = merkle_tree {
let batch_index = tree.get_metadata().queue_metadata.next_full_batch_index;
let full_batch = tree.batches.get(batch_index as usize).unwrap();

full_batch.get_state() != BatchState::Inserted
&& full_batch.get_current_zkp_batch_index() > full_batch.get_num_inserted_zkps()
} else {
false
let merkle_tree = match self.tree_type {
TreeType::BatchedAddress => {
BatchedMerkleTreeAccount::address_tree_from_bytes_mut(account.data.as_mut_slice())
}
TreeType::BatchedState => {
BatchedMerkleTreeAccount::state_tree_from_bytes_mut(account.data.as_mut_slice())
}
_ => return false,
};

if let Ok(tree) = merkle_tree {
let batch_index = tree.get_metadata().queue_metadata.next_full_batch_index;
let full_batch = tree.batches.get(batch_index as usize).unwrap();

full_batch.get_state() != BatchState::Inserted
&& full_batch.get_current_zkp_batch_index() > full_batch.get_num_inserted_zkps()
} else {
false
}
}

async fn verify_output_queue_batch_ready(&self, rpc: &mut R) -> bool {
info!("verify_output_queue_batch_ready");
let mut account = match rpc.get_account(self.context.output_queue).await {
Ok(Some(account)) => account,
_ => return false,
};

let output_queue = match self.tree_type {
TreeType::BatchedState => {
BatchedQueueAccount::output_queue_from_bytes_mut(account.data.as_mut_slice())
}
_ => return false,
};
is_ready

info!("output_queue: {:?}", output_queue);

if let Ok(queue) = output_queue {
let batch_index = queue.get_metadata().batch_metadata.next_full_batch_index;
let full_batch = queue.batches.get(batch_index as usize).unwrap();

full_batch.get_state() != BatchState::Inserted
&& full_batch.get_current_zkp_batch_index() > full_batch.get_num_inserted_zkps()
} else {
false
}
}
}
5 changes: 0 additions & 5 deletions forester/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,6 @@ impl<R: RpcConnection, I: Indexer<R>> EpochManager<R, I> {
if tree.tree_accounts.tree_type == TreeType::BatchedState
|| tree.tree_accounts.tree_type == TreeType::BatchedAddress
{
info!(
"Processing batched operations for tree {:?} ({:?})",
tree.tree_accounts.tree_type, tree.tree_accounts.merkle_tree
);

let batch_context = BatchContext {
rpc_pool: self.rpc_pool.clone(),
indexer: self.indexer.clone(),
Expand Down

0 comments on commit a3c5f20

Please sign in to comment.