From fa968da32e104b4152c2029858458e4cb20f3e59 Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Thu, 28 Sep 2023 15:08:11 +0200 Subject: [PATCH] cli: Don't skip preflight when interacting with programs (#33426) * cli: Don't skip preflight when closing a program * Don't skip preflight anywhere for program deploys, fix test --- cli/src/program.rs | 4 ---- cli/src/test_utils.rs | 21 +++++++++++++-------- cli/tests/program.rs | 4 ++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cli/src/program.rs b/cli/src/program.rs index 1c6bf98861..4222c732e0 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -1175,7 +1175,6 @@ fn process_set_authority( &tx, config.commitment, RpcSendTransactionConfig { - skip_preflight: true, preflight_commitment: Some(config.commitment.commitment), ..RpcSendTransactionConfig::default() }, @@ -1226,7 +1225,6 @@ fn process_set_authority_checked( &tx, config.commitment, RpcSendTransactionConfig { - skip_preflight: false, preflight_commitment: Some(config.commitment.commitment), ..RpcSendTransactionConfig::default() }, @@ -1562,7 +1560,6 @@ fn close( &tx, config.commitment, RpcSendTransactionConfig { - skip_preflight: true, preflight_commitment: Some(config.commitment.commitment), ..RpcSendTransactionConfig::default() }, @@ -2232,7 +2229,6 @@ fn send_deploy_messages( &final_tx, config.commitment, RpcSendTransactionConfig { - skip_preflight: true, preflight_commitment: Some(config.commitment.commitment), ..RpcSendTransactionConfig::default() }, diff --git a/cli/src/test_utils.rs b/cli/src/test_utils.rs index 5526022591..68b3763658 100644 --- a/cli/src/test_utils.rs +++ b/cli/src/test_utils.rs @@ -39,6 +39,17 @@ pub fn check_ready(rpc_client: &RpcClient) { } } +pub fn wait_n_slots(rpc_client: &RpcClient, n: u64) -> u64 { + let slot = rpc_client.get_slot().unwrap(); + loop { + sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT)); + let new_slot = rpc_client.get_slot().unwrap(); + if new_slot - slot > n { + return new_slot; + } + } +} + pub fn wait_for_next_epoch_plus_n_slots(rpc_client: &RpcClient, n: u64) -> (Epoch, u64) { let current_epoch = rpc_client.get_epoch_info().unwrap().epoch; let next_epoch = current_epoch + 1; @@ -48,14 +59,8 @@ pub fn wait_for_next_epoch_plus_n_slots(rpc_client: &RpcClient, n: u64) -> (Epoc let next_epoch = rpc_client.get_epoch_info().unwrap().epoch; if next_epoch > current_epoch { - let slot = rpc_client.get_slot().unwrap(); - loop { - sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT)); - let new_slot = rpc_client.get_slot().unwrap(); - if new_slot - slot > n { - return (next_epoch, new_slot); - } - } + let new_slot = wait_n_slots(rpc_client, n); + return (next_epoch, new_slot); } } } diff --git a/cli/tests/program.rs b/cli/tests/program.rs index ec28e46000..de5ef8cd01 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -5,6 +5,7 @@ use { solana_cli::{ cli::{process_command, CliCommand, CliConfig}, program::{ProgramCliCommand, CLOSE_PROGRAM_WARNING}, + test_utils::wait_n_slots, }, solana_cli_output::OutputFormat, solana_faucet::faucet::run_local_faucet, @@ -688,6 +689,9 @@ fn test_cli_program_close_program() { &bpf_loader_upgradeable::id(), ); + // Wait one slot to avoid "Program was deployed in this block already" error + wait_n_slots(&rpc_client, 1); + // Close program let close_account = rpc_client.get_account(&programdata_pubkey).unwrap(); let programdata_lamports = close_account.lamports;