From c6bd3883466e72771d14dc5f6d4aaa6edd386698 Mon Sep 17 00:00:00 2001 From: kirill lykov Date: Thu, 7 Mar 2024 12:51:44 -0800 Subject: [PATCH] Add get_blocks and get_slot methods to bench-tps-client (#94) * add get_block(s)/slot methods to BenchTpsClient * Update Cargo.lock * add commitment level for get_slot/blocks --- Cargo.lock | 1 + bench-tps/Cargo.toml | 1 + bench-tps/src/bench_tps_client.rs | 22 +++++++++++-- bench-tps/src/bench_tps_client/bank_client.rs | 24 ++++++++++++++ bench-tps/src/bench_tps_client/rpc_client.rs | 27 +++++++++++++++- bench-tps/src/bench_tps_client/thin_client.rs | 30 +++++++++++++++++ bench-tps/src/bench_tps_client/tpu_client.rs | 32 ++++++++++++++++++- 7 files changed, 132 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85641aff1..b0b181a04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5590,6 +5590,7 @@ dependencies = [ "solana-test-validator", "solana-thin-client", "solana-tpu-client", + "solana-transaction-status", "solana-version", "spl-instruction-padding", "tempfile", diff --git a/bench-tps/Cargo.toml b/bench-tps/Cargo.toml index cd40eb1c8..2fc48c9e2 100644 --- a/bench-tps/Cargo.toml +++ b/bench-tps/Cargo.toml @@ -37,6 +37,7 @@ solana-sdk = { workspace = true } solana-streamer = { workspace = true } solana-thin-client = { workspace = true } solana-tpu-client = { workspace = true } +solana-transaction-status = { workspace = true } solana-version = { workspace = true } spl-instruction-padding = { workspace = true } thiserror = { workspace = true } diff --git a/bench-tps/src/bench_tps_client.rs b/bench-tps/src/bench_tps_client.rs index 3ab15bec1..0715d7398 100644 --- a/bench-tps/src/bench_tps_client.rs +++ b/bench-tps/src/bench_tps_client.rs @@ -1,11 +1,12 @@ use { - solana_rpc_client_api::client_error::Error as ClientError, + solana_rpc_client_api::{client_error::Error as ClientError, config::RpcBlockConfig}, solana_sdk::{ account::Account, commitment_config::CommitmentConfig, epoch_info::EpochInfo, hash::Hash, - message::Message, pubkey::Pubkey, signature::Signature, transaction::Transaction, - transport::TransportError, + message::Message, pubkey::Pubkey, signature::Signature, slot_history::Slot, + transaction::Transaction, transport::TransportError, }, solana_tpu_client::tpu_client::TpuSenderError, + solana_transaction_status::UiConfirmedBlock, thiserror::Error, }; @@ -93,6 +94,21 @@ pub trait BenchTpsClient { ) -> Result; fn get_multiple_accounts(&self, pubkeys: &[Pubkey]) -> Result>>; + + fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result; + + fn get_blocks_with_commitment( + &self, + start_slot: Slot, + end_slot: Option, + commitment_config: CommitmentConfig, + ) -> Result>; + + fn get_block_with_config( + &self, + slot: Slot, + rpc_block_config: RpcBlockConfig, + ) -> Result; } mod bank_client; diff --git a/bench-tps/src/bench_tps_client/bank_client.rs b/bench-tps/src/bench_tps_client/bank_client.rs index 1aef7284c..3ea9080e5 100644 --- a/bench-tps/src/bench_tps_client/bank_client.rs +++ b/bench-tps/src/bench_tps_client/bank_client.rs @@ -1,5 +1,6 @@ use { crate::bench_tps_client::{BenchTpsClient, BenchTpsError, Result}, + solana_rpc_client_api::config::RpcBlockConfig, solana_runtime::bank_client::BankClient, solana_sdk::{ account::Account, @@ -10,8 +11,10 @@ use { message::Message, pubkey::Pubkey, signature::Signature, + slot_history::Slot, transaction::Transaction, }, + solana_transaction_status::UiConfirmedBlock, }; impl BenchTpsClient for BankClient { @@ -111,4 +114,25 @@ impl BenchTpsClient for BankClient { fn get_multiple_accounts(&self, _pubkeys: &[Pubkey]) -> Result>> { unimplemented!("BankClient doesn't support get_multiple_accounts"); } + + fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result { + SyncClient::get_slot_with_commitment(self, commitment_config).map_err(|err| err.into()) + } + + fn get_blocks_with_commitment( + &self, + _start_slot: Slot, + _end_slot: Option, + _commitment_config: CommitmentConfig, + ) -> Result> { + unimplemented!("BankClient doesn't support get_blocks"); + } + + fn get_block_with_config( + &self, + _slot: Slot, + _rpc_block_config: RpcBlockConfig, + ) -> Result { + unimplemented!("BankClient doesn't support get_block_with_config"); + } } diff --git a/bench-tps/src/bench_tps_client/rpc_client.rs b/bench-tps/src/bench_tps_client/rpc_client.rs index 2535099b4..87ec1b869 100644 --- a/bench-tps/src/bench_tps_client/rpc_client.rs +++ b/bench-tps/src/bench_tps_client/rpc_client.rs @@ -1,10 +1,13 @@ use { crate::bench_tps_client::{BenchTpsClient, BenchTpsError, Result}, solana_rpc_client::rpc_client::RpcClient, + solana_rpc_client_api::config::RpcBlockConfig, solana_sdk::{ account::Account, commitment_config::CommitmentConfig, epoch_info::EpochInfo, hash::Hash, - message::Message, pubkey::Pubkey, signature::Signature, transaction::Transaction, + message::Message, pubkey::Pubkey, signature::Signature, slot_history::Slot, + transaction::Transaction, }, + solana_transaction_status::UiConfirmedBlock, }; impl BenchTpsClient for RpcClient { @@ -104,4 +107,26 @@ impl BenchTpsClient for RpcClient { fn get_multiple_accounts(&self, pubkeys: &[Pubkey]) -> Result>> { RpcClient::get_multiple_accounts(self, pubkeys).map_err(|err| err.into()) } + + fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result { + RpcClient::get_slot_with_commitment(self, commitment_config).map_err(|err| err.into()) + } + + fn get_blocks_with_commitment( + &self, + start_slot: Slot, + end_slot: Option, + commitment_config: CommitmentConfig, + ) -> Result> { + RpcClient::get_blocks_with_commitment(self, start_slot, end_slot, commitment_config) + .map_err(|err| err.into()) + } + + fn get_block_with_config( + &self, + slot: Slot, + rpc_block_config: RpcBlockConfig, + ) -> Result { + RpcClient::get_block_with_config(self, slot, rpc_block_config).map_err(|err| err.into()) + } } diff --git a/bench-tps/src/bench_tps_client/thin_client.rs b/bench-tps/src/bench_tps_client/thin_client.rs index 6696774d6..22945c449 100644 --- a/bench-tps/src/bench_tps_client/thin_client.rs +++ b/bench-tps/src/bench_tps_client/thin_client.rs @@ -1,6 +1,7 @@ use { crate::bench_tps_client::{BenchTpsClient, BenchTpsError, Result}, solana_client::thin_client::ThinClient, + solana_rpc_client_api::config::RpcBlockConfig, solana_sdk::{ account::Account, client::{AsyncClient, Client, SyncClient}, @@ -10,8 +11,10 @@ use { message::Message, pubkey::Pubkey, signature::Signature, + slot_history::Slot, transaction::Transaction, }, + solana_transaction_status::UiConfirmedBlock, }; impl BenchTpsClient for ThinClient { @@ -110,4 +113,31 @@ impl BenchTpsClient for ThinClient { .get_multiple_accounts(pubkeys) .map_err(|err| err.into()) } + + fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result { + self.rpc_client() + .get_slot_with_commitment(commitment_config) + .map_err(|err| err.into()) + } + + fn get_blocks_with_commitment( + &self, + start_slot: Slot, + end_slot: Option, + commitment_config: CommitmentConfig, + ) -> Result> { + self.rpc_client() + .get_blocks_with_commitment(start_slot, end_slot, commitment_config) + .map_err(|err| err.into()) + } + + fn get_block_with_config( + &self, + slot: Slot, + rpc_block_config: RpcBlockConfig, + ) -> Result { + self.rpc_client() + .get_block_with_config(slot, rpc_block_config) + .map_err(|err| err.into()) + } } diff --git a/bench-tps/src/bench_tps_client/tpu_client.rs b/bench-tps/src/bench_tps_client/tpu_client.rs index c56da2ae6..6c053271a 100644 --- a/bench-tps/src/bench_tps_client/tpu_client.rs +++ b/bench-tps/src/bench_tps_client/tpu_client.rs @@ -4,10 +4,13 @@ use { solana_connection_cache::connection_cache::{ ConnectionManager, ConnectionPool, NewConnectionConfig, }, + solana_rpc_client_api::config::RpcBlockConfig, solana_sdk::{ account::Account, commitment_config::CommitmentConfig, epoch_info::EpochInfo, hash::Hash, - message::Message, pubkey::Pubkey, signature::Signature, transaction::Transaction, + message::Message, pubkey::Pubkey, signature::Signature, slot_history::Slot, + transaction::Transaction, }, + solana_transaction_status::UiConfirmedBlock, }; impl BenchTpsClient for TpuClient @@ -130,4 +133,31 @@ where .get_multiple_accounts(pubkeys) .map_err(|err| err.into()) } + + fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result { + self.rpc_client() + .get_slot_with_commitment(commitment_config) + .map_err(|err| err.into()) + } + + fn get_blocks_with_commitment( + &self, + start_slot: Slot, + end_slot: Option, + commitment_config: CommitmentConfig, + ) -> Result> { + self.rpc_client() + .get_blocks_with_commitment(start_slot, end_slot, commitment_config) + .map_err(|err| err.into()) + } + + fn get_block_with_config( + &self, + slot: Slot, + rpc_block_config: RpcBlockConfig, + ) -> Result { + self.rpc_client() + .get_block_with_config(slot, rpc_block_config) + .map_err(|err| err.into()) + } }