diff --git a/Cargo.lock b/Cargo.lock index 1b61f56c98..81b5a73cc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2294,7 +2294,6 @@ dependencies = [ "anchor-lang", "async-trait", "base64 0.22.1", - "bb8", "bincode", "borsh 0.10.3", "bs58 0.4.0", @@ -2310,6 +2309,7 @@ dependencies = [ "futures 0.3.30", "lazy_static", "light-bounded-vec", + "light-client", "light-concurrent-merkle-tree", "light-hash-set", "light-hasher", @@ -2358,6 +2358,7 @@ dependencies = [ "anchor-lang", "anchor-spl", "async-trait", + "light-client", "light-compressed-token", "light-concurrent-merkle-tree", "light-hash-set", @@ -3493,6 +3494,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "light-client" +version = "0.8.0" +dependencies = [ + "async-trait", + "bb8", + "borsh 0.10.3", + "log", + "solana-banks-client", + "solana-client", + "solana-program", + "solana-sdk", + "solana-transaction-status", + "thiserror", + "tokio", +] + [[package]] name = "light-compressed-token" version = "1.0.0" @@ -3637,7 +3655,7 @@ dependencies = [ "ark-relations", "ark-serialize", "ark-std", - "borsh 0.9.3", + "borsh 0.10.3", "bytemuck", "color-eyre", "duct", @@ -3760,6 +3778,7 @@ dependencies = [ "ark-ff", "async-trait", "forester-utils", + "light-client", "light-compressed-token", "light-concurrent-merkle-tree", "light-hash-set", diff --git a/Cargo.toml b/Cargo.toml index e790aab9d5..6ad793d7d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "programs/system", "programs/compressed-token", "programs/registry", + "client", "sdk", "test-utils", "utils", @@ -23,7 +24,7 @@ members = [ "forester-utils", "forester", "photon-api", - "sdk"] +] [profile.release] overflow-checks = true @@ -32,6 +33,8 @@ overflow-checks = true opt-level = 2 [workspace.dependencies] +# Solana +solana-banks-client = "=1.18.22" solana-banks-interface = "=1.18.22" solana-program = "=1.18.22" solana-sdk = "=1.18.22" @@ -41,19 +44,34 @@ solana-cli-output = "=1.18.22" solana-transaction-status = "=1.18.22" solana-account-decoder = "=1.18.22" solana-rpc = "=1.18.22" +spl-token = "=4.0.0" -photon-api = { path = "photon-api" } - +# Anchor anchor-lang = "=0.29.0" anchor-spl = "=0.29.0" -spl-token = "=4.0.0" +# Anchor compatibility +borsh = "0.10.0" +# Macro helpers proc-macro2 = "1.0" quote = "1.0" syn = { version = "2.0", features = ["visit-mut", "full"] } +# Async ecosystem tokio = { version = "1.39.1", features = ["rt", "macros", "rt-multi-thread"] } +async-trait = "0.1.82" +bb8 = "0.8.5" + +# Logging +log = "0.4" + +# Error handling +thiserror = "1.0" + +# Light Protocol +light-client = { path = "client", version = "0.8.0" } +photon-api = { path = "photon-api" } [patch.crates-io] "solana-account-decoder" = { git = "https://github.com/lightprotocol/agave", branch = "v1.18.22-enforce-cpi-tracking" } diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000000..e34da5213c --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "light-client" +version = "0.8.0" +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/lightprotocol/light-protocol" +description = "Client library for Light Protocol" + +[dependencies] +# Solana +solana-banks-client = { workspace = true } +solana-client = { workspace = true } +solana-program = { workspace = true } +solana-sdk = { workspace = true } +solana-transaction-status = { workspace = true } + +# Anchor compatibility +borsh = { workspace = true } + +# Async ecosystem +tokio = { workspace = true } +async-trait = { workspace = true } +bb8 = { workspace = true } + +log = { workspace = true } +thiserror = { workspace = true } diff --git a/client/src/indexer/mod.rs b/client/src/indexer/mod.rs new file mode 100644 index 0000000000..9499eca14c --- /dev/null +++ b/client/src/indexer/mod.rs @@ -0,0 +1 @@ +pub trait Indexer: Sync + Send + Debug + 'static {} diff --git a/client/src/lib.rs b/client/src/lib.rs new file mode 100644 index 0000000000..c3b26435bf --- /dev/null +++ b/client/src/lib.rs @@ -0,0 +1,3 @@ +pub mod rpc; +pub mod rpc_pool; +pub mod transaction_params; diff --git a/forester-utils/src/rpc/errors.rs b/client/src/rpc/errors.rs similarity index 88% rename from forester-utils/src/rpc/errors.rs rename to client/src/rpc/errors.rs index bbf18f346d..722b3ac674 100644 --- a/forester-utils/src/rpc/errors.rs +++ b/client/src/rpc/errors.rs @@ -1,6 +1,6 @@ -use anchor_lang::solana_program::instruction::InstructionError; +use solana_banks_client::BanksClientError; use solana_client::client_error::ClientError; -use solana_program_test::BanksClientError; +use solana_program::instruction::InstructionError; use solana_sdk::transaction::TransactionError; use std::io; use thiserror::Error; @@ -10,9 +10,6 @@ pub enum RpcError { #[error("BanksError: {0}")] BanksError(#[from] BanksClientError), - #[error("ProgramTestError: {0}")] - ProgramTestError(#[from] solana_program_test::ProgramTestError), - #[error("TransactionError: {0}")] TransactionError(#[from] TransactionError), @@ -24,8 +21,13 @@ pub enum RpcError { #[error("Error: `{0}`")] CustomError(String), + #[error("Assert Rpc Error: {0}")] AssertRpcError(String), + + /// The chosen warp slot is not in the future, so warp is not performed + #[error("Warp slot not in the future")] + InvalidWarpSlot, } pub fn assert_rpc_error( diff --git a/forester-utils/src/rpc/mod.rs b/client/src/rpc/mod.rs similarity index 100% rename from forester-utils/src/rpc/mod.rs rename to client/src/rpc/mod.rs diff --git a/forester-utils/src/rpc/rpc_connection.rs b/client/src/rpc/rpc_connection.rs similarity index 93% rename from forester-utils/src/rpc/rpc_connection.rs rename to client/src/rpc/rpc_connection.rs index 1a944f1f4c..1bffdd3480 100644 --- a/forester-utils/src/rpc/rpc_connection.rs +++ b/client/src/rpc/rpc_connection.rs @@ -1,9 +1,9 @@ use crate::rpc::errors::RpcError; use crate::transaction_params::TransactionParams; -use anchor_lang::solana_program::clock::Slot; -use anchor_lang::solana_program::instruction::Instruction; -use anchor_lang::AnchorDeserialize; use async_trait::async_trait; +use borsh::BorshDeserialize; +use solana_program::clock::Slot; +use solana_program::instruction::Instruction; use solana_sdk::account::{Account, AccountSharedData}; use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::epoch_info::EpochInfo; @@ -47,7 +47,7 @@ pub trait RpcConnection: Send + Sync + Debug + 'static { transaction_params: Option, ) -> Result, RpcError> where - T: AnchorDeserialize + Send + Debug; + T: BorshDeserialize + Send + Debug; async fn create_and_send_transaction<'a>( &'a mut self, @@ -71,7 +71,7 @@ pub trait RpcConnection: Send + Sync + Debug + 'static { async fn airdrop_lamports(&mut self, to: &Pubkey, lamports: u64) -> Result; - async fn get_anchor_account( + async fn get_anchor_account( &mut self, pubkey: &Pubkey, ) -> Result, RpcError> { diff --git a/forester-utils/src/rpc/solana_rpc.rs b/client/src/rpc/solana_rpc.rs similarity index 92% rename from forester-utils/src/rpc/solana_rpc.rs rename to client/src/rpc/solana_rpc.rs index a9cabc03ae..746c4acf03 100644 --- a/forester-utils/src/rpc/solana_rpc.rs +++ b/client/src/rpc/solana_rpc.rs @@ -1,23 +1,22 @@ use crate::rpc::errors::RpcError; use crate::rpc::rpc_connection::RpcConnection; use crate::transaction_params::TransactionParams; -use anchor_lang::prelude::Pubkey; -use anchor_lang::solana_program::clock::Slot; -use anchor_lang::solana_program::hash::Hash; -use anchor_lang::AnchorDeserialize; use async_trait::async_trait; +use borsh::BorshDeserialize; use log::warn; use solana_client::rpc_client::RpcClient; use solana_client::rpc_config::{RpcSendTransactionConfig, RpcTransactionConfig}; -use solana_program_test::BanksClientError; +use solana_program::clock::Slot; +use solana_program::hash::Hash; +use solana_program::pubkey::Pubkey; use solana_sdk::account::{Account, AccountSharedData}; use solana_sdk::bs58; use solana_sdk::clock::UnixTimestamp; use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::epoch_info::EpochInfo; -use solana_sdk::instruction::{Instruction, InstructionError}; +use solana_sdk::instruction::Instruction; use solana_sdk::signature::{Keypair, Signature}; -use solana_sdk::transaction::{Transaction, TransactionError}; +use solana_sdk::transaction::Transaction; use solana_transaction_status::option_serializer::OptionSerializer; use solana_transaction_status::{UiInstruction, UiTransactionEncoding}; use std::fmt::{Debug, Display, Formatter}; @@ -125,7 +124,7 @@ impl SolanaRpcConnection { } impl SolanaRpcConnection { - fn parse_inner_instructions( + fn parse_inner_instructions( &self, signature: Signature, ) -> Result { @@ -271,7 +270,7 @@ impl RpcConnection for SolanaRpcConnection { transaction_params: Option, ) -> Result, RpcError> where - T: AnchorDeserialize + Send + Debug, + T: BorshDeserialize + Send + Debug, { let pre_balance = self.client.get_balance(payer)?; let latest_blockhash = self.client.get_latest_blockhash()?; @@ -327,18 +326,7 @@ impl RpcConnection for SolanaRpcConnection { - 5000 * deduped_signers.len() as i64 - network_fee; if post_balance as i64 != expected_post_balance { - println!("transaction_params: {:?}", transaction_params); - println!("pre_balance: {}", pre_balance); - println!("post_balance: {}", post_balance); - println!("expected post_balance: {}", expected_post_balance); - println!( - "diff post_balance: {}", - post_balance as i64 - expected_post_balance - ); - println!("network_fee: {}", network_fee); - return Err(RpcError::from(BanksClientError::TransactionError( - TransactionError::InstructionError(0, InstructionError::Custom(11111)), - ))); + return Err(RpcError::AssertRpcError(format!("unexpected balance after transaction: expected {expected_post_balance}, got {post_balance}"))); } } diff --git a/forester/src/rpc_pool.rs b/client/src/rpc_pool.rs similarity index 97% rename from forester/src/rpc_pool.rs rename to client/src/rpc_pool.rs index 4aedc55d8b..11ae112ae9 100644 --- a/forester/src/rpc_pool.rs +++ b/client/src/rpc_pool.rs @@ -1,11 +1,11 @@ -use crate::RpcConnection; use bb8::{Pool, PooledConnection}; -use forester_utils::rpc::RpcError; use solana_sdk::commitment_config::CommitmentConfig; use std::time::Duration; use thiserror::Error; use tokio::time::sleep; +use crate::rpc::{RpcConnection, RpcError}; + #[derive(Error, Debug)] pub enum PoolError { #[error("Failed to create RPC client: {0}")] diff --git a/forester-utils/src/transaction_params.rs b/client/src/transaction_params.rs similarity index 100% rename from forester-utils/src/transaction_params.rs rename to client/src/transaction_params.rs diff --git a/forester-utils/Cargo.toml b/forester-utils/Cargo.toml index 4b5335428d..7a2618022f 100644 --- a/forester-utils/Cargo.toml +++ b/forester-utils/Cargo.toml @@ -7,6 +7,7 @@ repository = "https://github.com/lightprotocol/light-protocol" description = "Utility library for Light's Forester node implementation" [dependencies] +# Light Protocol account-compression = { path = "../programs/account-compression", version = "1.0.0", features = ["cpi"] } light-compressed-token = { path = "../programs/compressed-token", version = "1.0.0", features = ["cpi"] } light-hash-set = { path = "../merkle-tree/hash-set", version = "1.0.0" } @@ -20,21 +21,33 @@ light-system-program = { path = "../programs/system", version = "1.0.0", feature light-utils = { path = "../utils", version = "1.0.0" } photon-api = { workspace = true } +light-client = { workspace = true } +# Anchor anchor-lang = { workspace = true } anchor-spl = { workspace = true } +# Solana spl-token = { workspace = true, features = ["no-entrypoint"] } solana-program-test = { workspace = true } solana-sdk = { workspace = true } solana-client = { workspace = true } solana-transaction-status = { workspace = true } +# Async ecosystem tokio = { workspace = true } +async-trait = { workspace = true } +# Error handling thiserror = "1.0" + +# Logging log = "0.4" + +# Big numbers num-bigint = "0.4.6" num-traits = "0.2.19" + +# HTTP client reqwest = "0.11.26" -async-trait = "0.1.82" + diff --git a/forester-utils/src/address_merkle_tree_config.rs b/forester-utils/src/address_merkle_tree_config.rs index f736e8f586..3973354c1e 100644 --- a/forester-utils/src/address_merkle_tree_config.rs +++ b/forester-utils/src/address_merkle_tree_config.rs @@ -1,4 +1,3 @@ -use crate::rpc::RpcConnection; use crate::{ get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree, indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}, @@ -8,6 +7,7 @@ use account_compression::{ AddressMerkleTreeAccount, AddressMerkleTreeConfig, AddressQueueConfig, NullifierQueueConfig, QueueAccount, StateMerkleTreeAccount, StateMerkleTreeConfig, }; +use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use num_traits::Zero; use solana_sdk::pubkey::Pubkey; diff --git a/forester-utils/src/forester_epoch.rs b/forester-utils/src/forester_epoch.rs index 234d52aa9d..44a47d8737 100644 --- a/forester-utils/src/forester_epoch.rs +++ b/forester-utils/src/forester_epoch.rs @@ -1,9 +1,9 @@ use std::fmt::Display; // TODO: move into separate forester utils crate -use crate::rpc::{RpcConnection, RpcError}; use anchor_lang::{ prelude::borsh, solana_program::pubkey::Pubkey, AnchorDeserialize, AnchorSerialize, }; +use light_client::rpc::{RpcConnection, RpcError}; use light_registry::{ protocol_config::state::{EpochState, ProtocolConfig}, sdk::{create_register_forester_epoch_pda_instruction, create_report_work_instruction}, diff --git a/forester-utils/src/indexer/mod.rs b/forester-utils/src/indexer/mod.rs index 642dfdb564..f69ee5dbbe 100644 --- a/forester-utils/src/indexer/mod.rs +++ b/forester-utils/src/indexer/mod.rs @@ -2,10 +2,10 @@ use num_bigint::BigUint; use solana_sdk::signature::Keypair; use std::fmt::Debug; -use crate::rpc::RpcConnection; use account_compression::initialize_address_merkle_tree::{ Error as AccountCompressionError, Pubkey, }; +use light_client::rpc::RpcConnection; use light_compressed_token::TokenData; use light_hash_set::HashSetError; use light_hasher::Poseidon; diff --git a/forester-utils/src/lib.rs b/forester-utils/src/lib.rs index 194d00900b..61595d5126 100644 --- a/forester-utils/src/lib.rs +++ b/forester-utils/src/lib.rs @@ -1,7 +1,7 @@ -use crate::rpc::{RpcConnection, RpcError}; use account_compression::initialize_address_merkle_tree::Pubkey; use anchor_lang::solana_program::instruction::Instruction; use anchor_lang::solana_program::system_instruction; +use light_client::rpc::{RpcConnection, RpcError}; use light_concurrent_merkle_tree::copy::ConcurrentMerkleTreeCopy; use light_hash_set::HashSet; use light_hasher::Hasher; @@ -18,8 +18,6 @@ pub mod address_merkle_tree_config; pub mod forester_epoch; pub mod indexer; pub mod registry; -pub mod rpc; -pub mod transaction_params; pub fn create_account_instruction( payer: &Pubkey, diff --git a/forester-utils/src/registry.rs b/forester-utils/src/registry.rs index 4afbb1e615..1426160541 100644 --- a/forester-utils/src/registry.rs +++ b/forester-utils/src/registry.rs @@ -6,7 +6,7 @@ use account_compression::{ }; use crate::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; -use crate::rpc::{RpcConnection, RpcError}; +use light_client::rpc::{RpcConnection, RpcError}; use light_registry::account_compression_cpi::sdk::{ create_rollover_state_merkle_tree_instruction, CreateRolloverMerkleTreeInstructionInputs, }; diff --git a/forester/Cargo.toml b/forester/Cargo.toml index 8c9f92483c..6606aa45c3 100644 --- a/forester/Cargo.toml +++ b/forester/Cargo.toml @@ -44,7 +44,6 @@ crossbeam-channel = "0.5.12" tokio-stream = "0.1.14" base64 = "0.22.0" async-trait = "0.1.81" -bb8 = "0.8.5" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } tracing-appender = "0.2.3" @@ -53,6 +52,7 @@ lazy_static = "1.4" warp = "0.3" dashmap = "6.1.0" scopeguard = "1.2.0" +light-client = { workspace = true } [dev-dependencies] function_name = "0.3.0" diff --git a/forester/src/config.rs b/forester/src/config.rs index 93bc447384..a9106d1291 100644 --- a/forester/src/config.rs +++ b/forester/src/config.rs @@ -1,6 +1,6 @@ use account_compression::utils::constants::{ADDRESS_QUEUE_VALUES, STATE_NULLIFIER_QUEUE_VALUES}; use forester_utils::forester_epoch::{Epoch, TreeAccounts, TreeForesterSchedule}; -use forester_utils::rpc::RetryConfig; +use light_client::rpc::RetryConfig; use light_registry::{EpochPda, ForesterEpochPda}; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::Keypair; diff --git a/forester/src/epoch_manager.rs b/forester/src/epoch_manager.rs index a7c068b39f..04cde7f02f 100644 --- a/forester/src/epoch_manager.rs +++ b/forester/src/epoch_manager.rs @@ -3,7 +3,6 @@ use crate::queue_helpers::QueueItemData; use crate::rollover::{ is_tree_ready_for_rollover, rollover_address_merkle_tree, rollover_state_merkle_tree, }; -use crate::rpc_pool::SolanaRpcPool; use crate::send_transaction::{ send_batched_transactions, BuildTransactionBatchConfig, EpochManagerTransactions, SendBatchedTransactionsConfig, @@ -12,6 +11,7 @@ use crate::slot_tracker::{slot_duration, wait_until_slot_reached, SlotTracker}; use crate::tree_data_sync::fetch_trees; use crate::Result; use crate::{ForesterConfig, ForesterEpochInfo}; +use light_client::rpc_pool::SolanaRpcPool; use crate::metrics::{process_queued_metrics, push_metrics, queue_metric_update}; use crate::tree_finder::TreeFinder; @@ -20,8 +20,8 @@ use forester_utils::forester_epoch::{ get_epoch_phases, Epoch, TreeAccounts, TreeForesterSchedule, TreeType, }; use forester_utils::indexer::{Indexer, MerkleProof, NewAddressProofWithContext}; -use forester_utils::rpc::{RetryConfig, RpcConnection, RpcError}; use futures::future::join_all; +use light_client::rpc::{RetryConfig, RpcConnection, RpcError}; use light_registry::errors::RegistryError; use light_registry::protocol_config::state::ProtocolConfig; use light_registry::sdk::{ diff --git a/forester/src/errors.rs b/forester/src/errors.rs index d5814c77d3..73ddcc42f9 100644 --- a/forester/src/errors.rs +++ b/forester/src/errors.rs @@ -1,8 +1,8 @@ -use crate::rpc_pool::PoolError; use account_compression::initialize_address_merkle_tree::Error as AccountCompressionError; use config::ConfigError; use forester_utils::indexer::IndexerError; -use forester_utils::rpc::errors::RpcError; +use light_client::rpc::errors::RpcError; +use light_client::rpc_pool::PoolError; use light_hash_set::HashSetError; use photon_api::apis::{default_api::GetCompressedAccountProofPostError, Error as PhotonApiError}; use prometheus::Error as PrometheusError; diff --git a/forester/src/lib.rs b/forester/src/lib.rs index 19f02f82d6..842b56514a 100644 --- a/forester/src/lib.rs +++ b/forester/src/lib.rs @@ -9,7 +9,6 @@ pub mod photon_indexer; pub mod pubsub_client; pub mod queue_helpers; pub mod rollover; -pub mod rpc_pool; pub mod send_transaction; pub mod settings; mod slot_tracker; @@ -22,14 +21,14 @@ use crate::epoch_manager::{run_service, WorkReport}; use crate::errors::ForesterError; use crate::metrics::QUEUE_LENGTH; use crate::queue_helpers::fetch_queue_item_data; -use crate::rpc_pool::SolanaRpcPool; use crate::slot_tracker::SlotTracker; use crate::utils::get_protocol_config; use account_compression::utils::constants::{ADDRESS_QUEUE_VALUES, STATE_NULLIFIER_QUEUE_VALUES}; pub use config::{ForesterConfig, ForesterEpochInfo}; use forester_utils::forester_epoch::{TreeAccounts, TreeType}; use forester_utils::indexer::Indexer; -use forester_utils::rpc::{RpcConnection, SolanaRpcConnection}; +use light_client::rpc::{RpcConnection, SolanaRpcConnection}; +use light_client::rpc_pool::SolanaRpcPool; pub use settings::init_config; use solana_sdk::commitment_config::CommitmentConfig; use std::sync::Arc; diff --git a/forester/src/main.rs b/forester/src/main.rs index a83986dff8..d1d7bc88e0 100644 --- a/forester/src/main.rs +++ b/forester/src/main.rs @@ -7,7 +7,7 @@ use forester::telemetry::setup_telemetry; use forester::tree_data_sync::fetch_trees; use forester::{init_config, run_pipeline, run_queue_info}; use forester_utils::forester_epoch::TreeType; -use forester_utils::rpc::{RpcConnection, SolanaRpcConnection}; +use light_client::rpc::{RpcConnection, SolanaRpcConnection}; use std::sync::Arc; use tokio::signal::ctrl_c; use tokio::sync::{mpsc, oneshot}; diff --git a/forester/src/photon_indexer.rs b/forester/src/photon_indexer.rs index 6bcd5a8cdd..9b0e34061c 100644 --- a/forester/src/photon_indexer.rs +++ b/forester/src/photon_indexer.rs @@ -1,7 +1,7 @@ use crate::utils::decode_hash; use account_compression::initialize_address_merkle_tree::Pubkey; use forester_utils::indexer::{Indexer, IndexerError, MerkleProof, NewAddressProofWithContext}; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use photon_api::apis::configuration::{ApiKey, Configuration}; use photon_api::models::{AddressWithTree, GetCompressedAccountsByOwnerPostRequestParams}; use solana_sdk::bs58; diff --git a/forester/src/queue_helpers.rs b/forester/src/queue_helpers.rs index 0cc2514b76..254799c76b 100644 --- a/forester/src/queue_helpers.rs +++ b/forester/src/queue_helpers.rs @@ -1,7 +1,7 @@ use crate::{errors::ForesterError, Result}; use account_compression::initialize_address_merkle_tree::Pubkey; use account_compression::QueueAccount; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use light_hash_set::HashSet; use std::mem; use tracing::debug; diff --git a/forester/src/rollover/operations.rs b/forester/src/rollover/operations.rs index d89fb45385..8910be39f5 100644 --- a/forester/src/rollover/operations.rs +++ b/forester/src/rollover/operations.rs @@ -30,10 +30,10 @@ use forester_utils::indexer::{ AddressMerkleTreeAccounts, Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle, }; use forester_utils::registry::RentExemption; -use forester_utils::rpc::{RpcConnection, RpcError}; use forester_utils::{ create_account_instruction, get_concurrent_merkle_tree, get_indexed_merkle_tree, }; +use light_client::rpc::{RpcConnection, RpcError}; use light_hasher::Poseidon; use light_merkle_tree_reference::MerkleTree; diff --git a/forester/src/send_transaction.rs b/forester/src/send_transaction.rs index 8ea510bf23..e3b7be9d25 100644 --- a/forester/src/send_transaction.rs +++ b/forester/src/send_transaction.rs @@ -2,7 +2,6 @@ use crate::config::QueueConfig; use crate::epoch_manager::{MerkleProofType, WorkItem}; use crate::errors::ForesterError; use crate::queue_helpers::fetch_queue_item_data; -use crate::rpc_pool::SolanaRpcPool; use crate::Result; use account_compression::utils::constants::{ ADDRESS_MERKLE_TREE_CHANGELOG, ADDRESS_MERKLE_TREE_INDEXED_CHANGELOG, ADDRESS_QUEUE_VALUES, @@ -11,8 +10,9 @@ use account_compression::utils::constants::{ use async_trait::async_trait; use forester_utils::forester_epoch::{TreeAccounts, TreeType}; use forester_utils::indexer::Indexer; -use forester_utils::rpc::{RetryConfig, RpcConnection, SolanaRpcConnection}; use futures::future::join_all; +use light_client::rpc::{RetryConfig, RpcConnection, SolanaRpcConnection}; +use light_client::rpc_pool::SolanaRpcPool; use light_registry::account_compression_cpi::sdk::{ create_nullify_instruction, create_update_address_merkle_tree_instruction, CreateNullifyInstructionInputs, UpdateAddressMerkleTreeInstructionInputs, diff --git a/forester/src/settings.rs b/forester/src/settings.rs index 9446256926..68e65c0bb8 100644 --- a/forester/src/settings.rs +++ b/forester/src/settings.rs @@ -4,7 +4,7 @@ use crate::ForesterConfig; use account_compression::initialize_address_merkle_tree::Pubkey; use anchor_lang::Id; use config::{Config, Environment}; -use forester_utils::rpc::RetryConfig; +use light_client::rpc::RetryConfig; use solana_sdk::signature::{Keypair, Signer}; use std::fmt::{Display, Formatter}; use std::path::Path; diff --git a/forester/src/slot_tracker.rs b/forester/src/slot_tracker.rs index fd38e7583c..9578c09805 100644 --- a/forester/src/slot_tracker.rs +++ b/forester/src/slot_tracker.rs @@ -1,4 +1,4 @@ -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::UNIX_EPOCH; use std::{sync::Arc, time::SystemTime}; diff --git a/forester/src/tree_data_sync.rs b/forester/src/tree_data_sync.rs index 101e165e36..730948ecae 100644 --- a/forester/src/tree_data_sync.rs +++ b/forester/src/tree_data_sync.rs @@ -3,7 +3,7 @@ use account_compression::utils::check_discrimininator::check_discriminator; use account_compression::{AddressMerkleTreeAccount, MerkleTreeMetadata, StateMerkleTreeAccount}; use borsh::BorshDeserialize; use forester_utils::forester_epoch::{TreeAccounts, TreeType}; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use solana_sdk::account::Account; use solana_sdk::pubkey::Pubkey; use tracing::debug; diff --git a/forester/src/tree_finder.rs b/forester/src/tree_finder.rs index 6991582c5d..9af21c1312 100644 --- a/forester/src/tree_finder.rs +++ b/forester/src/tree_finder.rs @@ -1,8 +1,8 @@ use crate::errors::ForesterError; -use crate::rpc_pool::SolanaRpcPool; use crate::tree_data_sync::fetch_trees; use forester_utils::forester_epoch::TreeAccounts; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; +use light_client::rpc_pool::SolanaRpcPool; use std::sync::Arc; use tokio::sync::broadcast; use tokio::time::{interval, Duration}; diff --git a/forester/src/utils.rs b/forester/src/utils.rs index 9051463ebb..0f77604afb 100644 --- a/forester/src/utils.rs +++ b/forester/src/utils.rs @@ -1,4 +1,4 @@ -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use light_registry::protocol_config::state::{ProtocolConfig, ProtocolConfigPda}; use light_registry::utils::get_protocol_config_pda_address; use std::process::Command; diff --git a/forester/tests/e2e_test.rs b/forester/tests/e2e_test.rs index ebac0e895c..891d324e3d 100644 --- a/forester/tests/e2e_test.rs +++ b/forester/tests/e2e_test.rs @@ -1,13 +1,13 @@ use account_compression::utils::constants::{ADDRESS_QUEUE_VALUES, STATE_NULLIFIER_QUEUE_VALUES}; use account_compression::AddressMerkleTreeAccount; use forester::queue_helpers::fetch_queue_item_data; -use forester::rpc_pool::SolanaRpcPool; use forester::run_pipeline; use forester::utils::{get_protocol_config, LightValidatorConfig}; use forester_utils::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts}; use forester_utils::registry::register_test_forester; -use forester_utils::rpc::solana_rpc::SolanaRpcUrl; -use forester_utils::rpc::{RpcConnection, RpcError, SolanaRpcConnection}; +use light_client::rpc::solana_rpc::SolanaRpcUrl; +use light_client::rpc::{RpcConnection, RpcError, SolanaRpcConnection}; +use light_client::rpc_pool::SolanaRpcPool; use light_registry::utils::{get_epoch_pda_address, get_forester_epoch_pda_from_authority}; use light_registry::{EpochPda, ForesterEpochPda}; use light_test_utils::e2e_test_env::E2ETestEnv; diff --git a/forester/tests/test_utils.rs b/forester/tests/test_utils.rs index e9c11dd8fd..eb72ceae14 100644 --- a/forester/tests/test_utils.rs +++ b/forester/tests/test_utils.rs @@ -6,7 +6,7 @@ use forester::telemetry::setup_telemetry; use forester::utils::{spawn_validator, LightValidatorConfig}; use forester::ForesterConfig; use forester_utils::indexer::{Indexer, IndexerError, NewAddressProofWithContext}; -use forester_utils::rpc::{RpcConnection, SolanaRpcConnection}; +use light_client::rpc::{RpcConnection, SolanaRpcConnection}; use light_test_utils::e2e_test_env::{GeneralActionConfig, KeypairActionConfig, User}; use light_test_utils::indexer::TestIndexer; use light_test_utils::test_env::get_test_env_accounts; diff --git a/test-utils/Cargo.toml b/test-utils/Cargo.toml index 18080ec4f1..1b9f37056b 100644 --- a/test-utils/Cargo.toml +++ b/test-utils/Cargo.toml @@ -44,6 +44,7 @@ photon-api = { workspace = true } log = "0.4" serde = { version = "1.0.197", features = ["derive"] } async-trait = "0.1.82" +light-client = { workspace = true } [dev-dependencies] rand = "0.8" diff --git a/test-utils/src/address_tree_rollover.rs b/test-utils/src/address_tree_rollover.rs index 943cefda59..c90ac62982 100644 --- a/test-utils/src/address_tree_rollover.rs +++ b/test-utils/src/address_tree_rollover.rs @@ -25,8 +25,8 @@ use forester_utils::registry::{ create_rollover_address_merkle_tree_instructions, create_rollover_state_merkle_tree_instructions, }; -use forester_utils::rpc::{RpcConnection, RpcError}; use forester_utils::{create_account_instruction, get_hash_set, get_indexed_merkle_tree}; +use light_client::rpc::{RpcConnection, RpcError}; use light_hasher::Poseidon; use light_indexed_merkle_tree::zero_copy::IndexedMerkleTreeZeroCopyMut; diff --git a/test-utils/src/assert_address_merkle_tree.rs b/test-utils/src/assert_address_merkle_tree.rs index f66b29f2d7..3900ccd0d5 100644 --- a/test-utils/src/assert_address_merkle_tree.rs +++ b/test-utils/src/assert_address_merkle_tree.rs @@ -1,5 +1,5 @@ -use forester_utils::rpc::RpcConnection; use forester_utils::{get_indexed_merkle_tree, AccountZeroCopy}; +use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use solana_sdk::pubkey::Pubkey; diff --git a/test-utils/src/assert_compressed_tx.rs b/test-utils/src/assert_compressed_tx.rs index b30b10fa4c..c84fb16cd2 100644 --- a/test-utils/src/assert_compressed_tx.rs +++ b/test-utils/src/assert_compressed_tx.rs @@ -1,7 +1,7 @@ use account_compression::{state::QueueAccount, StateMerkleTreeAccount}; use forester_utils::indexer::{Indexer, StateMerkleTreeAccounts}; -use forester_utils::rpc::RpcConnection; use forester_utils::{get_concurrent_merkle_tree, get_hash_set, AccountZeroCopy}; +use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use light_system_program::sdk::event::MerkleTreeSequenceNumber; use light_system_program::sdk::{ diff --git a/test-utils/src/assert_epoch.rs b/test-utils/src/assert_epoch.rs index 0856fe638f..a012e694c2 100644 --- a/test-utils/src/assert_epoch.rs +++ b/test-utils/src/assert_epoch.rs @@ -1,4 +1,4 @@ -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use light_registry::{ protocol_config::state::ProtocolConfigPda, utils::{get_epoch_pda_address, get_forester_pda, get_protocol_config_pda_address}, diff --git a/test-utils/src/assert_merkle_tree.rs b/test-utils/src/assert_merkle_tree.rs index 1729a0b671..2db42ffa3d 100644 --- a/test-utils/src/assert_merkle_tree.rs +++ b/test-utils/src/assert_merkle_tree.rs @@ -1,6 +1,6 @@ use account_compression::StateMerkleTreeAccount; -use forester_utils::rpc::RpcConnection; use forester_utils::{get_concurrent_merkle_tree, AccountZeroCopy}; +use light_client::rpc::RpcConnection; use light_hasher::Poseidon; use light_utils::fee::compute_rollover_fee; use solana_sdk::pubkey::Pubkey; diff --git a/test-utils/src/assert_queue.rs b/test-utils/src/assert_queue.rs index 6490db7bb2..138b749095 100644 --- a/test-utils/src/assert_queue.rs +++ b/test-utils/src/assert_queue.rs @@ -1,6 +1,6 @@ use account_compression::{QueueAccount, QueueMetadata, QueueType, RolloverMetadata}; -use forester_utils::rpc::RpcConnection; use forester_utils::{get_hash_set, AccountZeroCopy}; +use light_client::rpc::RpcConnection; use light_utils::fee::compute_rollover_fee; use solana_sdk::pubkey::Pubkey; diff --git a/test-utils/src/assert_token_tx.rs b/test-utils/src/assert_token_tx.rs index 4e04021940..6dba2dc066 100644 --- a/test-utils/src/assert_token_tx.rs +++ b/test-utils/src/assert_token_tx.rs @@ -4,7 +4,7 @@ use crate::assert_compressed_tx::{ }; use anchor_lang::AnchorSerialize; use forester_utils::indexer::{Indexer, TokenDataWithContext}; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::RpcConnection; use light_compressed_token::{ get_token_pool_pda, process_transfer::{get_cpi_authority_pda, TokenTransferOutputData}, diff --git a/test-utils/src/e2e_test_env.rs b/test-utils/src/e2e_test_env.rs index c2266f36ea..7c9a9e8947 100644 --- a/test-utils/src/e2e_test_env.rs +++ b/test-utils/src/e2e_test_env.rs @@ -132,9 +132,9 @@ use light_utils::bigint::bigint_to_be_bytes_array; use light_utils::rand::gen_prime; use crate::indexer::TestIndexer; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; -use forester_utils::transaction_params::{FeeConfig, TransactionParams}; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; +use light_client::transaction_params::{FeeConfig, TransactionParams}; pub struct User { pub keypair: Keypair, diff --git a/test-utils/src/indexer/test_indexer.rs b/test-utils/src/indexer/test_indexer.rs index 1eeef3b7bd..e2bd3a884b 100644 --- a/test-utils/src/indexer/test_indexer.rs +++ b/test-utils/src/indexer/test_indexer.rs @@ -17,9 +17,9 @@ use forester_utils::indexer::{ NewAddressProofWithContext, ProofRpcResult, StateMerkleTreeAccounts, StateMerkleTreeBundle, TokenDataWithContext, }; -use forester_utils::rpc::RpcConnection; -use forester_utils::transaction_params::FeeConfig; use forester_utils::{get_concurrent_merkle_tree, get_indexed_merkle_tree}; +use light_client::rpc::RpcConnection; +use light_client::transaction_params::FeeConfig; use light_compressed_token::constants::TOKEN_COMPRESSED_ACCOUNT_DISCRIMINATOR; use light_compressed_token::mint_sdk::create_create_token_pool_instruction; use light_compressed_token::{get_token_pool_pda, TokenData}; diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 8cffefabc4..c4d4de26bb 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -30,11 +30,14 @@ pub use forester_utils::{ create_rollover_state_merkle_tree_instructions, register_test_forester, update_test_forester, }, - rpc::solana_rpc::SolanaRpcUrl, - rpc::{assert_rpc_error, RpcConnection, RpcError, SolanaRpcConnection}, - transaction_params::{FeeConfig, TransactionParams}, AccountZeroCopy, }; +pub use light_client::{ + rpc::{ + assert_rpc_error, solana_rpc::SolanaRpcUrl, RpcConnection, RpcError, SolanaRpcConnection, + }, + transaction_params::{FeeConfig, TransactionParams}, +}; /// Asserts that the given `BanksTransactionResultWithMetadata` is an error with a custom error code /// or a program error. diff --git a/test-utils/src/rpc/test_rpc.rs b/test-utils/src/rpc/test_rpc.rs index 7e8e2b8bc0..2046807d8f 100644 --- a/test-utils/src/rpc/test_rpc.rs +++ b/test-utils/src/rpc/test_rpc.rs @@ -15,9 +15,9 @@ use solana_sdk::signature::{Keypair, Signature}; use solana_sdk::signer::Signer; use solana_sdk::transaction::{Transaction, TransactionError}; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; -use forester_utils::transaction_params::TransactionParams; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; +use light_client::transaction_params::TransactionParams; pub struct ProgramTestRpcConnection { pub context: ProgramTestContext, @@ -295,7 +295,9 @@ impl RpcConnection for ProgramTestRpcConnection { } async fn warp_to_slot(&mut self, slot: Slot) -> Result<(), RpcError> { - self.context.warp_to_slot(slot).map_err(RpcError::from) + self.context + .warp_to_slot(slot) + .map_err(|_| RpcError::InvalidWarpSlot) } async fn send_transaction(&self, _transaction: &Transaction) -> Result { diff --git a/test-utils/src/spl.rs b/test-utils/src/spl.rs index cbdfb72a91..1f2a51c240 100644 --- a/test-utils/src/spl.rs +++ b/test-utils/src/spl.rs @@ -32,9 +32,9 @@ use crate::{ assert_compressed_tx::get_merkle_tree_snapshots, assert_token_tx::{assert_create_mint, assert_mint_to, assert_transfer}, }; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; -use forester_utils::transaction_params::TransactionParams; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; +use light_client::transaction_params::TransactionParams; pub async fn mint_tokens_helper>( rpc: &mut R, diff --git a/test-utils/src/state_tree_rollover.rs b/test-utils/src/state_tree_rollover.rs index d6288e9a38..e6e7088f1a 100644 --- a/test-utils/src/state_tree_rollover.rs +++ b/test-utils/src/state_tree_rollover.rs @@ -10,9 +10,9 @@ use account_compression::{ StateMerkleTreeAccount, StateMerkleTreeConfig, ID, }; use anchor_lang::{InstructionData, Lamports, ToAccountMetas}; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; use forester_utils::{create_account_instruction, get_hash_set}; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; use light_concurrent_merkle_tree::{ copy::ConcurrentMerkleTreeCopy, zero_copy::ConcurrentMerkleTreeZeroCopyMut, }; diff --git a/test-utils/src/system_program.rs b/test-utils/src/system_program.rs index 1e61d7aea0..b47c06b402 100644 --- a/test-utils/src/system_program.rs +++ b/test-utils/src/system_program.rs @@ -20,9 +20,9 @@ use solana_sdk::{ use crate::assert_compressed_tx::{ assert_compressed_transaction, get_merkle_tree_snapshots, AssertCompressedTransactionInputs, }; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; -use forester_utils::transaction_params::TransactionParams; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; +use light_client::transaction_params::TransactionParams; #[allow(clippy::too_many_arguments)] pub async fn create_addresses_test>( diff --git a/test-utils/src/test_env.rs b/test-utils/src/test_env.rs index 844003c221..5c027a8bbe 100644 --- a/test-utils/src/test_env.rs +++ b/test-utils/src/test_env.rs @@ -11,10 +11,10 @@ use account_compression::{AddressMerkleTreeConfig, AddressQueueConfig, QueueType use account_compression::{NullifierQueueConfig, StateMerkleTreeConfig}; use forester_utils::forester_epoch::{Epoch, TreeAccounts, TreeType}; use forester_utils::registry::register_test_forester; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::solana_rpc::SolanaRpcUrl; -use forester_utils::rpc::{RpcConnection, SolanaRpcConnection}; use forester_utils::{airdrop_lamports, create_account_instruction}; +use light_client::rpc::errors::RpcError; +use light_client::rpc::solana_rpc::SolanaRpcUrl; +use light_client::rpc::{RpcConnection, SolanaRpcConnection}; use light_hasher::Poseidon; use light_macros::pubkey; use light_registry::account_compression_cpi::sdk::get_registered_program_pda; @@ -900,7 +900,7 @@ pub async fn deregister_program_with_registry_program( governance_authority: &Keypair, group_pda: &Pubkey, program_id_keypair: &Keypair, -) -> Result { +) -> Result { let governance_authority_pda = get_protocol_config_pda_address(); let (instruction, token_program_registered_program_pda) = create_deregister_program_instruction( governance_authority.pubkey(), diff --git a/test-utils/src/test_forester.rs b/test-utils/src/test_forester.rs index e5f558ea17..d9a17d3ad3 100644 --- a/test-utils/src/test_forester.rs +++ b/test-utils/src/test_forester.rs @@ -8,8 +8,8 @@ use account_compression::{instruction::InsertAddresses, StateMerkleTreeAccount, use account_compression::{AddressMerkleTreeAccount, SAFETY_MARGIN}; use anchor_lang::system_program; use anchor_lang::{InstructionData, ToAccountMetas}; -use forester_utils::rpc::errors::RpcError; -use forester_utils::rpc::RpcConnection; +use light_client::rpc::errors::RpcError; +use light_client::rpc::RpcConnection; use light_concurrent_merkle_tree::event::MerkleTreeEvent; use light_hasher::Poseidon; use light_indexed_merkle_tree::copy::IndexedMerkleTreeCopy;