From 4e604e121141426bddedbcaf76b9a7c20a3a811d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2020 16:56:29 +0000 Subject: [PATCH] Add (hidden) --use-deprecated-loader flag to `solana deploy` (#11828) (cherry picked from commit de736e00ad623976c8e7d4781d49c6dd135ceb7b) Co-authored-by: Michael Vines --- cli/src/cli.rs | 38 +++++++++++++++++++++++++++++++++----- cli/tests/deploy.rs | 2 ++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 46c2262f0b..74d2c3e87d 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -33,7 +33,7 @@ use solana_faucet::faucet::request_airdrop_transaction; use solana_faucet::faucet_mock::request_airdrop_transaction; use solana_remote_wallet::remote_wallet::RemoteWalletManager; use solana_sdk::{ - bpf_loader, + bpf_loader, bpf_loader_deprecated, clock::{Epoch, Slot, DEFAULT_TICKS_PER_SECOND}, commitment_config::CommitmentConfig, decode_error::DecodeError, @@ -266,6 +266,7 @@ pub enum CliCommand { Deploy { program_location: String, address: Option, + use_deprecated_loader: bool, }, // Stake Commands CreateStakeAccount { @@ -697,11 +698,13 @@ pub fn parse_command( signers.push(signer); 1 }); + let use_deprecated_loader = matches.is_present("use_deprecated_loader"); Ok(CliCommandInfo { command: CliCommand::Deploy { program_location: matches.value_of("program_location").unwrap().to_string(), address, + use_deprecated_loader, }, signers, }) @@ -1366,6 +1369,7 @@ fn process_deploy( config: &CliConfig, program_location: &str, address: Option, + use_deprecated_loader: bool, ) -> ProcessResult { let new_keypair = Keypair::new(); // Create ephemeral keypair to use for program address, if not provided let program_id = if let Some(i) = address { @@ -1381,6 +1385,12 @@ fn process_deploy( CliError::DynamicProgramError(format!("Unable to read program file: {}", err)) })?; + let loader_id = if use_deprecated_loader { + bpf_loader_deprecated::id() + } else { + bpf_loader::id() + }; + // Build transactions to calculate fees let mut messages: Vec<&Message> = Vec::new(); let (blockhash, fee_calculator, _) = rpc_client @@ -1392,7 +1402,7 @@ fn process_deploy( &program_id.pubkey(), minimum_balance.max(1), program_data.len() as u64, - &bpf_loader::id(), + &loader_id, ); let message = Message::new(&[ix], Some(&config.signers[0].pubkey())); let mut create_account_tx = Transaction::new_unsigned(message); @@ -1403,7 +1413,7 @@ fn process_deploy( for (chunk, i) in program_data.chunks(DATA_CHUNK_SIZE).zip(0..) { let instruction = loader_instruction::write( &program_id.pubkey(), - &bpf_loader::id(), + &loader_id, (i * DATA_CHUNK_SIZE) as u32, chunk.to_vec(), ); @@ -1416,7 +1426,7 @@ fn process_deploy( } messages.append(&mut write_message_refs); - let instruction = loader_instruction::finalize(&program_id.pubkey(), &bpf_loader::id()); + let instruction = loader_instruction::finalize(&program_id.pubkey(), &loader_id); let finalize_message = Message::new(&[instruction], Some(&signers[0].pubkey())); messages.push(&finalize_message); @@ -1967,7 +1977,14 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { CliCommand::Deploy { program_location, address, - } => process_deploy(&rpc_client, config, program_location, *address), + use_deprecated_loader, + } => process_deploy( + &rpc_client, + config, + program_location, + *address, + *use_deprecated_loader, + ), // Stake Commands @@ -2654,6 +2671,13 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .takes_value(true) .validator(is_valid_signer) .help("The signer for the desired address of the program [default: new random address]") + ) + .arg( + Arg::with_name("use-deprecated-loader") + .long("use_deprecated_loader") + .takes_value(false) + .hidden(true) // Don't document this argument to discourage its use + .help("Use the deprecated BPF loader") ), ) .subcommand( @@ -3098,6 +3122,7 @@ mod tests { command: CliCommand::Deploy { program_location: "/Users/test/program.o".to_string(), address: None, + use_deprecated_loader: false, }, signers: vec![read_keypair_file(&keypair_file).unwrap().into()], } @@ -3118,6 +3143,7 @@ mod tests { command: CliCommand::Deploy { program_location: "/Users/test/program.o".to_string(), address: Some(1), + use_deprecated_loader: false, }, signers: vec![ read_keypair_file(&keypair_file).unwrap().into(), @@ -3837,6 +3863,7 @@ mod tests { config.command = CliCommand::Deploy { program_location: pathbuf.to_str().unwrap().to_string(), address: None, + use_deprecated_loader: false, }; let result = process_command(&config); let json: Value = serde_json::from_str(&result.unwrap()).unwrap(); @@ -3854,6 +3881,7 @@ mod tests { config.command = CliCommand::Deploy { program_location: "bad/file/location.so".to_string(), address: None, + use_deprecated_loader: false, }; assert!(process_command(&config).is_err()); } diff --git a/cli/tests/deploy.rs b/cli/tests/deploy.rs index 7ccdc964bf..f605d5658e 100644 --- a/cli/tests/deploy.rs +++ b/cli/tests/deploy.rs @@ -63,6 +63,7 @@ fn test_cli_deploy_program() { config.command = CliCommand::Deploy { program_location: pathbuf.to_str().unwrap().to_string(), address: None, + use_deprecated_loader: false, }; let response = process_command(&config); @@ -96,6 +97,7 @@ fn test_cli_deploy_program() { config.command = CliCommand::Deploy { program_location: pathbuf.to_str().unwrap().to_string(), address: Some(1), + use_deprecated_loader: false, }; process_command(&config).unwrap(); let account1 = rpc_client