Skip to content

Commit

Permalink
refactor: remove AddressMerkleTree{Accounts,Bundle}, StateMerkleTree{…
Browse files Browse the repository at this point in the history
…Accounts, Bundle} from forester-utils
  • Loading branch information
sergeytimoshin committed Nov 20, 2024
1 parent fac98a2 commit 6d76228
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 71 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,21 @@ pub struct AddressMerkleTreeAccounts {
pub queue: Pubkey,
}

#[derive(Debug, Clone)]
pub struct StateMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<MerkleTree<Poseidon>>,
pub accounts: StateMerkleTreeAccounts,
}

#[derive(Debug, Clone)]
pub struct AddressMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<IndexedMerkleTree<Poseidon, usize>>,
pub indexed_array: Box<IndexedArray<Poseidon, usize>>,
pub accounts: AddressMerkleTreeAccounts,
}

#[derive(Debug, Clone)]
pub struct StateMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<MerkleTree<Poseidon>>,
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])>,
}
7 changes: 2 additions & 5 deletions forester-utils/src/address_merkle_tree_config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
37 changes: 4 additions & 33 deletions forester-utils/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -39,38 +42,6 @@ pub struct ProofRpcResult {
pub address_root_indices: Vec<u16>,
}

#[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<MerkleTree<Poseidon>>,
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<IndexedMerkleTree<Poseidon, usize>>,
pub indexed_array: Box<IndexedArray<Poseidon, usize>>,
pub accounts: AddressMerkleTreeAccounts,
}

pub trait Indexer<R: RpcConnection>: Sync + Send + Debug + 'static {
fn get_multiple_compressed_account_proofs(
&self,
Expand Down
2 changes: 1 addition & 1 deletion forester-utils/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions forester/src/rollover/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion forester/tests/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions light-program-test/src/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
Expand Down
1 change: 1 addition & 0 deletions test-programs/account-compression-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion test-utils/src/assert_compressed_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions test-utils/src/e2e_test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
19 changes: 11 additions & 8 deletions test-utils/src/indexer/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -657,7 +660,7 @@ impl<R: RpcConnection> TestIndexer<R> {
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![],
Expand Down Expand Up @@ -704,7 +707,7 @@ impl<R: RpcConnection> TestIndexer<R> {
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,
}
}

Expand Down Expand Up @@ -743,7 +746,7 @@ impl<R: RpcConnection> TestIndexer<R> {
forester: Option<Pubkey>,
version: u64,
) {
let rollover_fee = match version {
let rollover_fee: u64 = match version {
1 => {
create_state_merkle_tree_and_queue_account(
&self.payer,
Expand All @@ -760,7 +763,7 @@ impl<R: RpcConnection> TestIndexer<R> {
)
.await
.unwrap();
FeeConfig::default().state_merkle_tree_rollover as i64
FeeConfig::default().state_merkle_tree_rollover
}
2 => {
let params = InitStateTreeAccountsInstructionData::test_default();
Expand All @@ -774,7 +777,7 @@ impl<R: RpcConnection> TestIndexer<R> {
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",
Expand Down
2 changes: 1 addition & 1 deletion test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test-utils/src/test_batch_forester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion test-utils/src/test_forester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6d76228

Please sign in to comment.