From a3c5f20d8327e1ae7aded76e4855af5f26202820 Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Mon, 6 Jan 2025 15:56:15 +0000 Subject: [PATCH] remove unused imports in system-cpi-test. --- forester/src/batch_processor/common.rs | 79 +++++++++++++++++++------- forester/src/epoch_manager.rs | 5 -- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/forester/src/batch_processor/common.rs b/forester/src/batch_processor/common.rs index 3cd667adb..4876c6e7f 100644 --- a/forester/src/batch_processor/common.rs +++ b/forester/src/batch_processor/common.rs @@ -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; @@ -60,32 +62,67 @@ impl> BatchProcessor { 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 + } } } diff --git a/forester/src/epoch_manager.rs b/forester/src/epoch_manager.rs index a7655d1e5..566622c09 100644 --- a/forester/src/epoch_manager.rs +++ b/forester/src/epoch_manager.rs @@ -870,11 +870,6 @@ impl> EpochManager { 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(),