From 6d762289aaee15f37478ad6b0b9b200f3f5586d8 Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Wed, 20 Nov 2024 10:17:44 +0000 Subject: [PATCH] refactor: remove AddressMerkleTree{Accounts,Bundle}, StateMerkleTree{Accounts, Bundle} from forester-utils --- Cargo.lock | 1 + client/src/indexer/mod.rs | 18 +++++---- .../src/address_merkle_tree_config.rs | 7 +--- forester-utils/src/indexer/mod.rs | 37 ++----------------- forester-utils/src/registry.rs | 2 +- forester/src/rollover/operations.rs | 7 ++-- forester/tests/e2e_test.rs | 2 +- light-program-test/src/test_indexer.rs | 3 ++ .../account-compression-test/Cargo.toml | 1 + .../tests/address_merkle_tree_tests.rs | 6 +-- test-utils/src/assert_compressed_tx.rs | 3 +- test-utils/src/e2e_test_env.rs | 13 ++++--- test-utils/src/indexer/test_indexer.rs | 19 ++++++---- test-utils/src/lib.rs | 2 +- test-utils/src/test_batch_forester.rs | 3 +- test-utils/src/test_forester.rs | 2 +- 16 files changed, 55 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9aed5fc604..1ce6e2656e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,7 @@ dependencies = [ "ark-bn254", "ark-ff", "light-bounded-vec", + "light-client", "light-compressed-token", "light-concurrent-merkle-tree", "light-hash-set", diff --git a/client/src/indexer/mod.rs b/client/src/indexer/mod.rs index 709c9770c0..46d116bd8c 100644 --- a/client/src/indexer/mod.rs +++ b/client/src/indexer/mod.rs @@ -92,13 +92,6 @@ pub struct AddressMerkleTreeAccounts { pub queue: Pubkey, } -#[derive(Debug, Clone)] -pub struct StateMerkleTreeBundle { - pub rollover_fee: u64, - pub merkle_tree: Box>, - pub accounts: StateMerkleTreeAccounts, -} - #[derive(Debug, Clone)] pub struct AddressMerkleTreeBundle { pub rollover_fee: u64, @@ -106,3 +99,14 @@ pub struct AddressMerkleTreeBundle { pub indexed_array: Box>, pub accounts: AddressMerkleTreeAccounts, } + +#[derive(Debug, Clone)] +pub struct StateMerkleTreeBundle { + pub rollover_fee: u64, + pub merkle_tree: Box>, + pub accounts: StateMerkleTreeAccounts, + pub version: u64, + pub output_queue_elements: Vec<[u8; 32]>, + /// leaf index, leaf, tx hash + pub input_leaf_indices: Vec<(u32, [u8; 32], [u8; 32])>, +} diff --git a/forester-utils/src/address_merkle_tree_config.rs b/forester-utils/src/address_merkle_tree_config.rs index d7b0c08145..4c47a242cb 100644 --- a/forester-utils/src/address_merkle_tree_config.rs +++ b/forester-utils/src/address_merkle_tree_config.rs @@ -1,14 +1,11 @@ -use crate::{ - get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree, - indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}, - AccountZeroCopy, -}; +use crate::{get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree, AccountZeroCopy}; use account_compression::{ batched_merkle_tree::BatchedMerkleTreeAccount, AddressMerkleTreeAccount, AddressMerkleTreeConfig, AddressQueueConfig, NullifierQueueConfig, QueueAccount, StateMerkleTreeAccount, StateMerkleTreeConfig, }; use anchor_lang::Discriminator; +use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use num_traits::Zero; diff --git a/forester-utils/src/indexer/mod.rs b/forester-utils/src/indexer/mod.rs index c1659a0a1f..2234858ae7 100644 --- a/forester-utils/src/indexer/mod.rs +++ b/forester-utils/src/indexer/mod.rs @@ -5,6 +5,10 @@ use std::fmt::Debug; use account_compression::initialize_address_merkle_tree::{ Error as AccountCompressionError, Pubkey, }; +use light_client::indexer::AddressMerkleTreeBundle; +use light_client::indexer::{ + AddressMerkleTreeAccounts, StateMerkleTreeAccounts, StateMerkleTreeBundle, +}; use light_client::rpc::RpcConnection; use light_compressed_token::TokenData; use light_hash_set::HashSetError; @@ -17,7 +21,6 @@ use light_system_program::sdk::compressed_account::CompressedAccountWithMerkleCo use light_system_program::sdk::event::PublicTransactionEvent; use photon_api::apis::{default_api::GetCompressedAccountProofPostError, Error as PhotonApiError}; use thiserror::Error; - #[derive(Debug, Clone)] pub struct TokenDataWithContext { pub token_data: TokenData, @@ -39,38 +42,6 @@ pub struct ProofRpcResult { pub address_root_indices: Vec, } -#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)] -pub struct StateMerkleTreeAccounts { - pub merkle_tree: Pubkey, - pub nullifier_queue: Pubkey, - pub cpi_context: Pubkey, -} - -#[derive(Debug, Clone, Copy)] -pub struct AddressMerkleTreeAccounts { - pub merkle_tree: Pubkey, - pub queue: Pubkey, -} - -#[derive(Debug, Clone)] -pub struct StateMerkleTreeBundle { - pub rollover_fee: i64, - pub merkle_tree: Box>, - pub accounts: StateMerkleTreeAccounts, - pub version: u64, - pub output_queue_elements: Vec<[u8; 32]>, - /// leaf index, leaf, tx hash - pub input_leaf_indices: Vec<(u32, [u8; 32], [u8; 32])>, -} - -#[derive(Debug, Clone)] -pub struct AddressMerkleTreeBundle { - pub rollover_fee: i64, - pub merkle_tree: Box>, - pub indexed_array: Box>, - pub accounts: AddressMerkleTreeAccounts, -} - pub trait Indexer: Sync + Send + Debug + 'static { fn get_multiple_compressed_account_proofs( &self, diff --git a/forester-utils/src/registry.rs b/forester-utils/src/registry.rs index 914fb901c8..3b9fdae95f 100644 --- a/forester-utils/src/registry.rs +++ b/forester-utils/src/registry.rs @@ -5,7 +5,7 @@ use account_compression::{ StateMerkleTreeConfig, }; -use crate::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; +use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; use light_client::rpc::{RpcConnection, RpcError}; use light_registry::account_compression_cpi::sdk::{ create_rollover_state_merkle_tree_instruction, CreateRolloverMerkleTreeInstructionInputs, diff --git a/forester/src/rollover/operations.rs b/forester/src/rollover/operations.rs index b24c3edcfa..76760ddc63 100644 --- a/forester/src/rollover/operations.rs +++ b/forester/src/rollover/operations.rs @@ -26,13 +26,14 @@ use forester_utils::address_merkle_tree_config::{ get_address_bundle_config, get_state_bundle_config, }; use forester_utils::forester_epoch::{TreeAccounts, TreeType}; -use forester_utils::indexer::{ - AddressMerkleTreeAccounts, Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle, -}; +use forester_utils::indexer::Indexer; use forester_utils::registry::RentExemption; use forester_utils::{ create_account_instruction, get_concurrent_merkle_tree, get_indexed_merkle_tree, }; +use light_client::indexer::{ + AddressMerkleTreeAccounts, StateMerkleTreeAccounts, StateMerkleTreeBundle, +}; use light_client::rpc::{RpcConnection, RpcError}; use light_hasher::Poseidon; use light_merkle_tree_reference::MerkleTree; diff --git a/forester/tests/e2e_test.rs b/forester/tests/e2e_test.rs index 4fe027dbab..ebe26dd815 100644 --- a/forester/tests/e2e_test.rs +++ b/forester/tests/e2e_test.rs @@ -3,8 +3,8 @@ use account_compression::AddressMerkleTreeAccount; use forester::queue_helpers::fetch_queue_item_data; use forester::run_pipeline; use forester::utils::get_protocol_config; -use forester_utils::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; use forester_utils::registry::register_test_forester; +use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; use light_client::rpc::solana_rpc::SolanaRpcUrl; use light_client::rpc::{RpcConnection, RpcError, SolanaRpcConnection}; use light_client::rpc_pool::SolanaRpcPool; diff --git a/light-program-test/src/test_indexer.rs b/light-program-test/src/test_indexer.rs index b3661592ce..9f5008035f 100644 --- a/light-program-test/src/test_indexer.rs +++ b/light-program-test/src/test_indexer.rs @@ -338,6 +338,9 @@ where accounts: *accounts, merkle_tree, rollover_fee: FeeConfig::default().state_merkle_tree_rollover, + version: 1, + input_leaf_indices: vec![], + output_queue_elements: vec![], } }) .collect::>(); diff --git a/test-programs/account-compression-test/Cargo.toml b/test-programs/account-compression-test/Cargo.toml index be902aaa66..0d645ec57b 100644 --- a/test-programs/account-compression-test/Cargo.toml +++ b/test-programs/account-compression-test/Cargo.toml @@ -43,6 +43,7 @@ light-merkle-tree-reference = {path = "../../merkle-tree/reference"} light-bounded-vec = {path = "../../merkle-tree/bounded-vec"} light-utils = {path = "../../utils"} light-verifier = {path = "../../circuit-lib/verifier"} +light-client = { workspace = true } rand = "0.8" solana-cli-output = { workspace = true } serde_json = "1.0.114" diff --git a/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs b/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs index a3e831fa62..c77958af6e 100644 --- a/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs +++ b/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs @@ -12,6 +12,7 @@ use anchor_lang::error::ErrorCode; use ark_bn254::Fr; use ark_ff::{BigInteger, PrimeField, UniformRand}; use light_bounded_vec::BoundedVecError; +use light_client::indexer::{AddressMerkleTreeAccounts, AddressMerkleTreeBundle}; use light_concurrent_merkle_tree::errors::ConcurrentMerkleTreeError; use light_hash_set::{HashSet, HashSetError}; use light_hasher::Poseidon; @@ -29,8 +30,7 @@ use light_test_utils::{ }; use light_test_utils::{ airdrop_lamports, assert_rpc_error, create_account_instruction, get_hash_set, - get_indexed_merkle_tree, AddressMerkleTreeAccounts, AddressMerkleTreeBundle, FeeConfig, - RpcConnection, RpcError, + get_indexed_merkle_tree, FeeConfig, RpcConnection, RpcError, }; use light_utils::bigint::bigint_to_be_bytes_array; use num_bigint::ToBigUint; @@ -1474,7 +1474,7 @@ pub async fn test_setup_with_address_merkle_tree( merkle_tree: address_merkle_tree_keypair.pubkey(), queue: address_queue_keypair.pubkey(), }, - rollover_fee: FeeConfig::default().address_queue_rollover as i64, + rollover_fee: FeeConfig::default().address_queue_rollover, }; (context, payer, address_merkle_tree_bundle) } diff --git a/test-utils/src/assert_compressed_tx.rs b/test-utils/src/assert_compressed_tx.rs index 4ef53c5f5e..4e8223d39a 100644 --- a/test-utils/src/assert_compressed_tx.rs +++ b/test-utils/src/assert_compressed_tx.rs @@ -4,8 +4,9 @@ use account_compression::batched_merkle_tree::{ use account_compression::batched_queue::BatchedQueueAccount; use account_compression::{state::QueueAccount, StateMerkleTreeAccount}; use anchor_lang::Discriminator; -use forester_utils::indexer::{Indexer, StateMerkleTreeAccounts}; +use forester_utils::indexer::Indexer; use forester_utils::{get_concurrent_merkle_tree, get_hash_set, AccountZeroCopy}; +use light_client::indexer::StateMerkleTreeAccounts; use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use light_system_program::sdk::event::MerkleTreeSequenceNumber; diff --git a/test-utils/src/e2e_test_env.rs b/test-utils/src/e2e_test_env.rs index 97ca757655..e32a9fb455 100644 --- a/test-utils/src/e2e_test_env.rs +++ b/test-utils/src/e2e_test_env.rs @@ -123,12 +123,13 @@ use forester_utils::address_merkle_tree_config::{ address_tree_ready_for_rollover, state_tree_ready_for_rollover, }; use forester_utils::forester_epoch::{Epoch, Forester, TreeAccounts, TreeType}; -use forester_utils::indexer::{ - AddressMerkleTreeAccounts, AddressMerkleTreeBundle, Indexer, StateMerkleTreeAccounts, - StateMerkleTreeBundle, TokenDataWithContext, -}; +use forester_utils::indexer::{Indexer, TokenDataWithContext}; use forester_utils::registry::register_test_forester; use forester_utils::{airdrop_lamports, AccountZeroCopy}; +use light_client::indexer::{ + AddressMerkleTreeAccounts, AddressMerkleTreeBundle, StateMerkleTreeAccounts, + StateMerkleTreeBundle, +}; use light_hasher::Poseidon; use light_indexed_merkle_tree::HIGHEST_ADDRESS_PLUS_ONE; use light_indexed_merkle_tree::{array::IndexedArray, reference::IndexedMerkleTree}; @@ -991,7 +992,7 @@ where .deserialized() .metadata .rollover_metadata - .rollover_fee as i64, + .rollover_fee, accounts: StateMerkleTreeAccounts { merkle_tree: merkle_tree_keypair.pubkey(), nullifier_queue: nullifier_queue_keypair.pubkey(), @@ -1081,7 +1082,7 @@ where .deserialized() .metadata .rollover_metadata - .rollover_fee as i64, + .rollover_fee, accounts: AddressMerkleTreeAccounts { merkle_tree: merkle_tree_keypair.pubkey(), queue: nullifier_queue_keypair.pubkey(), diff --git a/test-utils/src/indexer/test_indexer.rs b/test-utils/src/indexer/test_indexer.rs index 06e87f0c43..c190caee92 100644 --- a/test-utils/src/indexer/test_indexer.rs +++ b/test-utils/src/indexer/test_indexer.rs @@ -25,11 +25,14 @@ use account_compression::{ NullifierQueueConfig, StateMerkleTreeConfig, }; use forester_utils::indexer::{ - AddressMerkleTreeAccounts, AddressMerkleTreeBundle, BatchedTreeProofRpcResult, Indexer, - IndexerError, MerkleProof, NewAddressProofWithContext, ProofRpcResult, StateMerkleTreeAccounts, - StateMerkleTreeBundle, TokenDataWithContext, + BatchedTreeProofRpcResult, Indexer, IndexerError, MerkleProof, NewAddressProofWithContext, + ProofRpcResult, TokenDataWithContext, }; use forester_utils::{get_concurrent_merkle_tree, get_indexed_merkle_tree, AccountZeroCopy}; +use light_client::indexer::{ + AddressMerkleTreeAccounts, AddressMerkleTreeBundle, StateMerkleTreeAccounts, + StateMerkleTreeBundle, +}; use light_client::rpc::{RpcConnection, RpcError}; use light_client::transaction_params::FeeConfig; use light_compressed_token::constants::TOKEN_COMPRESSED_ACCOUNT_DISCRIMINATOR; @@ -657,7 +660,7 @@ impl TestIndexer { state_merkle_trees.push(StateMerkleTreeBundle { accounts: *state_merkle_tree_account, merkle_tree, - rollover_fee: FeeConfig::default().state_merkle_tree_rollover as i64, + rollover_fee: FeeConfig::default().state_merkle_tree_rollover, version, output_queue_elements: vec![], input_leaf_indices: vec![], @@ -704,7 +707,7 @@ impl TestIndexer { merkle_tree, indexed_array, accounts: address_merkle_tree_accounts, - rollover_fee: FeeConfig::default().address_queue_rollover as i64, + rollover_fee: FeeConfig::default().address_queue_rollover, } } @@ -743,7 +746,7 @@ impl TestIndexer { forester: Option, version: u64, ) { - let rollover_fee = match version { + let rollover_fee: u64 = match version { 1 => { create_state_merkle_tree_and_queue_account( &self.payer, @@ -760,7 +763,7 @@ impl TestIndexer { ) .await .unwrap(); - FeeConfig::default().state_merkle_tree_rollover as i64 + FeeConfig::default().state_merkle_tree_rollover } 2 => { let params = InitStateTreeAccountsInstructionData::test_default(); @@ -774,7 +777,7 @@ impl TestIndexer { cpi_context_keypair, params, ).await; - FeeConfig::test_batched().state_merkle_tree_rollover as i64 + FeeConfig::test_batched().state_merkle_tree_rollover } _ => panic!( "add_state_merkle_tree: Version not supported, {}. Versions: 1 concurrent, 2 batched", diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 5260bdf7b8..51c4e39f3f 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -25,7 +25,7 @@ pub use forester_utils::{ airdrop_lamports, create_account_instruction, forester_epoch::{Epoch, TreeAccounts, TreeType}, get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree, - indexer::{AddressMerkleTreeAccounts, AddressMerkleTreeBundle, Indexer, TokenDataWithContext}, + indexer::{Indexer, TokenDataWithContext}, registry::{ create_rollover_address_merkle_tree_instructions, create_rollover_state_merkle_tree_instructions, register_test_forester, diff --git a/test-utils/src/test_batch_forester.rs b/test-utils/src/test_batch_forester.rs index 71b916e59d..785b34c367 100644 --- a/test-utils/src/test_batch_forester.rs +++ b/test-utils/src/test_batch_forester.rs @@ -13,7 +13,8 @@ use account_compression::{ get_output_queue_account_default, InitStateTreeAccountsInstructionData, }; use anchor_lang::AnchorSerialize; -use forester_utils::{create_account_instruction, indexer::StateMerkleTreeBundle, AccountZeroCopy}; +use forester_utils::{create_account_instruction, AccountZeroCopy}; +use light_client::indexer::StateMerkleTreeBundle; use light_client::rpc::{RpcConnection, RpcError}; use light_hasher::Poseidon; use light_prover_client::{ diff --git a/test-utils/src/test_forester.rs b/test-utils/src/test_forester.rs index 2121a4a47c..0041820390 100644 --- a/test-utils/src/test_forester.rs +++ b/test-utils/src/test_forester.rs @@ -17,8 +17,8 @@ use light_concurrent_merkle_tree::event::MerkleTreeEvent; use light_hasher::Poseidon; use light_indexed_merkle_tree::copy::IndexedMerkleTreeCopy; -use forester_utils::indexer::{AddressMerkleTreeBundle, StateMerkleTreeBundle}; use forester_utils::{get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree}; +use light_client::indexer::{AddressMerkleTreeBundle, StateMerkleTreeBundle}; use light_registry::account_compression_cpi::sdk::{ create_nullify_instruction, create_update_address_merkle_tree_instruction, CreateNullifyInstructionInputs, UpdateAddressMerkleTreeInstructionInputs,