Skip to content

Commit

Permalink
refactor: use less &mut self and more async-await in BanksClient (sol…
Browse files Browse the repository at this point in the history
…ana-labs#2591)

* refactor: use less &mut self in BanksClient

* refactor: use async-await syntax instead of explicit Futures
  • Loading branch information
andreisilviudragnea authored Aug 16, 2024
1 parent 3b9e7a3 commit 1492119
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 171 deletions.
321 changes: 169 additions & 152 deletions banks-client/src/lib.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion program-test/tests/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions program-test/tests/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion program-test/tests/compute_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion program-test/tests/core_bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions program-test/tests/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
&[],
Expand Down
2 changes: 1 addition & 1 deletion program-test/tests/genesis_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion program-test/tests/lamports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion program-test/tests/realloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions program-test/tests/return_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions program-test/tests/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) =
Expand All @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions tpu-client/src/nonblocking/tpu_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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<Output = TransportResult<()>> + 'a>(
async fn timeout_future<Fut: Future<Output = TransportResult<()>>>(
timeout_duration: Duration,
future: Fut,
) -> impl Future<Output = TransportResult<()>> + 'a {
) -> TransportResult<()> {
timeout(timeout_duration, future)
.await
.unwrap_or_else(|_| Err(TransportError::Custom("Timed out".to_string())))
}

Expand Down

0 comments on commit 1492119

Please sign in to comment.