From 1492119857df939f236354d71f7182127d11eca4 Mon Sep 17 00:00:00 2001 From: Andrei Silviu Dragnea Date: Fri, 16 Aug 2024 17:30:12 +0100 Subject: [PATCH] refactor: use less &mut self and more async-await in BanksClient (#2591) * refactor: use less &mut self in BanksClient * refactor: use async-await syntax instead of explicit Futures --- banks-client/src/lib.rs | 321 ++++++++++++----------- program-test/tests/bpf.rs | 2 +- program-test/tests/builtins.rs | 4 +- program-test/tests/compute_units.rs | 2 +- program-test/tests/core_bpf.rs | 2 +- program-test/tests/cpi.rs | 8 +- program-test/tests/genesis_accounts.rs | 2 +- program-test/tests/lamports.rs | 2 +- program-test/tests/realloc.rs | 2 +- program-test/tests/return_data.rs | 4 +- program-test/tests/spl.rs | 4 +- tpu-client/src/nonblocking/tpu_client.rs | 7 +- 12 files changed, 189 insertions(+), 171 deletions(-) diff --git a/banks-client/src/lib.rs b/banks-client/src/lib.rs index aae81192d3a07b..125aceefa89f89 100644 --- a/banks-client/src/lib.rs +++ b/banks-client/src/lib.rs @@ -11,7 +11,7 @@ pub use { }; use { borsh::BorshDeserialize, - futures::{future::join_all, Future, FutureExt, TryFutureExt}, + futures::future::join_all, solana_banks_interface::{ BanksRequest, BanksResponse, BanksTransactionResultWithMetadata, BanksTransactionResultWithSimulation, @@ -58,175 +58,185 @@ impl BanksClient { TarpcClient::new(config, transport) } - pub fn send_transaction_with_context( - &mut self, + pub async fn send_transaction_with_context( + &self, ctx: Context, transaction: impl Into, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { self.inner .send_transaction_with_context(ctx, transaction.into()) + .await .map_err(Into::into) } - pub fn get_transaction_status_with_context( - &mut self, + pub async fn get_transaction_status_with_context( + &self, ctx: Context, signature: Signature, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.inner .get_transaction_status_with_context(ctx, signature) + .await .map_err(Into::into) } - pub fn get_slot_with_context( - &mut self, + pub async fn get_slot_with_context( + &self, ctx: Context, commitment: CommitmentLevel, - ) -> impl Future> + '_ { + ) -> Result { self.inner .get_slot_with_context(ctx, commitment) + .await .map_err(Into::into) } - pub fn get_block_height_with_context( - &mut self, + pub async fn get_block_height_with_context( + &self, ctx: Context, commitment: CommitmentLevel, - ) -> impl Future> + '_ { + ) -> Result { self.inner .get_block_height_with_context(ctx, commitment) + .await .map_err(Into::into) } - pub fn process_transaction_with_commitment_and_context( - &mut self, + pub async fn process_transaction_with_commitment_and_context( + &self, ctx: Context, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future>, BanksClientError>> + '_ { + ) -> Result>, BanksClientError> { self.inner .process_transaction_with_commitment_and_context(ctx, transaction.into(), commitment) + .await .map_err(Into::into) } - pub fn process_transaction_with_preflight_and_commitment_and_context( - &mut self, + pub async fn process_transaction_with_preflight_and_commitment_and_context( + &self, ctx: Context, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future> + '_ - { + ) -> Result { self.inner .process_transaction_with_preflight_and_commitment_and_context( ctx, transaction.into(), commitment, ) + .await .map_err(Into::into) } - pub fn process_transaction_with_metadata_and_context( - &mut self, + pub async fn process_transaction_with_metadata_and_context( + &self, ctx: Context, transaction: impl Into, - ) -> impl Future> + '_ - { + ) -> Result { self.inner .process_transaction_with_metadata_and_context(ctx, transaction.into()) + .await .map_err(Into::into) } - pub fn simulate_transaction_with_commitment_and_context( - &mut self, + pub async fn simulate_transaction_with_commitment_and_context( + &self, ctx: Context, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future> + '_ - { + ) -> Result { self.inner .simulate_transaction_with_commitment_and_context(ctx, transaction.into(), commitment) + .await .map_err(Into::into) } - pub fn get_account_with_commitment_and_context( - &mut self, + pub async fn get_account_with_commitment_and_context( + &self, ctx: Context, address: Pubkey, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.inner .get_account_with_commitment_and_context(ctx, address, commitment) + .await .map_err(Into::into) } /// Send a transaction and return immediately. The server will resend the /// transaction until either it is accepted by the cluster or the transaction's /// blockhash expires. - pub fn send_transaction( - &mut self, + pub async fn send_transaction( + &self, transaction: impl Into, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { self.send_transaction_with_context(context::current(), transaction.into()) + .await } /// Return the cluster Sysvar - pub fn get_sysvar( - &mut self, - ) -> impl Future> + '_ { - self.get_account(T::id()).map(|result| { - let sysvar = result?.ok_or(BanksClientError::ClientError("Sysvar not present"))?; - from_account::(&sysvar).ok_or(BanksClientError::ClientError( - "Failed to deserialize sysvar", - )) - }) + pub async fn get_sysvar(&self) -> Result { + let sysvar = self + .get_account(T::id()) + .await? + .ok_or(BanksClientError::ClientError("Sysvar not present"))?; + from_account::(&sysvar).ok_or(BanksClientError::ClientError( + "Failed to deserialize sysvar", + )) } /// Return the cluster rent - pub fn get_rent(&mut self) -> impl Future> + '_ { - self.get_sysvar::() + pub async fn get_rent(&self) -> Result { + self.get_sysvar::().await } /// Send a transaction and return after the transaction has been rejected or /// reached the given level of commitment. - pub fn process_transaction_with_commitment( - &mut self, + pub async fn process_transaction_with_commitment( + &self, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { let ctx = context::current(); - self.process_transaction_with_commitment_and_context(ctx, transaction, commitment) - .map(|result| match result? { - None => Err(BanksClientError::ClientError( - "invalid blockhash or fee-payer", - )), - Some(transaction_result) => Ok(transaction_result?), - }) + match self + .process_transaction_with_commitment_and_context(ctx, transaction, commitment) + .await? + { + None => Err(BanksClientError::ClientError( + "invalid blockhash or fee-payer", + )), + Some(transaction_result) => Ok(transaction_result?), + } } /// Process a transaction and return the result with metadata. - pub fn process_transaction_with_metadata( - &mut self, + pub async fn process_transaction_with_metadata( + &self, transaction: impl Into, - ) -> impl Future> + '_ - { + ) -> Result { let ctx = context::current(); self.process_transaction_with_metadata_and_context(ctx, transaction.into()) + .await } /// Send a transaction and return any preflight (sanitization or simulation) errors, or return /// after the transaction has been rejected or reached the given level of commitment. - pub fn process_transaction_with_preflight_and_commitment( - &mut self, + pub async fn process_transaction_with_preflight_and_commitment( + &self, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { let ctx = context::current(); - self.process_transaction_with_preflight_and_commitment_and_context( - ctx, - transaction, - commitment, - ) - .map(|result| match result? { + match self + .process_transaction_with_preflight_and_commitment_and_context( + ctx, + transaction, + commitment, + ) + .await? + { BanksTransactionResultWithSimulation { result: None, simulation_details: _, @@ -246,31 +256,33 @@ impl BanksClient { result: Some(result), simulation_details: _, } => result.map_err(Into::into), - }) + } } /// Send a transaction and return any preflight (sanitization or simulation) errors, or return /// after the transaction has been finalized or rejected. - pub fn process_transaction_with_preflight( - &mut self, + pub async fn process_transaction_with_preflight( + &self, transaction: impl Into, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { self.process_transaction_with_preflight_and_commitment( transaction, CommitmentLevel::default(), ) + .await } /// Send a transaction and return until the transaction has been finalized or rejected. - pub fn process_transaction( - &mut self, + pub async fn process_transaction( + &self, transaction: impl Into, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { self.process_transaction_with_commitment(transaction, CommitmentLevel::default()) + .await } pub async fn process_transactions_with_commitment>( - &mut self, + &self, transactions: Vec, commitment: CommitmentLevel, ) -> Result<(), BanksClientError> { @@ -286,112 +298,115 @@ impl BanksClient { } /// Send transactions and return until the transaction has been finalized or rejected. - pub fn process_transactions<'a, T: Into + 'a>( - &'a mut self, + pub async fn process_transactions<'a, T: Into + 'a>( + &'a self, transactions: Vec, - ) -> impl Future> + '_ { + ) -> Result<(), BanksClientError> { self.process_transactions_with_commitment(transactions, CommitmentLevel::default()) + .await } /// Simulate a transaction at the given commitment level - pub fn simulate_transaction_with_commitment( - &mut self, + pub async fn simulate_transaction_with_commitment( + &self, transaction: impl Into, commitment: CommitmentLevel, - ) -> impl Future> + '_ - { + ) -> Result { self.simulate_transaction_with_commitment_and_context( context::current(), transaction, commitment, ) + .await } /// Simulate a transaction at the default commitment level - pub fn simulate_transaction( - &mut self, + pub async fn simulate_transaction( + &self, transaction: impl Into, - ) -> impl Future> + '_ - { + ) -> Result { self.simulate_transaction_with_commitment(transaction, CommitmentLevel::default()) + .await } /// Return the most recent rooted slot. All transactions at or below this slot /// are said to be finalized. The cluster will not fork to a higher slot. - pub fn get_root_slot(&mut self) -> impl Future> + '_ { + pub async fn get_root_slot(&self) -> Result { self.get_slot_with_context(context::current(), CommitmentLevel::default()) + .await } /// Return the most recent rooted block height. All transactions at or below this height /// are said to be finalized. The cluster will not fork to a higher block height. - pub fn get_root_block_height( - &mut self, - ) -> impl Future> + '_ { + pub async fn get_root_block_height(&self) -> Result { self.get_block_height_with_context(context::current(), CommitmentLevel::default()) + .await } /// Return the account at the given address at the slot corresponding to the given /// commitment level. If the account is not found, None is returned. - pub fn get_account_with_commitment( - &mut self, + pub async fn get_account_with_commitment( + &self, address: Pubkey, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.get_account_with_commitment_and_context(context::current(), address, commitment) + .await } /// Return the account at the given address at the time of the most recent root slot. /// If the account is not found, None is returned. - pub fn get_account( - &mut self, - address: Pubkey, - ) -> impl Future, BanksClientError>> + '_ { + pub async fn get_account(&self, address: Pubkey) -> Result, BanksClientError> { self.get_account_with_commitment(address, CommitmentLevel::default()) + .await } /// Return the unpacked account data at the given address /// If the account is not found, an error is returned - pub fn get_packed_account_data( - &mut self, + pub async fn get_packed_account_data( + &self, address: Pubkey, - ) -> impl Future> + '_ { - self.get_account(address).map(|result| { - let account = result?.ok_or(BanksClientError::ClientError("Account not found"))?; - T::unpack_from_slice(&account.data) - .map_err(|_| BanksClientError::ClientError("Failed to deserialize account")) - }) + ) -> Result { + let account = self + .get_account(address) + .await? + .ok_or(BanksClientError::ClientError("Account not found"))?; + T::unpack_from_slice(&account.data) + .map_err(|_| BanksClientError::ClientError("Failed to deserialize account")) } /// Return the unpacked account data at the given address /// If the account is not found, an error is returned - pub fn get_account_data_with_borsh( - &mut self, + pub async fn get_account_data_with_borsh( + &self, address: Pubkey, - ) -> impl Future> + '_ { - self.get_account(address).map(|result| { - let account = result?.ok_or(BanksClientError::ClientError("Account not found"))?; - T::try_from_slice(&account.data).map_err(Into::into) - }) + ) -> Result { + let account = self + .get_account(address) + .await? + .ok_or(BanksClientError::ClientError("Account not found"))?; + T::try_from_slice(&account.data).map_err(Into::into) } /// Return the balance in lamports of an account at the given address at the slot /// corresponding to the given commitment level. - pub fn get_balance_with_commitment( - &mut self, + pub async fn get_balance_with_commitment( + &self, address: Pubkey, commitment: CommitmentLevel, - ) -> impl Future> + '_ { - self.get_account_with_commitment_and_context(context::current(), address, commitment) - .map(|result| Ok(result?.map(|x| x.lamports).unwrap_or(0))) + ) -> Result { + Ok(self + .get_account_with_commitment_and_context(context::current(), address, commitment) + .await? + .map(|x| x.lamports) + .unwrap_or(0)) } /// Return the balance in lamports of an account at the given address at the time /// of the most recent root slot. - pub fn get_balance( - &mut self, - address: Pubkey, - ) -> impl Future> + '_ { + pub async fn get_balance(&self, address: Pubkey) -> Result { self.get_balance_with_commitment(address, CommitmentLevel::default()) + .await } /// Return the status of a transaction with a signature matching the transaction's first @@ -399,16 +414,17 @@ impl BanksClient { /// blockhash was expired or the fee-paying account had insufficient funds to pay the /// transaction fee. Note that servers rarely store the full transaction history. This /// method may return None if the transaction status has been discarded. - pub fn get_transaction_status( - &mut self, + pub async fn get_transaction_status( + &self, signature: Signature, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.get_transaction_status_with_context(context::current(), signature) + .await } /// Same as get_transaction_status, but for multiple transactions. pub async fn get_transaction_statuses( - &mut self, + &self, signatures: Vec, ) -> Result>, BanksClientError> { // tarpc futures oddly hold a mutable reference back to the client so clone the client upfront @@ -427,66 +443,67 @@ impl BanksClient { statuses.into_iter().collect() } - pub fn get_latest_blockhash( - &mut self, - ) -> impl Future> + '_ { + pub async fn get_latest_blockhash(&self) -> Result { self.get_latest_blockhash_with_commitment(CommitmentLevel::default()) - .map(|result| { - result? - .map(|x| x.0) - .ok_or(BanksClientError::ClientError("valid blockhash not found")) - .map_err(Into::into) - }) + .await? + .map(|x| x.0) + .ok_or(BanksClientError::ClientError("valid blockhash not found")) + .map_err(Into::into) } - pub fn get_latest_blockhash_with_commitment( - &mut self, + pub async fn get_latest_blockhash_with_commitment( + &self, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.get_latest_blockhash_with_commitment_and_context(context::current(), commitment) + .await } - pub fn get_latest_blockhash_with_commitment_and_context( - &mut self, + pub async fn get_latest_blockhash_with_commitment_and_context( + &self, ctx: Context, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.inner .get_latest_blockhash_with_commitment_and_context(ctx, commitment) + .await .map_err(Into::into) } - pub fn get_fee_for_message( - &mut self, + pub async fn get_fee_for_message( + &self, message: Message, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.get_fee_for_message_with_commitment_and_context( context::current(), message, CommitmentLevel::default(), ) + .await } - pub fn get_fee_for_message_with_commitment( - &mut self, + pub async fn get_fee_for_message_with_commitment( + &self, message: Message, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.get_fee_for_message_with_commitment_and_context( context::current(), message, commitment, ) + .await } - pub fn get_fee_for_message_with_commitment_and_context( - &mut self, + pub async fn get_fee_for_message_with_commitment_and_context( + &self, ctx: Context, message: Message, commitment: CommitmentLevel, - ) -> impl Future, BanksClientError>> + '_ { + ) -> Result, BanksClientError> { self.inner .get_fee_for_message_with_commitment_and_context(ctx, message, commitment) + .await .map_err(Into::into) } } @@ -557,7 +574,7 @@ mod tests { let client_transport = start_local_server(bank_forks, block_commitment_cache, Duration::from_millis(1)) .await; - let mut banks_client = start_client(client_transport).await?; + let banks_client = start_client(client_transport).await?; let recent_blockhash = banks_client.get_latest_blockhash().await?; let transaction = Transaction::new(&[&genesis.mint_keypair], message, recent_blockhash); @@ -596,7 +613,7 @@ mod tests { let client_transport = start_local_server(bank_forks, block_commitment_cache, Duration::from_millis(1)) .await; - let mut banks_client = start_client(client_transport).await?; + let banks_client = start_client(client_transport).await?; let (recent_blockhash, last_valid_block_height) = banks_client .get_latest_blockhash_with_commitment(CommitmentLevel::default()) .await? diff --git a/program-test/tests/bpf.rs b/program-test/tests/bpf.rs index af9c19c2037dfc..d601c6c040ef9f 100644 --- a/program-test/tests/bpf.rs +++ b/program-test/tests/bpf.rs @@ -14,7 +14,7 @@ async fn test_add_bpf_program() { program_test.prefer_bpf(true); program_test.add_program("noop_program", program_id, None); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; // Assert the program is a BPF Loader 2 program. let program_account = context diff --git a/program-test/tests/builtins.rs b/program-test/tests/builtins.rs index b48724f8800973..4d5ca93ed041c3 100644 --- a/program-test/tests/builtins.rs +++ b/program-test/tests/builtins.rs @@ -13,7 +13,7 @@ use { #[tokio::test] async fn test_bpf_loader_upgradeable_present() { // Arrange - let (mut banks_client, payer, recent_blockhash) = ProgramTest::default().start().await; + let (banks_client, payer, recent_blockhash) = ProgramTest::default().start().await; let buffer_keypair = Keypair::new(); let upgrade_authority_keypair = Keypair::new(); @@ -50,7 +50,7 @@ async fn test_bpf_loader_upgradeable_present() { #[tokio::test] async fn versioned_transaction() { let program_test = ProgramTest::default(); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let program_id = Pubkey::new_unique(); let account = Keypair::new(); diff --git a/program-test/tests/compute_units.rs b/program-test/tests/compute_units.rs index bcbdd0b252f76b..3649e76a14c5d6 100644 --- a/program-test/tests/compute_units.rs +++ b/program-test/tests/compute_units.rs @@ -20,7 +20,7 @@ fn overflow_compute_units() { async fn max_compute_units() { let mut program_test = ProgramTest::default(); program_test.set_compute_max_units(i64::MAX as u64); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; // Invalid compute unit maximums are only triggered by BPF programs, so send // a valid instruction into a BPF program to make sure the issue doesn't diff --git a/program-test/tests/core_bpf.rs b/program-test/tests/core_bpf.rs index bc81a94f8e2f82..961539aace8e5b 100644 --- a/program-test/tests/core_bpf.rs +++ b/program-test/tests/core_bpf.rs @@ -14,7 +14,7 @@ async fn test_add_bpf_program() { let mut program_test = ProgramTest::default(); program_test.add_upgradeable_program_to_genesis("noop_program", &program_id); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; // Assert the program is a BPF Loader Upgradeable program. let program_account = context diff --git a/program-test/tests/cpi.rs b/program-test/tests/cpi.rs index 22592a7892e968..12047533926826 100644 --- a/program-test/tests/cpi.rs +++ b/program-test/tests/cpi.rs @@ -129,7 +129,7 @@ async fn cpi() { processor!(invoked_process_instruction), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![Instruction::new_with_bincode( invoker_program_id, &[0], @@ -165,7 +165,7 @@ async fn cpi_dupes() { processor!(invoked_process_instruction), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![Instruction::new_with_bincode( invoker_program_id, &[0], @@ -201,7 +201,7 @@ async fn cpi_create_account() { ); let create_account_keypair = Keypair::new(); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![Instruction::new_with_bincode( create_account_program_id, &[0], @@ -272,7 +272,7 @@ async fn stack_height() { processor!(invoked_stack_height), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![Instruction::new_with_bytes( invoker_stack_height_program_id, &[], diff --git a/program-test/tests/genesis_accounts.rs b/program-test/tests/genesis_accounts.rs index 41f1f71b923418..9aaa6eb9e7eeae 100644 --- a/program-test/tests/genesis_accounts.rs +++ b/program-test/tests/genesis_accounts.rs @@ -30,7 +30,7 @@ async fn genesis_accounts() { program_test.add_genesis_account(*pubkey, account.clone()); } - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; // Verify the accounts are present. for (pubkey, account) in my_genesis_accounts.iter() { diff --git a/program-test/tests/lamports.rs b/program-test/tests/lamports.rs index 783aae7edf4828..a7c2ac0d3becd1 100644 --- a/program-test/tests/lamports.rs +++ b/program-test/tests/lamports.rs @@ -42,7 +42,7 @@ async fn move_lamports() { let lamports = 1_000_000_000; let source = Keypair::new(); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![ system_instruction::create_account( &context.payer.pubkey(), diff --git a/program-test/tests/realloc.rs b/program-test/tests/realloc.rs index 14a93439e826f1..97b60ae083928f 100644 --- a/program-test/tests/realloc.rs +++ b/program-test/tests/realloc.rs @@ -50,7 +50,7 @@ async fn realloc_smaller_in_cpi() { program_id, processor!(process_instruction), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let token_2022_id = solana_inline_spl::token_2022::id(); let mint = Keypair::new(); diff --git a/program-test/tests/return_data.rs b/program-test/tests/return_data.rs index d8c3aa992c4f43..99ec61000c252a 100644 --- a/program-test/tests/return_data.rs +++ b/program-test/tests/return_data.rs @@ -69,7 +69,7 @@ async fn return_data() { processor!(set_return_data_process_instruction), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let instructions = vec![Instruction { program_id: get_return_data_program_id, accounts: vec![AccountMeta::new_readonly(set_return_data_program_id, false)], @@ -109,7 +109,7 @@ async fn simulation_return_data() { processor!(error_set_return_data_process_instruction), ); - let mut context = program_test.start_with_context().await; + let context = program_test.start_with_context().await; let expected_data = vec![240, 159, 166, 150]; let instructions = vec![Instruction { program_id: error_set_return_data_program_id, diff --git a/program-test/tests/spl.rs b/program-test/tests/spl.rs index fc6deff7ca61c4..d352bbf93bf667 100644 --- a/program-test/tests/spl.rs +++ b/program-test/tests/spl.rs @@ -14,7 +14,7 @@ use { #[tokio::test] async fn programs_present() { - let (mut banks_client, _, _) = ProgramTest::default().start().await; + let (banks_client, _, _) = ProgramTest::default().start().await; let rent = banks_client.get_rent().await.unwrap(); let token_2022_id = solana_inline_spl::token_2022::id(); let (token_2022_programdata_id, _) = @@ -32,7 +32,7 @@ async fn programs_present() { #[tokio::test] async fn token_2022() { - let (mut banks_client, payer, recent_blockhash) = ProgramTest::default().start().await; + let (banks_client, payer, recent_blockhash) = ProgramTest::default().start().await; let token_2022_id = solana_inline_spl::token_2022::id(); let mint = Keypair::new(); diff --git a/tpu-client/src/nonblocking/tpu_client.rs b/tpu-client/src/nonblocking/tpu_client.rs index 47d443af20a4ca..8c21ea4f510fc0 100644 --- a/tpu-client/src/nonblocking/tpu_client.rs +++ b/tpu-client/src/nonblocking/tpu_client.rs @@ -3,7 +3,7 @@ use { crate::tpu_client::{RecentLeaderSlots, TpuClientConfig, MAX_FANOUT_SLOTS}, bincode::serialize, futures_util::{ - future::{join_all, FutureExt, TryFutureExt}, + future::{join_all, FutureExt}, stream::StreamExt, }, log::*, @@ -308,11 +308,12 @@ where // // Useful for end-users who don't need a persistent connection to each validator, // and want to abort more quickly. -fn timeout_future<'a, Fut: Future> + 'a>( +async fn timeout_future>>( timeout_duration: Duration, future: Fut, -) -> impl Future> + 'a { +) -> TransportResult<()> { timeout(timeout_duration, future) + .await .unwrap_or_else(|_| Err(TransportError::Custom("Timed out".to_string()))) }