From d532c7e1261c45934075bf6a06b64e558c275039 Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Mon, 27 Jan 2025 15:43:39 +0100 Subject: [PATCH] refactor: move PhotonIndexer to light-client crate --- forester/src/indexer_type.rs | 5 +-- forester/src/lib.rs | 1 - forester/src/main.rs | 6 ++-- forester/src/utils.rs | 7 ----- forester/tests/test_utils.rs | 3 +- sdk-libs/client/src/indexer/mod.rs | 2 ++ .../client/src/indexer}/photon_indexer.rs | 31 ++++++++++--------- 7 files changed, 26 insertions(+), 29 deletions(-) rename {forester/src => sdk-libs/client/src/indexer}/photon_indexer.rs (96%) diff --git a/forester/src/indexer_type.rs b/forester/src/indexer_type.rs index 45a2f26472..ca39a6ccc8 100644 --- a/forester/src/indexer_type.rs +++ b/forester/src/indexer_type.rs @@ -3,7 +3,9 @@ use std::{any::Any, sync::Arc}; use async_trait::async_trait; use forester_utils::forester_epoch::TreeAccounts; use light_client::{ - indexer::{Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle}, + indexer::{ + photon_indexer::PhotonIndexer, Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle, + }, rpc::RpcConnection, }; use light_hasher::Poseidon; @@ -17,7 +19,6 @@ use tracing::info; use crate::{ errors::ForesterError, - photon_indexer::PhotonIndexer, rollover::{perform_address_merkle_tree_rollover, perform_state_merkle_tree_rollover_forester}, ForesterConfig, }; diff --git a/forester/src/lib.rs b/forester/src/lib.rs index 25ea7e6c0e..59f0c2aceb 100644 --- a/forester/src/lib.rs +++ b/forester/src/lib.rs @@ -10,7 +10,6 @@ pub mod helius_priority_fee_types; mod indexer_type; pub mod metrics; pub mod pagerduty; -pub mod photon_indexer; pub mod pubsub_client; pub mod queue_helpers; pub mod rollover; diff --git a/forester/src/main.rs b/forester/src/main.rs index 51ae5fa3e7..0b99486472 100644 --- a/forester/src/main.rs +++ b/forester/src/main.rs @@ -6,12 +6,14 @@ use forester::{ errors::ForesterError, forester_status, metrics::register_metrics, - photon_indexer::PhotonIndexer, run_pipeline, telemetry::setup_telemetry, ForesterConfig, }; -use light_client::rpc::{RpcConnection, SolanaRpcConnection}; +use light_client::{ + indexer::photon_indexer::PhotonIndexer, + rpc::{RpcConnection, SolanaRpcConnection}, +}; use tokio::{ signal::ctrl_c, sync::{mpsc, oneshot}, diff --git a/forester/src/utils.rs b/forester/src/utils.rs index 449977116c..b77a81f216 100644 --- a/forester/src/utils.rs +++ b/forester/src/utils.rs @@ -7,13 +7,6 @@ use light_registry::{ }; use tracing::debug; -pub fn decode_hash(account: &str) -> [u8; 32] { - let bytes = bs58::decode(account).into_vec().unwrap(); - let mut arr = [0u8; 32]; - arr.copy_from_slice(&bytes); - arr -} - pub async fn get_protocol_config(rpc: &mut R) -> ProtocolConfig { let authority_pda = get_protocol_config_pda_address(); let protocol_config_account = rpc diff --git a/forester/tests/test_utils.rs b/forester/tests/test_utils.rs index 4cfbbc6ca5..cec8cea89e 100644 --- a/forester/tests/test_utils.rs +++ b/forester/tests/test_utils.rs @@ -2,12 +2,11 @@ use account_compression::initialize_address_merkle_tree::Pubkey; use forester::{ config::{ExternalServicesConfig, GeneralConfig}, metrics::register_metrics, - photon_indexer::PhotonIndexer, telemetry::setup_telemetry, ForesterConfig, }; use light_client::{ - indexer::{Indexer, IndexerError, NewAddressProofWithContext}, + indexer::{photon_indexer::PhotonIndexer, Indexer, IndexerError, NewAddressProofWithContext}, rpc::RpcConnection, }; use light_program_test::{indexer::TestIndexerExtensions, test_env::get_test_env_accounts}; diff --git a/sdk-libs/client/src/indexer/mod.rs b/sdk-libs/client/src/indexer/mod.rs index cb7b61b88d..b527a255b3 100644 --- a/sdk-libs/client/src/indexer/mod.rs +++ b/sdk-libs/client/src/indexer/mod.rs @@ -14,6 +14,8 @@ use thiserror::Error; use crate::rpc::RpcConnection; +pub mod photon_indexer; + #[derive(Error, Debug)] pub enum IndexerError { #[error("RPC Error: {0}")] diff --git a/forester/src/photon_indexer.rs b/sdk-libs/client/src/indexer/photon_indexer.rs similarity index 96% rename from forester/src/photon_indexer.rs rename to sdk-libs/client/src/indexer/photon_indexer.rs index abbbf61b80..8ed737ed53 100644 --- a/forester/src/photon_indexer.rs +++ b/sdk-libs/client/src/indexer/photon_indexer.rs @@ -1,23 +1,21 @@ use std::fmt::Debug; -use account_compression::initialize_address_merkle_tree::Pubkey; use async_trait::async_trait; -use light_client::{ - indexer::{ - AddressMerkleTreeBundle, Indexer, IndexerError, LeafIndexInfo, MerkleProof, - NewAddressProofWithContext, ProofOfLeaf, - }, - rpc::RpcConnection, -}; use light_sdk::proof::ProofRpcResult; use photon_api::{ apis::configuration::{ApiKey, Configuration}, models::{AddressWithTree, GetCompressedAccountsByOwnerPostRequestParams}, }; +use solana_program::pubkey::Pubkey; use solana_sdk::bs58; -use tracing::debug; -use crate::utils::decode_hash; +use crate::{ + indexer::{ + AddressMerkleTreeBundle, Indexer, IndexerError, LeafIndexInfo, MerkleProof, + NewAddressProofWithContext, ProofOfLeaf, + }, + rpc::RpcConnection, +}; pub struct PhotonIndexer { configuration: Configuration, @@ -74,11 +72,11 @@ impl Indexer for PhotonIndexer { ) -> ProofRpcResult { todo!() } + async fn get_multiple_compressed_account_proofs( &self, hashes: Vec, ) -> Result, IndexerError> { - debug!("Getting proofs for {:?}", hashes); let request: photon_api::models::GetMultipleCompressedAccountProofsPostRequest = photon_api::models::GetMultipleCompressedAccountProofsPostRequest { params: hashes, @@ -174,16 +172,12 @@ impl Indexer for PhotonIndexer { ..Default::default() }; - debug!("Request: {:?}", request); - let result = photon_api::apis::default_api::get_multiple_new_address_proofs_v2_post( &self.configuration, request, ) .await; - debug!("Response: {:?}", result); - if result.is_err() { return Err(IndexerError::Custom(result.err().unwrap().to_string())); } @@ -252,3 +246,10 @@ impl Indexer for PhotonIndexer { todo!() } } + +fn decode_hash(account: &str) -> [u8; 32] { + let bytes = bs58::decode(account).into_vec().unwrap(); + let mut arr = [0u8; 32]; + arr.copy_from_slice(&bytes); + arr +}