From ff321023b15ea9d6d00d35f68f06d54ec32c1f79 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Tue, 5 Nov 2024 19:55:32 +0100 Subject: [PATCH] Non breaking in parallel + remove test cases --- cargo-registry/src/client.rs | 7 ++ cli/src/clap_app.rs | 2 +- cli/src/program.rs | 14 ++-- cli/src/program_v4.rs | 9 ++- cli/tests/program.rs | 19 ++--- cli/tests/transfer.rs | 7 +- ...nd_and_confirm_transactions_in_parallel.rs | 27 +++++-- ...nd_and_confirm_transactions_in_parallel.rs | 73 ++++++++++++++++--- rpc-client/src/nonblocking/rpc_client.rs | 1 - 9 files changed, 113 insertions(+), 46 deletions(-) diff --git a/cargo-registry/src/client.rs b/cargo-registry/src/client.rs index 3fad5e5fce961f..faad91479f3dbc 100644 --- a/cargo-registry/src/client.rs +++ b/cargo-registry/src/client.rs @@ -67,6 +67,13 @@ impl Client { App::new(name) .about(about) .version(version) + .arg( + Arg::with_name("skip_preflight") + .long("skip-preflight") + .global(true) + .takes_value(false) + .help("Skip the preflight check when sending transactions"), + ) .arg( Arg::with_name("config_file") .short("C") diff --git a/cli/src/clap_app.rs b/cli/src/clap_app.rs index cea02f01b9f53a..3f62ba48abb323 100644 --- a/cli/src/clap_app.rs +++ b/cli/src/clap_app.rs @@ -19,7 +19,7 @@ pub fn get_clap_app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> A .long("skip-preflight") .global(true) .takes_value(false) - .help("Skip the preflight check when sending transactions (default: false)"), + .help("Skip the preflight check when sending transactions"), ) .arg({ let arg = Arg::with_name("config_file") diff --git a/cli/src/program.rs b/cli/src/program.rs index a72728f4307ddb..878b26c6520f10 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -35,7 +35,8 @@ use { solana_client::{ connection_cache::ConnectionCache, send_and_confirm_transactions_in_parallel::{ - send_and_confirm_transactions_in_parallel_blocking, SendAndConfirmConfig, + send_and_confirm_transactions_in_parallel_blocking_v2, + SendAndConfirmConfigV2, }, tpu_client::{TpuClient, TpuClientConfig}, }, @@ -1575,7 +1576,10 @@ fn process_program_upgrade( let signers = &[fee_payer_signer, upgrade_authority_signer]; tx.try_sign(signers, blockhash)?; let final_tx_sig = rpc_client - .send_and_confirm_transaction_with_spinner(&tx) + .send_and_confirm_transaction_with_spinner_and_config(&tx, + config.commitment, + config.send_transaction_config + ) .map_err(|e| format!("Upgrading program failed: {e}"))?; let program_id = CliProgramId { program_id: program_id.to_string(), @@ -2995,15 +2999,15 @@ fn send_deploy_messages( .expect("Should return a valid tpu client") ); - send_and_confirm_transactions_in_parallel_blocking( + send_and_confirm_transactions_in_parallel_blocking_v2( rpc_client.clone(), tpu_client, &write_messages, &[fee_payer_signer, write_signer], - SendAndConfirmConfig { + SendAndConfirmConfigV2 { resign_txs_count: Some(max_sign_attempts), with_spinner: true, - skip_preflight: config.send_transaction_config.skip_preflight, + rpc_send_transaction_config: config.send_transaction_config, }, ) }, diff --git a/cli/src/program_v4.rs b/cli/src/program_v4.rs index 9da11348ea37de..63c427bcef7ba1 100644 --- a/cli/src/program_v4.rs +++ b/cli/src/program_v4.rs @@ -20,7 +20,8 @@ use { solana_client::{ connection_cache::ConnectionCache, send_and_confirm_transactions_in_parallel::{ - send_and_confirm_transactions_in_parallel_blocking, SendAndConfirmConfig, + send_and_confirm_transactions_in_parallel_blocking_v2, + SendAndConfirmConfigV2, }, tpu_client::{TpuClient, TpuClientConfig}, }, @@ -1083,15 +1084,15 @@ fn send_messages( .block_on(tpu_client_fut) .expect("Should return a valid tpu client"); - send_and_confirm_transactions_in_parallel_blocking( + send_and_confirm_transactions_in_parallel_blocking_v2( rpc_client.clone(), Some(tpu_client), write_messages, &[config.payer, config.authority], - SendAndConfirmConfig { + SendAndConfirmConfigV2 { resign_txs_count: Some(5), with_spinner: true, - skip_preflight: config.rpc_send_transaction_config.skip_preflight, + rpc_send_transaction_config: config.rpc_send_transaction_config, }, ) } diff --git a/cli/tests/program.rs b/cli/tests/program.rs index fcf206e58d5573..b2ed10700c6567 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -569,6 +569,7 @@ fn test_cli_program_upgrade_with_feature(enable_feature: bool) { let mut config = CliConfig::recent_for_tests(); config.json_rpc_url = test_validator.rpc_url(); + config.send_transaction_config.skip_preflight = false; let online_signer = Keypair::new(); let offline_signer = Keypair::new(); @@ -1369,9 +1370,8 @@ fn test_cli_program_close_program() { assert_eq!(programdata_lamports, recipient_account.lamports); } -#[test_case(true; "Skip Preflight")] -#[test_case(false; "Dont skip Preflight")] -fn test_cli_program_extend_program_skip_preflight(skip_preflight: bool) { +#[test] +fn test_cli_program_extend_program() { solana_logger::setup(); let mut noop_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -1421,7 +1421,7 @@ fn test_cli_program_extend_program_skip_preflight(skip_preflight: bool) { lamports: 100 * minimum_balance_for_programdata + minimum_balance_for_program, }; config.send_transaction_config = RpcSendTransactionConfig { - skip_preflight: skip_preflight, + skip_preflight: false, preflight_commitment: Some(CommitmentConfig::processed().commitment), ..RpcSendTransactionConfig::default() }; @@ -1498,14 +1498,8 @@ fn test_cli_program_extend_program_skip_preflight(skip_preflight: bool) { use_rpc: false, skip_feature_verification: true, }); - if skip_preflight { - expect_command_failure( - &config, - "Program upgrade must fail, as the buffer is 1 byte too short", - "Deploying program failed: Error processing Instruction 0: account data too small for instruction", - ); - } else { - expect_command_failure( + + expect_command_failure( &config, "Program upgrade must fail, as the buffer is 1 byte too short", "Deploying program failed: \ @@ -1517,7 +1511,6 @@ fn test_cli_program_extend_program_skip_preflight(skip_preflight: bool) { ProgramData account not large enough\n \ Program BPFLoaderUpgradeab1e11111111111111111111111 failed: account data too small for instruction\n", ); - } // Wait one slot to avoid "Program was deployed in this block already" error wait_n_slots(&rpc_client, 1); diff --git a/cli/tests/transfer.rs b/cli/tests/transfer.rs index 378f758717c54f..dead746ae3e6c0 100644 --- a/cli/tests/transfer.rs +++ b/cli/tests/transfer.rs @@ -558,9 +558,8 @@ fn test_transfer_all(compute_unit_price: Option) { check_balance!(500_000 - fee, &rpc_client, &recipient_pubkey); } -#[test_case(true; "Skip Preflight")] -#[test_case(false; "Don`t skip Preflight")] -fn test_transfer_unfunded_recipient(skip_preflight: bool) { +#[test] +fn test_transfer_unfunded_recipient() { solana_logger::setup(); let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); @@ -580,7 +579,7 @@ fn test_transfer_unfunded_recipient(skip_preflight: bool) { let mut config = CliConfig::recent_for_tests(); config.json_rpc_url = test_validator.rpc_url(); config.signers = vec![&default_signer]; - config.send_transaction_config.skip_preflight = skip_preflight; + config.send_transaction_config.skip_preflight = false; let sender_pubkey = config.signers[0].pubkey(); let recipient_pubkey = Pubkey::from([1u8; 32]); diff --git a/client-test/tests/send_and_confirm_transactions_in_parallel.rs b/client-test/tests/send_and_confirm_transactions_in_parallel.rs index 07c43ab716ea7d..f083f1f2737554 100644 --- a/client-test/tests/send_and_confirm_transactions_in_parallel.rs +++ b/client-test/tests/send_and_confirm_transactions_in_parallel.rs @@ -1,8 +1,9 @@ use { solana_client::{ nonblocking::tpu_client::TpuClient, + rpc_config::RpcSendTransactionConfig, send_and_confirm_transactions_in_parallel::{ - send_and_confirm_transactions_in_parallel_blocking, SendAndConfirmConfig, + send_and_confirm_transactions_in_parallel_blocking_v2, SendAndConfirmConfigV2, }, }, solana_rpc_client::rpc_client::RpcClient, @@ -51,15 +52,21 @@ fn test_send_and_confirm_transactions_in_parallel_without_tpu_client() { let original_alice_balance = rpc_client.get_balance(&alice.pubkey()).unwrap(); let (messages, sum) = create_messages(alice_pubkey, bob_pubkey); - let txs_errors = send_and_confirm_transactions_in_parallel_blocking( + let txs_errors = send_and_confirm_transactions_in_parallel_blocking_v2( rpc_client.clone(), None, &messages, &[&alice], - SendAndConfirmConfig { + SendAndConfirmConfigV2 { with_spinner: false, resign_txs_count: Some(5), - skip_preflight: false, + rpc_send_transaction_config: RpcSendTransactionConfig { + skip_preflight: false, + preflight_commitment: Some(CommitmentConfig::confirmed().commitment), + encoding: None, + max_retries: None, + min_context_slot: None, + }, }, ); assert!(txs_errors.is_ok()); @@ -110,15 +117,21 @@ fn test_send_and_confirm_transactions_in_parallel_with_tpu_client() { ); let tpu_client = rpc_client.runtime().block_on(tpu_client_fut).unwrap(); - let txs_errors = send_and_confirm_transactions_in_parallel_blocking( + let txs_errors = send_and_confirm_transactions_in_parallel_blocking_v2( rpc_client.clone(), Some(tpu_client), &messages, &[&alice], - SendAndConfirmConfig { + SendAndConfirmConfigV2 { with_spinner: false, resign_txs_count: Some(5), - skip_preflight: false, + rpc_send_transaction_config: RpcSendTransactionConfig { + skip_preflight: false, + preflight_commitment: Some(CommitmentConfig::confirmed().commitment), + encoding: None, + max_retries: None, + min_context_slot: None, + }, }, ); assert!(txs_errors.is_ok()); diff --git a/client/src/send_and_confirm_transactions_in_parallel.rs b/client/src/send_and_confirm_transactions_in_parallel.rs index d2d3a25ae842db..61003b84c315d0 100644 --- a/client/src/send_and_confirm_transactions_in_parallel.rs +++ b/client/src/send_and_confirm_transactions_in_parallel.rs @@ -55,14 +55,45 @@ struct BlockHashData { pub last_valid_block_height: u64, } +// Deprecated struct to maintain backward compatibility +#[deprecated(note = "Use SendAndConfirmConfigV2 with send_and_confirm_transactions_in_parallel_v2")] #[derive(Clone, Debug, Copy)] pub struct SendAndConfirmConfig { pub with_spinner: bool, pub resign_txs_count: Option, - pub skip_preflight: bool, } -/// Sends and confirms transactions concurrently in a sync context +// New struct with RpcSendTransactionConfig for non-breaking change +#[derive(Clone, Debug, Copy)] +pub struct SendAndConfirmConfigV2 { + pub with_spinner: bool, + pub resign_txs_count: Option, + pub rpc_send_transaction_config: RpcSendTransactionConfig, +} + +#[deprecated(note = "Use send_and_confirm_transactions_in_parallel_v2")] +pub async fn send_and_confirm_transactions_in_parallel( + rpc_client: Arc, + tpu_client: Option, + messages: &[Message], + signers: &T, + config: SendAndConfirmConfig, +) -> Result>> { + let config_v2 = SendAndConfirmConfigV2 { + with_spinner: config.with_spinner, + resign_txs_count: config.resign_txs_count, + rpc_send_transaction_config: RpcSendTransactionConfig { + skip_preflight: false, + ..RpcSendTransactionConfig::default() + }, + }; + send_and_confirm_transactions_in_parallel_v2( + rpc_client, tpu_client, messages, signers, config_v2, + ) + .await +} + +#[deprecated(note = "Use send_and_confirm_transactions_in_parallel_blocking_v2")] pub fn send_and_confirm_transactions_in_parallel_blocking( rpc_client: Arc, tpu_client: Option, @@ -70,7 +101,28 @@ pub fn send_and_confirm_transactions_in_parallel_blocking( signers: &T, config: SendAndConfirmConfig, ) -> Result>> { - let fut = send_and_confirm_transactions_in_parallel( + let config_v2 = SendAndConfirmConfigV2 { + with_spinner: config.with_spinner, + resign_txs_count: config.resign_txs_count, + rpc_send_transaction_config: RpcSendTransactionConfig { + skip_preflight: false, + ..RpcSendTransactionConfig::default() + }, + }; + send_and_confirm_transactions_in_parallel_blocking_v2( + rpc_client, tpu_client, messages, signers, config_v2, + ) +} + +/// Sends and confirms transactions concurrently in a sync context +pub fn send_and_confirm_transactions_in_parallel_blocking_v2( + rpc_client: Arc, + tpu_client: Option, + messages: &[Message], + signers: &T, + config: SendAndConfirmConfigV2, +) -> Result>> { + let fut = send_and_confirm_transactions_in_parallel_v2( rpc_client.get_inner_client().clone(), tpu_client, messages, @@ -197,7 +249,7 @@ async fn send_transaction_with_rpc_fallback( serialized_transaction: Vec, context: &SendingContext, index: usize, - skip_preflight: bool, + rpc_send_transaction_config: RpcSendTransactionConfig, ) -> Result<()> { let send_over_rpc = if let Some(tpu_client) = tpu_client { !tokio::time::timeout( @@ -214,9 +266,8 @@ async fn send_transaction_with_rpc_fallback( .send_transaction_with_config( &transaction, RpcSendTransactionConfig { - skip_preflight, preflight_commitment: Some(rpc_client.commitment().commitment), - ..RpcSendTransactionConfig::default() + ..rpc_send_transaction_config }, ) .await @@ -268,7 +319,7 @@ async fn sign_all_messages_and_send( messages_with_index: Vec<(usize, Message)>, signers: &T, context: &SendingContext, - skip_preflight: bool, + rpc_send_transaction_config: RpcSendTransactionConfig, ) -> Result<()> { let current_transaction_count = messages_with_index.len(); let mut futures = vec![]; @@ -318,7 +369,7 @@ async fn sign_all_messages_and_send( serialized_transaction, context, *index, - skip_preflight, + rpc_send_transaction_config, ) .await }); @@ -433,12 +484,12 @@ async fn send_staggered_transactions( /// The sending and confirmation of transactions is done in parallel tasks /// The method signs transactions just before sending so that blockhash does not /// expire. -pub async fn send_and_confirm_transactions_in_parallel( +pub async fn send_and_confirm_transactions_in_parallel_v2( rpc_client: Arc, tpu_client: Option, messages: &[Message], signers: &T, - config: SendAndConfirmConfig, + config: SendAndConfirmConfigV2, ) -> Result>> { // get current blockhash and corresponding last valid block height let (blockhash, last_valid_block_height) = rpc_client @@ -527,7 +578,7 @@ pub async fn send_and_confirm_transactions_in_parallel( messages_with_index, signers, &context, - config.skip_preflight, + config.rpc_send_transaction_config, ) .await?; confirm_transactions_till_block_height_and_resend_unexpired_transaction_over_tpu( diff --git a/rpc-client/src/nonblocking/rpc_client.rs b/rpc-client/src/nonblocking/rpc_client.rs index 7f684d87d22165..b72b4a5d74a9c5 100644 --- a/rpc-client/src/nonblocking/rpc_client.rs +++ b/rpc-client/src/nonblocking/rpc_client.rs @@ -868,7 +868,6 @@ impl RpcClient { }; let config = RpcSendTransactionConfig { encoding: Some(encoding), - skip_preflight: config.skip_preflight, preflight_commitment: Some(preflight_commitment.commitment), ..config };