Remove feature switch for demoting sysvar write locks (#18373) (#18454)

Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
mergify[bot]
2021-07-06 23:25:28 +00:00
committed by GitHub
parent 6afeaac7a5
commit 72ed4f28b1
11 changed files with 70 additions and 184 deletions

View File

@@ -8,7 +8,7 @@ use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{demote_sysvar_write_locks, instructions_sysvar_enabled, FeatureSet},
feature_set::{instructions_sysvar_enabled, FeatureSet},
ic_logger_msg, ic_msg,
instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount},
@@ -294,7 +294,6 @@ impl<'a> ThisInvokeContext<'a> {
instruction,
executable_accounts,
accounts,
feature_set.is_active(&demote_sysvar_write_locks::id()),
);
let mut invoke_context = Self {
invoke_stack: Vec::with_capacity(bpf_compute_budget.max_invoke_depth),
@@ -410,7 +409,6 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
&self.rent,
caller_write_privileges,
&mut self.timings,
self.feature_set.is_active(&demote_sysvar_write_locks::id()),
logger,
)
}
@@ -622,7 +620,6 @@ impl MessageProcessor {
instruction: &'a CompiledInstruction,
executable_accounts: &'a [(Pubkey, Rc<RefCell<AccountSharedData>>)],
accounts: &'a [Rc<RefCell<AccountSharedData>>],
demote_sysvar_write_locks: bool,
) -> Vec<(bool, bool, &'a Pubkey, &'a RefCell<AccountSharedData>)> {
executable_accounts
.iter()
@@ -631,7 +628,7 @@ impl MessageProcessor {
let index = *index as usize;
(
message.is_signer(index),
message.is_writable(index, demote_sysvar_write_locks),
message.is_writable(index),
&message.account_keys[index],
&accounts[index] as &RefCell<AccountSharedData>,
)
@@ -768,7 +765,6 @@ impl MessageProcessor {
accounts,
keyed_account_indices_reordered,
caller_write_privileges,
demote_sysvar_write_locks,
) = {
let invoke_context = invoke_context.borrow();
@@ -861,7 +857,6 @@ impl MessageProcessor {
accounts,
keyed_account_indices_reordered,
caller_write_privileges,
invoke_context.is_feature_active(&demote_sysvar_write_locks::id()),
)
};
@@ -886,9 +881,7 @@ impl MessageProcessor {
{
let dst_keyed_account = &keyed_accounts[dst_keyed_account_index];
let src_keyed_account = account.borrow();
if message.is_writable(src_keyed_account_index, demote_sysvar_write_locks)
&& !src_keyed_account.executable()
{
if message.is_writable(src_keyed_account_index) && !src_keyed_account.executable() {
if dst_keyed_account.data_len()? != src_keyed_account.data().len()
&& dst_keyed_account.data_len()? != 0
{
@@ -937,13 +930,8 @@ impl MessageProcessor {
)?;
// Construct keyed accounts
let keyed_accounts = Self::create_keyed_accounts(
message,
instruction,
executable_accounts,
accounts,
invoke_context.is_feature_active(&demote_sysvar_write_locks::id()),
);
let keyed_accounts =
Self::create_keyed_accounts(message, instruction, executable_accounts, accounts);
// Invoke callee
invoke_context.push(program_id, &keyed_accounts)?;
@@ -1013,7 +1001,6 @@ impl MessageProcessor {
accounts: &[Rc<RefCell<AccountSharedData>>],
rent: &Rent,
timings: &mut ExecuteDetailsTimings,
demote_sysvar_write_locks: bool,
logger: Rc<RefCell<dyn Logger>>,
) -> Result<(), InstructionError> {
// Verify all executable accounts have zero outstanding refs
@@ -1034,7 +1021,7 @@ impl MessageProcessor {
pre_accounts[unique_index]
.verify(
program_id,
message.is_writable(account_index, demote_sysvar_write_locks),
message.is_writable(account_index),
rent,
&account,
timings,
@@ -1074,7 +1061,6 @@ impl MessageProcessor {
rent: &Rent,
caller_write_privileges: Option<&[bool]>,
timings: &mut ExecuteDetailsTimings,
demote_sysvar_write_locks: bool,
logger: Rc<RefCell<dyn Logger>>,
) -> Result<(), InstructionError> {
// Verify the per-account instruction results
@@ -1086,7 +1072,7 @@ impl MessageProcessor {
let is_writable = if let Some(caller_write_privileges) = caller_write_privileges {
caller_write_privileges[account_index]
} else {
message.is_writable(account_index, demote_sysvar_write_locks)
message.is_writable(account_index)
};
// Find the matching PreAccount
for pre_account in pre_accounts.iter_mut() {
@@ -1145,7 +1131,6 @@ impl MessageProcessor {
feature_set: Arc<FeatureSet>,
bpf_compute_budget: BpfComputeBudget,
timings: &mut ExecuteDetailsTimings,
demote_sysvar_write_locks: bool,
account_db: Arc<Accounts>,
ancestors: &Ancestors,
) -> Result<(), InstructionError> {
@@ -1191,7 +1176,6 @@ impl MessageProcessor {
accounts,
&rent_collector.rent,
timings,
demote_sysvar_write_locks,
invoke_context.get_logger(),
)?;
@@ -1221,7 +1205,6 @@ impl MessageProcessor {
account_db: Arc<Accounts>,
ancestors: &Ancestors,
) -> Result<(), TransactionError> {
let demote_sysvar_write_locks = feature_set.is_active(&demote_sysvar_write_locks::id());
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
let instruction_recorder = instruction_recorders
.as_ref()
@@ -1240,7 +1223,6 @@ impl MessageProcessor {
feature_set.clone(),
bpf_compute_budget,
timings,
demote_sysvar_write_locks,
account_db.clone(),
ancestors,
)
@@ -2245,13 +2227,11 @@ mod tests {
);
// not owned account modified by the caller (before the invoke)
let demote_sysvar_write_locks =
invoke_context.is_feature_active(&demote_sysvar_write_locks::id());
let caller_write_privileges = message
.account_keys
.iter()
.enumerate()
.map(|(i, _)| message.is_writable(i, demote_sysvar_write_locks))
.map(|(i, _)| message.is_writable(i))
.collect::<Vec<bool>>();
accounts[0].borrow_mut().data_as_mut_slice()[0] = 1;
assert_eq!(
@@ -2307,7 +2287,7 @@ mod tests {
.account_keys
.iter()
.enumerate()
.map(|(i, _)| message.is_writable(i, demote_sysvar_write_locks))
.map(|(i, _)| message.is_writable(i))
.collect::<Vec<bool>>();
assert_eq!(
MessageProcessor::process_cross_program_instruction(