Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move PhotonIndexer to light-client crate #1525

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions forester/src/indexer_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
Expand Down
1 change: 0 additions & 1 deletion forester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions forester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 0 additions & 7 deletions forester/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: RpcConnection>(rpc: &mut R) -> ProtocolConfig {
let authority_pda = get_protocol_config_pda_address();
let protocol_config_account = rpc
Expand Down
3 changes: 1 addition & 2 deletions forester/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 2 additions & 0 deletions sdk-libs/client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down
Original file line number Diff line number Diff line change
@@ -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<R: RpcConnection> {
configuration: Configuration,
Expand Down Expand Up @@ -74,11 +72,11 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
) -> ProofRpcResult {
todo!()
}

async fn get_multiple_compressed_account_proofs(
&self,
hashes: Vec<String>,
) -> Result<Vec<MerkleProof>, IndexerError> {
debug!("Getting proofs for {:?}", hashes);
let request: photon_api::models::GetMultipleCompressedAccountProofsPostRequest =
photon_api::models::GetMultipleCompressedAccountProofsPostRequest {
params: hashes,
Expand Down Expand Up @@ -174,16 +172,12 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
..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()));
}
Expand Down Expand Up @@ -252,3 +246,10 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following avoids the vector allocation. (Just a suggestion below didn't test it.)

Suggested change
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
}
fn decode_hash(account: &str) -> [u8; 32] {
let mut arr = [0u8; 32];
bs58::decode(account)
.into(&mut arr)
.expect("Failed to decode base58 string");
arr
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better to return a result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done 301544d.

We already have cleaner implementation for conversions like this btw, but there is a mess with photon_client & sdk types that needs to be untangled first.
I started doing it here, but its not finished yet #1515

Loading