From 48e8cf5767d8ac19dc51d1a7b274181de99fb9dc Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Sat, 7 Dec 2024 01:45:48 -0500 Subject: [PATCH] A benchmark suite for the `getTokenAccountsByDelgate` RPC call (#3967) --- accounts-cluster-bench/src/main.rs | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 81dba8f8b85182..ed0581afcbbe5d 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -176,6 +176,17 @@ fn make_create_message( ) .unwrap(), ); + instructions.push( + spl_token::instruction::approve( + &spl_token::id(), + &to_pubkey, + &base_keypair.pubkey(), + &base_keypair.pubkey(), + &[&base_keypair.pubkey()], + 1, + ) + .unwrap(), + ); } instructions @@ -243,6 +254,7 @@ pub enum RpcBench { MultipleAccounts, ProgramAccounts, TokenAccountsByOwner, + TokenAccountsByDelegate, } #[derive(Debug)] @@ -257,6 +269,7 @@ impl FromStr for RpcBench { match s { "slot" => Ok(RpcBench::Slot), "multiple-accounts" => Ok(RpcBench::MultipleAccounts), + "token-accounts-by-delegate" => Ok(RpcBench::TokenAccountsByDelegate), "token-accounts-by-owner" => Ok(RpcBench::TokenAccountsByOwner), "version" => Ok(RpcBench::Version), _ => Err(RpcParseError::InvalidOption), @@ -427,6 +440,26 @@ fn run_rpc_bench_loop( } } } + RpcBench::TokenAccountsByDelegate => { + let mut rpc_time = Measure::start("rpc-get-token-accounts-by-delegate"); + let filter = TokenAccountsFilter::Mint(*mint.as_ref().unwrap()); + match client.get_token_accounts_by_delegate(base_keypair_pubkey, filter) { + Ok(_accounts) => { + rpc_time.stop(); + stats.success += 1; + stats.total_success_time_us += rpc_time.as_us(); + } + Err(e) => { + rpc_time.stop(); + stats.errors += 1; + stats.total_errors_time_us += rpc_time.as_us(); + if last_error.elapsed().as_secs() > 2 { + info!("get-token-accounts-by-delegate error: {:?}", e); + last_error = Instant::now(); + } + } + } + } RpcBench::TokenAccountsByOwner => { let mut rpc_time = Measure::start("rpc-get-token-accounts-by-owner"); let filter = TokenAccountsFilter::Mint(*mint.as_ref().unwrap()); @@ -441,7 +474,7 @@ fn run_rpc_bench_loop( stats.errors += 1; stats.total_errors_time_us += rpc_time.as_us(); if last_error.elapsed().as_secs() > 2 { - info!("get-token-accounts error: {:?}", e); + info!("get-token-accounts-by-owner error: {:?}", e); last_error = Instant::now(); } }