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: remove rpc Clone implementations and add error handling #1076

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion forester/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub struct WorkReport {
pub processed_items: usize,
}

#[derive(Clone, Debug)]
#[derive(Debug)]
struct EpochManager<R: RpcConnection, I: Indexer<R>> {
config: Arc<ForesterConfig>,
protocol_config: Arc<ProtocolConfig>,
Expand All @@ -115,6 +115,20 @@ struct EpochManager<R: RpcConnection, I: Indexer<R>> {
trees: Vec<TreeAccounts>,
}

impl<R: RpcConnection, I: Indexer<R>> Clone for EpochManager<R, I> {
fn clone(&self) -> Self {
Self {
config: self.config.clone(),
protocol_config: self.protocol_config.clone(),
rpc_pool: self.rpc_pool.clone(),
indexer: self.indexer.clone(),
work_report_sender: self.work_report_sender.clone(),
processed_items_per_epoch_count: self.processed_items_per_epoch_count.clone(),
trees: self.trees.clone(),
}
}
}

#[derive(Debug, Clone)]
struct WorkItem {
tree_account: TreeAccounts,
Expand Down
10 changes: 1 addition & 9 deletions forester/src/photon_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::fmt::Debug;

pub struct PhotonIndexer<R: RpcConnection> {
configuration: Configuration,
#[allow(dead_code)]
rpc: R,
}

Expand All @@ -36,15 +37,6 @@ impl<R: RpcConnection> Debug for PhotonIndexer<R> {
}
}

impl<R: RpcConnection> Clone for PhotonIndexer<R> {
fn clone(&self) -> Self {
PhotonIndexer {
configuration: self.configuration.clone(),
rpc: self.rpc.clone(),
}
}
}

impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
async fn get_multiple_compressed_account_proofs(
&self,
Expand Down
3 changes: 1 addition & 2 deletions test-utils/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub use test_indexer::TokenDataWithContext;

use crate::indexer::test_indexer::ProofRpcResult;
use crate::rpc::rpc_connection::RpcConnection;
use crate::spl::create_mint_helper;
use account_compression::initialize_address_merkle_tree::{
Error as AccountCompressionError, Pubkey,
};
Expand All @@ -24,7 +23,7 @@ use light_system_program::sdk::event::PublicTransactionEvent;
use photon_api::apis::{default_api::GetCompressedAccountProofPostError, Error as PhotonApiError};
use thiserror::Error;

pub trait Indexer<R: RpcConnection>: Sync + Send + Clone + Debug + 'static {
pub trait Indexer<R: RpcConnection>: Sync + Send + Debug + 'static {
fn get_multiple_compressed_account_proofs(
&self,
hashes: Vec<String>,
Expand Down
24 changes: 4 additions & 20 deletions test-utils/src/indexer/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ pub struct TestIndexer<R: RpcConnection> {
phantom: PhantomData<R>,
}

impl<R: RpcConnection> Clone for TestIndexer<R> {
fn clone(&self) -> Self {
Self {
state_merkle_trees: self.state_merkle_trees.clone(),
address_merkle_trees: self.address_merkle_trees.clone(),
payer: self.payer.insecure_clone(),
group_pda: self.group_pda,
compressed_accounts: self.compressed_accounts.clone(),
nullified_compressed_accounts: self.nullified_compressed_accounts.clone(),
token_compressed_accounts: self.token_compressed_accounts.clone(),
token_nullified_compressed_accounts: self.token_nullified_compressed_accounts.clone(),
events: self.events.clone(),
proof_types: self.proof_types.clone(),
phantom: Default::default(),
}
}
}

#[derive(Debug, Clone)]
pub struct TokenDataWithContext {
pub token_data: TokenData,
Expand Down Expand Up @@ -771,7 +753,8 @@ impl<R: RpcConnection> TestIndexer<R> {
&AddressQueueConfig::default(),
0,
)
.await;
.await
.unwrap();
self.add_address_merkle_tree_accounts(merkle_tree_keypair, queue_keypair, owning_program_id)
}

Expand All @@ -797,7 +780,8 @@ impl<R: RpcConnection> TestIndexer<R> {
&StateMerkleTreeConfig::default(),
&NullifierQueueConfig::default(),
)
.await;
.await
.unwrap();

let state_merkle_tree_account = StateMerkleTreeAccounts {
merkle_tree: merkle_tree_keypair.pubkey(),
Expand Down
7 changes: 5 additions & 2 deletions test-utils/src/rpc/rpc_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use solana_sdk::signature::{Keypair, Signature};
use solana_sdk::transaction::Transaction;
use std::fmt::Debug;

pub trait RpcConnection: Clone + Send + Sync + Debug + 'static {
fn new<U: ToString>(_url: U, _commitment_config: Option<CommitmentConfig>) -> Self {
pub trait RpcConnection: Send + Sync + Debug + 'static {
fn new<U: ToString>(_url: U, _commitment_config: Option<CommitmentConfig>) -> Self
where
Self: Sized,
{
unimplemented!()
}

Expand Down
11 changes: 4 additions & 7 deletions test-utils/src/rpc/solana_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,11 @@ impl SolanaRpcConnection {
}
}

impl Clone for SolanaRpcConnection {
fn clone(&self) -> Self {
unimplemented!()
}
}

impl RpcConnection for SolanaRpcConnection {
fn new<U: ToString>(url: U, commitment_config: Option<CommitmentConfig>) -> Self {
fn new<U: ToString>(url: U, commitment_config: Option<CommitmentConfig>) -> Self
where
Self: Sized,
{
let payer = Keypair::new();
let commitment_config = commitment_config.unwrap_or(CommitmentConfig::confirmed());
let client = RpcClient::new_with_commitment(url, commitment_config);
Expand Down
6 changes: 0 additions & 6 deletions test-utils/src/rpc/test_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ impl Debug for ProgramTestRpcConnection {
}
}

impl Clone for ProgramTestRpcConnection {
fn clone(&self) -> Self {
unimplemented!()
}
}

impl RpcConnection for ProgramTestRpcConnection {
fn get_program_accounts(
&self,
Expand Down
Loading