Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip preflight to CLI #3339

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Release channels have their own copy of this changelog:

<a name="edge-channel"></a>
## [2.2.0] - Unreleased
* Changes
* CLI:
* Add global `--skip-preflight` option for skipping preflight checks on all transactions sent through RPC. This flag, along with `--use-rpc`, can improve success rate with program deployments using the public RPC nodes.

## [2.1.0]
* Breaking:
Expand Down
17 changes: 17 additions & 0 deletions cargo-registry/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
solana_cli_config::{Config, ConfigInput},
solana_cli_output::OutputFormat,
solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::config::RpcSendTransactionConfig,
solana_sdk::{
commitment_config,
signature::{read_keypair_file, Keypair},
Expand All @@ -30,6 +31,7 @@ impl<'a> RPCCommandConfig<'a> {
authority: &client.cli_signers[client.authority_signer_index],
output_format: &OutputFormat::Display,
use_quic: true,
rpc_send_transaction_config: client.rpc_transaction_config,
})
}
}
Expand All @@ -42,6 +44,7 @@ pub(crate) struct Client {
commitment: commitment_config::CommitmentConfig,
cli_signers: Vec<Keypair>,
authority_signer_index: SignerIndex,
rpc_transaction_config: RpcSendTransactionConfig,
}

impl Client {
Expand All @@ -64,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")
Expand Down Expand Up @@ -208,6 +218,8 @@ impl Client {
let server_url =
value_t!(matches, "server_url", String).unwrap_or(format!("http://0.0.0.0:{}", port));

let skip_preflight = matches.is_present("skip_preflight");
Woody4618 marked this conversation as resolved.
Show resolved Hide resolved

Ok(Client {
rpc_client: Arc::new(RpcClient::new_with_timeouts_and_commitment(
json_rpc_url.to_string(),
Expand All @@ -221,6 +233,11 @@ impl Client {
commitment,
cli_signers: vec![payer_keypair, authority_keypair],
authority_signer_index: 1,
rpc_transaction_config: RpcSendTransactionConfig {
skip_preflight,
preflight_commitment: Some(commitment.commitment),
..RpcSendTransactionConfig::default()
},
})
}
}
7 changes: 7 additions & 0 deletions cli/src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ pub fn get_clap_app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> A
.about(about)
.version(version)
.setting(AppSettings::SubcommandRequiredElseHelp)
.arg(
Arg::with_name("skip_preflight")
.long("skip-preflight")
.global(true)
.takes_value(false)
.help("Skip the preflight check when sending transactions"),
)
.arg({
let arg = Arg::with_name("config_file")
.short("C")
Expand Down
6 changes: 5 additions & 1 deletion cli/src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,10 @@ fn process_activate(
FEATURE_NAMES.get(&feature_id).unwrap(),
feature_id
);
let result = rpc_client.send_and_confirm_transaction_with_spinner(&transaction);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&transaction,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, config)
}
3 changes: 3 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ pub fn parse_args<'a>(
!DEFAULT_TPU_ENABLE_UDP
};

let skip_preflight = matches.is_present("skip_preflight");

let use_tpu_client = matches.is_present("use_tpu_client");

Ok((
Expand All @@ -227,6 +229,7 @@ pub fn parse_args<'a>(
output_format,
commitment,
send_transaction_config: RpcSendTransactionConfig {
skip_preflight,
preflight_commitment: Some(commitment.commitment),
..RpcSendTransactionConfig::default()
},
Expand Down
30 changes: 25 additions & 5 deletions cli/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ pub fn process_authorize_nonce_account(
&tx.message,
config.commitment,
)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
config.send_transaction_config,
);

log_instruction_custom_error::<SystemError>(result, config)
}
Expand Down Expand Up @@ -537,7 +541,11 @@ pub fn process_create_nonce_account(

let mut tx = Transaction::new_unsigned(message);
tx.try_sign(&config.signers, latest_blockhash)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
config.send_transaction_config,
);

log_instruction_custom_error::<SystemError>(result, config)
}
Expand Down Expand Up @@ -597,7 +605,11 @@ pub fn process_new_nonce(
&tx.message,
config.commitment,
)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
config.send_transaction_config,
);

log_instruction_custom_error::<SystemError>(result, config)
}
Expand Down Expand Up @@ -667,7 +679,11 @@ pub fn process_withdraw_from_nonce_account(
&tx.message,
config.commitment,
)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
config.send_transaction_config,
);

log_instruction_custom_error::<SystemError>(result, config)
}
Expand Down Expand Up @@ -697,7 +713,11 @@ pub(crate) fn process_upgrade_nonce_account(
&tx.message,
config.commitment,
)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, config)
}

