Cleanup activated rent_for_sysvars feature (#22454)

This commit is contained in:
Justin Starry
2022-01-14 20:34:09 +08:00
committed by GitHub
parent ae6c511f13
commit cddab635ff
7 changed files with 110 additions and 521 deletions

View File

@@ -15,7 +15,7 @@ use {
NonceError, SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH,
},
system_program,
sysvar::{self, rent::Rent},
sysvar::rent::Rent,
},
std::collections::HashSet,
};
@@ -124,19 +124,6 @@ fn assign(
return Err(InstructionError::MissingRequiredSignature);
}
// bpf programs are allowed to do this; so this is inconsistent...
// Thus, we're starting to remove this restriction from system instruction
// processor for consistency and fewer special casing by piggybacking onto
// the related feature gate..
let rent_for_sysvars = invoke_context
.feature_set
.is_active(&feature_set::rent_for_sysvars::id());
if !rent_for_sysvars && sysvar::check_id(owner) {
// guard against sysvars being made
ic_msg!(invoke_context, "Assign: cannot assign to sysvar, {}", owner);
return Err(SystemError::InvalidProgramId.into());
}
account.set_owner(*owner);
Ok(())
}
@@ -492,7 +479,6 @@ mod tests {
use solana_sdk::{
account::{self, Account, AccountSharedData},
client::SyncClient,
feature_set::FeatureSet,
genesis_config::create_genesis_config,
hash::{hash, Hash},
instruction::{AccountMeta, Instruction, InstructionError},
@@ -980,41 +966,6 @@ mod tests {
assert_eq!(result, Ok(()));
}
#[test]
fn test_create_sysvar_invalid_id_without_feature() {
let mut feature_set = FeatureSet::all_enabled();
feature_set
.active
.remove(&feature_set::rent_for_sysvars::id());
feature_set
.inactive
.insert(feature_set::rent_for_sysvars::id());
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
invoke_context.feature_set = Arc::new(feature_set);
// Attempt to create system account in account already owned by another program
let from = Pubkey::new_unique();
let from_account = RefCell::new(AccountSharedData::new(100, 0, &system_program::id()));
let to = Pubkey::new_unique();
let to_account = RefCell::new(AccountSharedData::new(0, 0, &system_program::id()));
let signers = [from, to].iter().cloned().collect::<HashSet<_>>();
let to_address = to.into();
let result = create_account(
&KeyedAccount::new(&from, true, &from_account),
&KeyedAccount::new(&to, false, &to_account),
&to_address,
50,
2,
&sysvar::id(),
&signers,
&invoke_context,
);
assert_eq!(result, Err(SystemError::InvalidProgramId.into()));
}
#[test]
fn test_create_data_populated() {
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
@@ -1151,34 +1102,6 @@ mod tests {
);
}
#[test]
fn test_assign_to_sysvar_without_feature() {
let mut feature_set = FeatureSet::all_enabled();
feature_set
.active
.remove(&feature_set::rent_for_sysvars::id());
feature_set
.inactive
.insert(feature_set::rent_for_sysvars::id());
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
invoke_context.feature_set = Arc::new(feature_set);
let new_owner = sysvar::id();
let from = Pubkey::new_unique();
let mut from_account = AccountSharedData::new(100, 0, &system_program::id());
assert_eq!(
assign(
&mut from_account,
&from.into(),
&new_owner,
&[from].iter().cloned().collect::<HashSet<_>>(),
&invoke_context,
),
Err(SystemError::InvalidProgramId.into())
);
}
#[test]
fn test_process_bogus_instruction() {
// Attempt to assign with no accounts