Skip to content

Commit 85f7bef

Browse files
mergify[bot]HaoranYiHaoranYi
authored
v1.18: Revert deprecate executable feature (backport of anza-xyz#309) (anza-xyz#337)
* Revert deprecate executable feature (anza-xyz#309) * revert deprecate executable feature * add native loader account transfer test --------- Co-authored-by: HaoranYi <[email protected]> (cherry picked from commit 0f8f8cd) # Conflicts: # programs/bpf_loader/src/lib.rs # runtime/src/accounts/mod.rs # runtime/src/bank.rs # runtime/src/bank/tests.rs # sdk/src/account.rs * fix merge conflict * fix a test --------- Co-authored-by: HaoranYi <[email protected]> Co-authored-by: HaoranYi <[email protected]>
1 parent 14dfc41 commit 85f7bef

File tree

26 files changed

+356
-726
lines changed

26 files changed

+356
-726
lines changed

cli/src/program.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use {
4444
},
4545
solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery,
4646
solana_sdk::{
47-
account::{is_executable, Account},
47+
account::Account,
4848
account_utils::StateMut,
4949
bpf_loader, bpf_loader_deprecated,
5050
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
@@ -1036,15 +1036,6 @@ fn get_default_program_keypair(program_location: &Option<String>) -> Keypair {
10361036
program_keypair
10371037
}
10381038

1039-
fn is_account_executable(account: &Account) -> bool {
1040-
if account.owner == bpf_loader_deprecated::id() || account.owner == bpf_loader::id() {
1041-
account.executable
1042-
} else {
1043-
let feature_set = FeatureSet::all_enabled();
1044-
is_executable(account, &feature_set)
1045-
}
1046-
}
1047-
10481039
/// Deploy program using upgradeable loader. It also can process program upgrades
10491040
#[allow(clippy::too_many_arguments)]
10501041
fn process_program_deploy(
@@ -1101,7 +1092,7 @@ fn process_program_deploy(
11011092
.into());
11021093
}
11031094

1104-
if !is_account_executable(&account) {
1095+
if !account.executable {
11051096
// Continue an initial deploy
11061097
true
11071098
} else if let Ok(UpgradeableLoaderState::Program {
@@ -2470,7 +2461,7 @@ fn complete_partial_program_init(
24702461
) -> Result<(Vec<Instruction>, u64), Box<dyn std::error::Error>> {
24712462
let mut instructions: Vec<Instruction> = vec![];
24722463
let mut balance_needed = 0;
2473-
if is_account_executable(account) {
2464+
if account.executable {
24742465
return Err("Buffer account is already executable".into());
24752466
}
24762467
if account.owner != *loader_id && !system_program::check_id(&account.owner) {

cli/tests/program.rs

+12-32
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ use {
1414
solana_rpc_client::rpc_client::RpcClient,
1515
solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery,
1616
solana_sdk::{
17-
account::is_executable,
1817
account_utils::StateMut,
1918
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
2019
commitment_config::CommitmentConfig,
21-
feature_set::FeatureSet,
2220
pubkey::Pubkey,
2321
signature::{Keypair, NullSigner, Signer},
2422
},
@@ -102,7 +100,7 @@ fn test_cli_program_deploy_non_upgradeable() {
102100
let account0 = rpc_client.get_account(&program_id).unwrap();
103101
assert_eq!(account0.lamports, minimum_balance_for_program);
104102
assert_eq!(account0.owner, bpf_loader_upgradeable::id());
105-
assert!(is_executable(&account0, &FeatureSet::all_enabled()));
103+
assert!(account0.executable);
106104

107105
let (programdata_pubkey, _) =
108106
Pubkey::find_program_address(&[program_id.as_ref()], &bpf_loader_upgradeable::id());
@@ -112,10 +110,7 @@ fn test_cli_program_deploy_non_upgradeable() {
112110
minimum_balance_for_programdata
113111
);
114112
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
115-
assert!(!is_executable(
116-
&programdata_account,
117-
&FeatureSet::all_enabled()
118-
));
113+
assert!(!programdata_account.executable);
119114
assert_eq!(
120115
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
121116
program_data[..]
@@ -143,7 +138,7 @@ fn test_cli_program_deploy_non_upgradeable() {
143138
.unwrap();
144139
assert_eq!(account1.lamports, minimum_balance_for_program);
145140
assert_eq!(account1.owner, bpf_loader_upgradeable::id());
146-
assert!(is_executable(&account1, &FeatureSet::all_enabled()));
141+
assert!(account1.executable);
147142
let (programdata_pubkey, _) = Pubkey::find_program_address(
148143
&[custom_address_keypair.pubkey().as_ref()],
149144
&bpf_loader_upgradeable::id(),
@@ -154,10 +149,7 @@ fn test_cli_program_deploy_non_upgradeable() {
154149
minimum_balance_for_programdata
155150
);
156151
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
157-
assert!(!is_executable(
158-
&programdata_account,
159-
&FeatureSet::all_enabled()
160-
));
152+
assert!(!programdata_account.executable);
161153
assert_eq!(
162154
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
163155
program_data[..]
@@ -385,7 +377,7 @@ fn test_cli_program_deploy_with_authority() {
385377
let program_account = rpc_client.get_account(&program_keypair.pubkey()).unwrap();
386378
assert_eq!(program_account.lamports, minimum_balance_for_program);
387379
assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
388-
assert!(is_executable(&program_account, &FeatureSet::all_enabled()));
380+
assert!(program_account.executable);
389381
let (programdata_pubkey, _) = Pubkey::find_program_address(
390382
&[program_keypair.pubkey().as_ref()],
391383
&bpf_loader_upgradeable::id(),
@@ -396,10 +388,7 @@ fn test_cli_program_deploy_with_authority() {
396388
minimum_balance_for_programdata
397389
);
398390
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
399-
assert!(!is_executable(
400-
&programdata_account,
401-
&FeatureSet::all_enabled()
402-
));
391+
assert!(!programdata_account.executable);
403392
assert_eq!(
404393
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
405394
program_data[..]
@@ -433,7 +422,7 @@ fn test_cli_program_deploy_with_authority() {
433422
let program_account = rpc_client.get_account(&program_pubkey).unwrap();
434423
assert_eq!(program_account.lamports, minimum_balance_for_program);
435424
assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
436-
assert!(is_executable(&program_account, &FeatureSet::all_enabled()));
425+
assert!(program_account.executable);
437426
let (programdata_pubkey, _) =
438427
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
439428
let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
@@ -442,10 +431,7 @@ fn test_cli_program_deploy_with_authority() {
442431
minimum_balance_for_programdata
443432
);
444433
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
445-
assert!(!is_executable(
446-
&programdata_account,
447-
&FeatureSet::all_enabled()
448-
));
434+
assert!(program_account.executable);
449435
assert_eq!(
450436
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
451437
program_data[..]
@@ -470,7 +456,7 @@ fn test_cli_program_deploy_with_authority() {
470456
let program_account = rpc_client.get_account(&program_pubkey).unwrap();
471457
assert_eq!(program_account.lamports, minimum_balance_for_program);
472458
assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
473-
assert!(is_executable(&program_account, &FeatureSet::all_enabled()));
459+
assert!(program_account.executable);
474460
let (programdata_pubkey, _) =
475461
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
476462
let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
@@ -479,10 +465,7 @@ fn test_cli_program_deploy_with_authority() {
479465
minimum_balance_for_programdata
480466
);
481467
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
482-
assert!(!is_executable(
483-
&programdata_account,
484-
&FeatureSet::all_enabled()
485-
));
468+
assert!(program_account.executable);
486469
assert_eq!(
487470
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
488471
program_data[..]
@@ -529,7 +512,7 @@ fn test_cli_program_deploy_with_authority() {
529512
let program_account = rpc_client.get_account(&program_pubkey).unwrap();
530513
assert_eq!(program_account.lamports, minimum_balance_for_program);
531514
assert_eq!(program_account.owner, bpf_loader_upgradeable::id());
532-
assert!(is_executable(&program_account, &FeatureSet::all_enabled()));
515+
assert!(program_account.executable);
533516
let (programdata_pubkey, _) =
534517
Pubkey::find_program_address(&[program_pubkey.as_ref()], &bpf_loader_upgradeable::id());
535518
let programdata_account = rpc_client.get_account(&programdata_pubkey).unwrap();
@@ -538,10 +521,7 @@ fn test_cli_program_deploy_with_authority() {
538521
minimum_balance_for_programdata
539522
);
540523
assert_eq!(programdata_account.owner, bpf_loader_upgradeable::id());
541-
assert!(!is_executable(
542-
&programdata_account,
543-
&FeatureSet::all_enabled()
544-
));
524+
assert!(program_account.executable);
545525
assert_eq!(
546526
programdata_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..],
547527
program_data[..]

ledger-tool/src/program.rs

-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
545545
.get_current_instruction_context()
546546
.unwrap(),
547547
true, // copy_account_data
548-
&invoke_context.feature_set,
549548
)
550549
.unwrap();
551550

program-runtime/src/invoke_context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'a> InvokeContext<'a> {
403403
})?;
404404
let borrowed_program_account = instruction_context
405405
.try_borrow_instruction_account(self.transaction_context, program_account_index)?;
406-
if !borrowed_program_account.is_executable(&self.feature_set) {
406+
if !borrowed_program_account.is_executable() {
407407
ic_msg!(self, "Account {} is not executable", callee_program_id);
408408
return Err(InstructionError::AccountNotExecutable);
409409
}
@@ -802,17 +802,17 @@ mod tests {
802802
MockInstruction::NoopFail => return Err(InstructionError::GenericError),
803803
MockInstruction::ModifyOwned => instruction_context
804804
.try_borrow_instruction_account(transaction_context, 0)?
805-
.set_data_from_slice(&[1], &invoke_context.feature_set)?,
805+
.set_data_from_slice(&[1])?,
806806
MockInstruction::ModifyNotOwned => instruction_context
807807
.try_borrow_instruction_account(transaction_context, 1)?
808-
.set_data_from_slice(&[1], &invoke_context.feature_set)?,
808+
.set_data_from_slice(&[1])?,
809809
MockInstruction::ModifyReadonly => instruction_context
810810
.try_borrow_instruction_account(transaction_context, 2)?
811-
.set_data_from_slice(&[1], &invoke_context.feature_set)?,
811+
.set_data_from_slice(&[1])?,
812812
MockInstruction::UnbalancedPush => {
813813
instruction_context
814814
.try_borrow_instruction_account(transaction_context, 0)?
815-
.checked_add_lamports(1, &invoke_context.feature_set)?;
815+
.checked_add_lamports(1)?;
816816
let program_id = *transaction_context.get_key_of_account_at_index(3)?;
817817
let metas = vec![
818818
AccountMeta::new_readonly(
@@ -843,7 +843,7 @@ mod tests {
843843
}
844844
MockInstruction::UnbalancedPop => instruction_context
845845
.try_borrow_instruction_account(transaction_context, 0)?
846-
.checked_add_lamports(1, &invoke_context.feature_set)?,
846+
.checked_add_lamports(1)?,
847847
MockInstruction::ConsumeComputeUnits {
848848
compute_units_to_consume,
849849
desired_result,
@@ -855,7 +855,7 @@ mod tests {
855855
}
856856
MockInstruction::Resize { new_len } => instruction_context
857857
.try_borrow_instruction_account(transaction_context, 0)?
858-
.set_data(vec![0; new_len as usize], &invoke_context.feature_set)?,
858+
.set_data(vec![0; new_len as usize])?,
859859
}
860860
} else {
861861
return Err(InstructionError::InvalidInstructionData);

program-runtime/src/message_processor.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ mod tests {
217217
MockSystemInstruction::TransferLamports { lamports } => {
218218
instruction_context
219219
.try_borrow_instruction_account(transaction_context, 0)?
220-
.checked_sub_lamports(lamports, &invoke_context.feature_set)?;
220+
.checked_sub_lamports(lamports)?;
221221
instruction_context
222222
.try_borrow_instruction_account(transaction_context, 1)?
223-
.checked_add_lamports(lamports, &invoke_context.feature_set)?;
223+
.checked_add_lamports(lamports)?;
224224
Ok(())
225225
}
226226
MockSystemInstruction::ChangeData { data } => {
227227
instruction_context
228228
.try_borrow_instruction_account(transaction_context, 1)?
229-
.set_data(vec![data], &invoke_context.feature_set)?;
229+
.set_data(vec![data])?;
230230
Ok(())
231231
}
232232
}
@@ -443,14 +443,14 @@ mod tests {
443443
MockSystemInstruction::DoWork { lamports, data } => {
444444
let mut dup_account = instruction_context
445445
.try_borrow_instruction_account(transaction_context, 2)?;
446-
dup_account.checked_sub_lamports(lamports, &invoke_context.feature_set)?;
447-
to_account.checked_add_lamports(lamports, &invoke_context.feature_set)?;
448-
dup_account.set_data(vec![data], &invoke_context.feature_set)?;
446+
dup_account.checked_sub_lamports(lamports)?;
447+
to_account.checked_add_lamports(lamports)?;
448+
dup_account.set_data(vec![data])?;
449449
drop(dup_account);
450450
let mut from_account = instruction_context
451451
.try_borrow_instruction_account(transaction_context, 0)?;
452-
from_account.checked_sub_lamports(lamports, &invoke_context.feature_set)?;
453-
to_account.checked_add_lamports(lamports, &invoke_context.feature_set)?;
452+
from_account.checked_sub_lamports(lamports)?;
453+
to_account.checked_add_lamports(lamports)?;
454454
Ok(())
455455
}
456456
}

program-test/src/lib.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pub fn invoke_builtin_function(
133133
.transaction_context
134134
.get_current_instruction_context()?,
135135
true, // copy_account_data // There is no VM so direct mapping can not be implemented here
136-
&invoke_context.feature_set,
137136
)?;
138137

139138
// Deserialize data back into instruction params
@@ -164,25 +163,18 @@ pub fn invoke_builtin_function(
164163
if borrowed_account.is_writable() {
165164
if let Some(account_info) = account_info_map.get(borrowed_account.get_key()) {
166165
if borrowed_account.get_lamports() != account_info.lamports() {
167-
borrowed_account
168-
.set_lamports(account_info.lamports(), &invoke_context.feature_set)?;
166+
borrowed_account.set_lamports(account_info.lamports())?;
169167
}
170168

171169
if borrowed_account
172170
.can_data_be_resized(account_info.data_len())
173171
.is_ok()
174-
&& borrowed_account
175-
.can_data_be_changed(&invoke_context.feature_set)
176-
.is_ok()
172+
&& borrowed_account.can_data_be_changed().is_ok()
177173
{
178-
borrowed_account.set_data_from_slice(
179-
&account_info.data.borrow(),
180-
&invoke_context.feature_set,
181-
)?;
174+
borrowed_account.set_data_from_slice(&account_info.data.borrow())?;
182175
}
183176
if borrowed_account.get_owner() != account_info.owner {
184-
borrowed_account
185-
.set_owner(account_info.owner.as_ref(), &invoke_context.feature_set)?;
177+
borrowed_account.set_owner(account_info.owner.as_ref())?;
186178
}
187179
}
188180
}
@@ -293,17 +285,17 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
293285
.unwrap();
294286
if borrowed_account.get_lamports() != account_info.lamports() {
295287
borrowed_account
296-
.set_lamports(account_info.lamports(), &invoke_context.feature_set)
288+
.set_lamports(account_info.lamports())
297289
.unwrap();
298290
}
299291
let account_info_data = account_info.try_borrow_data().unwrap();
300292
// The redundant check helps to avoid the expensive data comparison if we can
301293
match borrowed_account
302294
.can_data_be_resized(account_info_data.len())
303-
.and_then(|_| borrowed_account.can_data_be_changed(&invoke_context.feature_set))
295+
.and_then(|_| borrowed_account.can_data_be_changed())
304296
{
305297
Ok(()) => borrowed_account
306-
.set_data_from_slice(&account_info_data, &invoke_context.feature_set)
298+
.set_data_from_slice(&account_info_data)
307299
.unwrap(),
308300
Err(err) if borrowed_account.get_data() != *account_info_data => {
309301
panic!("{err:?}");
@@ -313,7 +305,7 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
313305
// Change the owner at the end so that we are allowed to change the lamports and data before
314306
if borrowed_account.get_owner() != account_info.owner {
315307
borrowed_account
316-
.set_owner(account_info.owner.as_ref(), &invoke_context.feature_set)
308+
.set_owner(account_info.owner.as_ref())
317309
.unwrap();
318310
}
319311
if instruction_account.is_writable {

0 commit comments

Comments
 (0)