Expand Down
46 changes: 20 additions & 26 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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},
},
Expand All @@ -47,7 +47,7 @@ use {
solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::{
client_error::ErrorKind as ClientErrorKind,
config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcSendTransactionConfig},
config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
filter::{Memcmp, RpcFilterType},
request::MAX_MULTIPLE_ACCOUNTS,
},
Expand Down Expand Up @@ -1575,7 +1575,11 @@ 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(),
Expand Down Expand Up @@ -1728,10 +1732,7 @@ fn process_set_authority(
.send_and_confirm_transaction_with_spinner_and_config(
Woody4618 marked this conversation as resolved.
Show resolved Hide resolved
&tx,
config.commitment,
RpcSendTransactionConfig {
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.send_transaction_config,
)
.map_err(|e| format!("Setting authority failed: {e}"))?;

Expand Down Expand Up @@ -1790,10 +1791,7 @@ fn process_set_authority_checked(
.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
RpcSendTransactionConfig {
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.send_transaction_config,
)
.map_err(|e| format!("Setting authority failed: {e}"))?;

Expand Down Expand Up @@ -2132,10 +2130,7 @@ fn close(
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
RpcSendTransactionConfig {
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.send_transaction_config,
);
if let Err(err) = result {
if let ClientErrorKind::TransactionError(TransactionError::InstructionError(
Expand Down Expand Up @@ -2358,10 +2353,7 @@ fn process_extend_program(
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&tx,
config.commitment,
RpcSendTransactionConfig {
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.send_transaction_config,
);
if let Err(err) = result {
if let ClientErrorKind::TransactionError(TransactionError::InstructionError(
Expand Down Expand Up @@ -2936,7 +2928,11 @@ fn send_deploy_messages(
} else {
initial_transaction.try_sign(&[fee_payer_signer], blockhash)?;
}
let result = rpc_client.send_and_confirm_transaction_with_spinner(&initial_transaction);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&initial_transaction,
config.commitment,
config.send_transaction_config,
);
log_instruction_custom_error::<SystemError>(result, config)
.map_err(|err| format!("Account allocation failed: {err}"))?;
} else {
Expand Down Expand Up @@ -3003,14 +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,
rpc_send_transaction_config: config.send_transaction_config,
},
)
},
Expand Down Expand Up @@ -3046,10 +3043,7 @@ fn send_deploy_messages(
.send_and_confirm_transaction_with_spinner_and_config(
&final_tx,
config.commitment,
RpcSendTransactionConfig {
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.send_transaction_config,
)
.map_err(|e| format!("Deploying program failed: {e}"))?,
));
Expand Down
28 changes: 17 additions & 11 deletions cli/src/program_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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},
},
Expand Down Expand Up @@ -567,6 +567,7 @@ pub struct ProgramV4CommandConfig<'a> {
pub authority: &'a dyn Signer,
pub output_format: &'a OutputFormat,
pub use_quic: bool,
pub rpc_send_transaction_config: RpcSendTransactionConfig,
}

impl<'a> ProgramV4CommandConfig<'a> {
Expand All @@ -578,6 +579,7 @@ impl<'a> ProgramV4CommandConfig<'a> {
authority: config.signers[*auth_signer_index],
output_format: &config.output_format,
use_quic: config.use_quic,
rpc_send_transaction_config: config.send_transaction_config,
}
}
}
Expand Down Expand Up @@ -1014,8 +1016,11 @@ fn send_messages(
let mut initial_transaction = Transaction::new_unsigned(message.clone());
initial_transaction
.try_sign(&[config.payer, initial_signer, config.authority], blockhash)?;
let result =
rpc_client.send_and_confirm_transaction_with_spinner(&initial_transaction);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&initial_transaction,
config.commitment,
config.rpc_send_transaction_config,
);
log_instruction_custom_error_ex::<SystemError, _>(
result,
config.output_format,
Expand All @@ -1031,7 +1036,11 @@ fn send_messages(

let mut initial_transaction = Transaction::new_unsigned(message.clone());
initial_transaction.try_sign(&[config.payer, config.authority], blockhash)?;
let result = rpc_client.send_and_confirm_transaction_with_spinner(&initial_transaction);
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
&initial_transaction,
config.commitment,
config.rpc_send_transaction_config,
);
log_instruction_custom_error_ex::<SystemError, _>(
result,
config.output_format,
Expand Down Expand Up @@ -1074,14 +1083,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,
rpc_send_transaction_config: config.rpc_send_transaction_config,
},
)
}
Expand All @@ -1107,11 +1117,7 @@ fn send_messages(
.send_and_confirm_transaction_with_spinner_and_config(
&final_tx,
config.commitment,
RpcSendTransactionConfig {
skip_preflight: true,
preflight_commitment: Some(config.commitment.commitment),
..RpcSendTransactionConfig::default()
},
config.rpc_send_transaction_config,
Woody4618 marked this conversation as resolved.
Show resolved Hide resolved
)
.map_err(|e| format!("Deploying program failed: {e}"))?;
}
Expand Down
Loading
Loading