Skip to content

Commit c7b2aa3

Browse files
refactor: replace with_indexer with photon_url in LightClientConfig (#1814)
* refactor: replace `with_indexer` with `photon_url` in `LightClientConfig` and adjust related tests and RPC calls * use `indexer_url` from config as photon_url in register_for_epoch_with_retry * forester: use `indexer_url` from config as photon_url in `SolanaRpcPoolBuilder`
1 parent e96ca3c commit c7b2aa3

19 files changed

+49
-88
lines changed

forester-utils/src/rpc_pool.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum PoolError {
2626

2727
pub struct SolanaConnectionManager<R: Rpc + 'static> {
2828
url: String,
29+
photon_url: Option<String>,
2930
commitment: CommitmentConfig,
3031
// TODO: implement Rpc for SolanaConnectionManager and rate limit requests.
3132
_rpc_rate_limiter: Option<RateLimiter>,
@@ -36,12 +37,14 @@ pub struct SolanaConnectionManager<R: Rpc + 'static> {
3637
impl<R: Rpc + 'static> SolanaConnectionManager<R> {
3738
pub fn new(
3839
url: String,
40+
photon_url: Option<String>,
3941
commitment: CommitmentConfig,
4042
rpc_rate_limiter: Option<RateLimiter>,
4143
send_tx_rate_limiter: Option<RateLimiter>,
4244
) -> Self {
4345
Self {
4446
url,
47+
photon_url,
4548
commitment,
4649
_rpc_rate_limiter: rpc_rate_limiter,
4750
_send_tx_rate_limiter: send_tx_rate_limiter,
@@ -58,8 +61,8 @@ impl<R: Rpc + 'static> bb8::ManageConnection for SolanaConnectionManager<R> {
5861
async fn connect(&self) -> Result<Self::Connection, Self::Error> {
5962
let config = LightClientConfig {
6063
url: self.url.to_string(),
64+
photon_url: self.photon_url.clone(),
6165
commitment_config: Some(self.commitment),
62-
with_indexer: false,
6366
fetch_active_tree: false,
6467
};
6568

@@ -86,6 +89,8 @@ pub struct SolanaRpcPool<R: Rpc + 'static> {
8689
#[derive(Debug)]
8790
pub struct SolanaRpcPoolBuilder<R: Rpc> {
8891
url: Option<String>,
92+
photon_url: Option<String>,
93+
8994
commitment: Option<CommitmentConfig>,
9095

9196
max_size: u32,
@@ -110,6 +115,7 @@ impl<R: Rpc> SolanaRpcPoolBuilder<R> {
110115
pub fn new() -> Self {
111116
Self {
112117
url: None,
118+
photon_url: None,
113119
commitment: None,
114120
max_size: 50,
115121
connection_timeout_secs: 15,
@@ -128,6 +134,11 @@ impl<R: Rpc> SolanaRpcPoolBuilder<R> {
128134
self
129135
}
130136

137+
pub fn photon_url(mut self, url: Option<String>) -> Self {
138+
self.photon_url = url;
139+
self
140+
}
141+
131142
pub fn commitment(mut self, commitment: CommitmentConfig) -> Self {
132143
self.commitment = Some(commitment);
133144
self
@@ -183,6 +194,7 @@ impl<R: Rpc> SolanaRpcPoolBuilder<R> {
183194

184195
let manager = SolanaConnectionManager::new(
185196
url,
197+
self.photon_url,
186198
commitment,
187199
self.rpc_rate_limiter,
188200
self.send_tx_rate_limiter,

forester/src/epoch_manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,9 @@ impl<R: Rpc, I: Indexer + IndexerType<R> + 'static> EpochManager<R, I> {
475475
) -> Result<ForesterEpochInfo> {
476476
let rpc = LightClient::new(LightClientConfig {
477477
url: self.config.external_services.rpc_url.to_string(),
478+
photon_url: self.config.external_services.indexer_url.clone(),
478479
commitment_config: None,
479480
fetch_active_tree: false,
480-
481-
with_indexer: false,
482481
})
483482
.await
484483
.unwrap();
@@ -545,10 +544,9 @@ impl<R: Rpc, I: Indexer + IndexerType<R> + 'static> EpochManager<R, I> {
545544
info!("Registering for epoch: {}", epoch);
546545
let mut rpc = LightClient::new(LightClientConfig {
547546
url: self.config.external_services.rpc_url.to_string(),
547+
photon_url: None,
548548
commitment_config: None,
549549
fetch_active_tree: false,
550-
551-
with_indexer: false,
552550
})
553551
.await
554552
.unwrap();
@@ -1198,9 +1196,9 @@ impl<R: Rpc, I: Indexer + IndexerType<R> + 'static> EpochManager<R, I> {
11981196
info!("Reporting work");
11991197
let mut rpc = LightClient::new(LightClientConfig {
12001198
url: self.config.external_services.rpc_url.to_string(),
1199+
photon_url: None,
12011200
commitment_config: None,
12021201
fetch_active_tree: false,
1203-
with_indexer: false,
12041202
})
12051203
.await
12061204
.unwrap();

forester/src/forester_status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ pub async fn fetch_forester_status(args: &StatusArgs) -> crate::Result<()> {
173173
debug!("RPC URL: {}", config.external_services.rpc_url);
174174
let mut rpc = LightClient::new(LightClientConfig {
175175
url: config.external_services.rpc_url.to_string(),
176+
photon_url: None,
176177
commitment_config: None,
177178
fetch_active_tree: false,
178-
with_indexer: false,
179179
})
180180
.await?;
181181
let trees = fetch_trees(&rpc).await?;

forester/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ pub async fn run_queue_info(
5555
) -> Result<()> {
5656
let mut rpc = LightClient::new(LightClientConfig {
5757
url: config.external_services.rpc_url.to_string(),
58+
photon_url: None,
5859
commitment_config: None,
5960
fetch_active_tree: false,
60-
61-
with_indexer: false,
6261
})
6362
.await
6463
.unwrap();
@@ -122,6 +121,7 @@ pub async fn run_pipeline<R: Rpc, I: Indexer + IndexerType<R> + 'static>(
122121
) -> Result<()> {
123122
let mut builder = SolanaRpcPoolBuilder::<R>::default()
124123
.url(config.external_services.rpc_url.to_string())
124+
.photon_url(config.external_services.indexer_url.clone())
125125
.commitment(CommitmentConfig::confirmed())
126126
.max_size(config.rpc_pool_config.max_size)
127127
.connection_timeout_secs(config.rpc_pool_config.connection_timeout_secs)

forester/tests/address_v2_test.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use light_batched_merkle_tree::{
1111
use light_client::{
1212
indexer::{photon_indexer::PhotonIndexer, AddressWithTree},
1313
local_test_validator::{LightValidatorConfig, ProverConfig},
14-
rpc::{client::RpcUrl, merkle_tree::MerkleTreeExt, LightClient, LightClientConfig, Rpc},
14+
rpc::{merkle_tree::MerkleTreeExt, LightClient, LightClientConfig, Rpc},
1515
};
1616
use light_compressed_account::{
1717
address::derive_address,
@@ -32,7 +32,7 @@ use light_test_utils::{
3232
use rand::{prelude::StdRng, Rng, SeedableRng};
3333
use serial_test::serial;
3434
use solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey};
35-
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair, signer::Signer};
35+
use solana_sdk::{signature::Keypair, signer::Signer};
3636
use tokio::sync::{mpsc, oneshot, Mutex};
3737

3838
use crate::test_utils::{forester_config, init};
@@ -71,14 +71,7 @@ async fn test_create_v2_address() {
7171
config.derivation_pubkey = env.protocol.forester.pubkey();
7272
config.general_config = GeneralConfig::test_address_v2();
7373

74-
let mut rpc = LightClient::new(LightClientConfig {
75-
url: RpcUrl::Localnet.to_string(),
76-
commitment_config: Some(CommitmentConfig::processed()),
77-
fetch_active_tree: false,
78-
with_indexer: true,
79-
})
80-
.await
81-
.unwrap();
74+
let mut rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
8275
rpc.payer = env.protocol.forester.insecure_clone();
8376

8477
ensure_sufficient_balance(

forester/tests/batched_address_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ async fn test_address_batched() {
6565
let commitment_config = CommitmentConfig::confirmed();
6666
let mut rpc = LightClient::new(LightClientConfig {
6767
url: RpcUrl::Localnet.to_string(),
68+
photon_url: None,
6869
commitment_config: Some(commitment_config),
6970
fetch_active_tree: false,
70-
with_indexer: false,
7171
})
7272
.await
7373
.unwrap();

forester/tests/batched_state_async_indexer_test.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use light_client::{
1212
GetCompressedTokenAccountsByOwnerOrDelegateOptions, Indexer,
1313
},
1414
local_test_validator::{LightValidatorConfig, ProverConfig},
15-
rpc::{client::RpcUrl, LightClient, LightClientConfig, Rpc},
15+
rpc::{LightClient, LightClientConfig, Rpc},
1616
};
1717
use light_compressed_account::{
1818
address::derive_address_legacy,
@@ -38,7 +38,6 @@ use rand::{prelude::SliceRandom, rngs::StdRng, Rng, SeedableRng};
3838
use serial_test::serial;
3939
use solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey};
4040
use solana_sdk::{
41-
commitment_config::CommitmentConfig,
4241
signature::{Keypair, Signature},
4342
signer::Signer,
4443
};
@@ -222,14 +221,7 @@ async fn test_state_indexer_async_batched() {
222221
// ─────────────────────────────────────────────────────────────────────────────
223222

224223
async fn setup_rpc_connection(forester: &Keypair) -> LightClient {
225-
let mut rpc = LightClient::new(LightClientConfig {
226-
url: RpcUrl::Localnet.to_string(),
227-
commitment_config: Some(CommitmentConfig::processed()),
228-
fetch_active_tree: false,
229-
with_indexer: true,
230-
})
231-
.await
232-
.unwrap();
224+
let mut rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
233225
rpc.payer = forester.insecure_clone();
234226
rpc
235227
}

forester/tests/batched_state_indexer_test.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use light_batched_merkle_tree::{
1212
use light_client::{
1313
indexer::{photon_indexer::PhotonIndexer, Indexer, IndexerRpcConfig, RetryConfig},
1414
local_test_validator::{LightValidatorConfig, ProverConfig},
15-
rpc::{client::RpcUrl, LightClient, LightClientConfig, Rpc},
15+
rpc::{LightClient, LightClientConfig, Rpc},
1616
};
1717
use light_compressed_account::TreeType;
1818
use light_program_test::{accounts::test_accounts::TestAccounts, indexer::TestIndexer};
@@ -61,15 +61,7 @@ async fn test_state_indexer_batched() {
6161
.await
6262
.unwrap();
6363

64-
let commitment_config = CommitmentConfig::confirmed();
65-
let mut rpc = LightClient::new(LightClientConfig {
66-
url: RpcUrl::Localnet.to_string(),
67-
fetch_active_tree: false,
68-
commitment_config: Some(commitment_config),
69-
with_indexer: true,
70-
})
71-
.await
72-
.unwrap();
64+
let mut rpc = LightClient::new(LightClientConfig::local()).await.unwrap();
7365
rpc.payer = forester_keypair.insecure_clone();
7466

7567
rpc.airdrop_lamports(&forester_keypair.pubkey(), LAMPORTS_PER_SOL * 100_000)

forester/tests/batched_state_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ async fn test_state_batched() {
6969
let commitment_config = CommitmentConfig::confirmed();
7070
let mut rpc = LightClient::new(LightClientConfig {
7171
url: RpcUrl::Localnet.to_string(),
72+
photon_url: None,
7273
commitment_config: Some(commitment_config),
7374
fetch_active_tree: false,
74-
with_indexer: false,
7575
})
7676
.await
7777
.unwrap();

forester/tests/e2e_test.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,9 @@ async fn test_epoch_monitor_with_2_foresters() {
6060
.await
6161
.unwrap();
6262

63-
let mut rpc = LightClient::new(LightClientConfig {
64-
url: RpcUrl::Localnet.to_string(),
65-
commitment_config: Some(CommitmentConfig::confirmed()),
66-
fetch_active_tree: false,
67-
with_indexer: false,
68-
})
69-
.await
70-
.unwrap();
63+
let mut rpc = LightClient::new(LightClientConfig::local_no_indexer())
64+
.await
65+
.unwrap();
7166
rpc.payer = forester_keypair1.insecure_clone();
7267

7368
// Airdrop to both foresters and governance authority
@@ -410,9 +405,9 @@ async fn test_epoch_double_registration() {
410405

411406
let mut rpc = LightClient::new(LightClientConfig {
412407
url: RpcUrl::Localnet.to_string(),
408+
photon_url: None,
413409
commitment_config: Some(CommitmentConfig::confirmed()),
414410
fetch_active_tree: false,
415-
with_indexer: false,
416411
})
417412
.await
418413
.unwrap();

0 commit comments

Comments
 (0)