Cleanup and feature gate instruction processing (#12359) (#12384)

(cherry picked from commit 22d8b3c3f8)

Co-authored-by: sakridge <sakridge@gmail.com>
This commit is contained in:
mergify[bot]
2020-09-22 06:19:14 +00:00
committed by GitHub
parent a85a2839e4
commit 0f3208dece
5 changed files with 43 additions and 19 deletions

View File

@@ -1983,6 +1983,8 @@ impl Bank {
&self.rent_collector,
log_collector.clone(),
executors.clone(),
self.cluster_type(),
self.epoch(),
);
Self::refcells_to_accounts(

View File

@@ -10,6 +10,7 @@ use solana_sdk::{
ComputeBudget, ComputeMeter, ErasedProcessInstruction, ErasedProcessInstructionWithContext,
Executor, InvokeContext, Logger, ProcessInstruction, ProcessInstructionWithContext,
},
genesis_config::ClusterType,
instruction::{CompiledInstruction, InstructionError},
message::Message,
native_loader,
@@ -656,6 +657,7 @@ impl MessageProcessor {
/// This method calls the instruction's program entrypoint method and verifies that the result of
/// the call does not violate the bank's accounting rules.
/// The accounts are committed back to the bank only if this function returns Ok(_).
#[allow(clippy::too_many_arguments)]
fn execute_instruction(
&self,
message: &Message,
@@ -666,17 +668,21 @@ impl MessageProcessor {
log_collector: Option<Rc<LogCollector>>,
executors: Rc<RefCell<Executors>>,
instruction_index: usize,
cluster_type: ClusterType,
epoch: Epoch,
) -> Result<(), InstructionError> {
// Fixup the special instructions key if present
// before the account pre-values are taken care of
for (i, key) in message.account_keys.iter().enumerate() {
if solana_sdk::sysvar::instructions::check_id(key) {
let mut mut_account_ref = accounts[i].borrow_mut();
solana_sdk::sysvar::instructions::store_current_instruction(
&mut mut_account_ref.data,
instruction_index as u16,
);
break;
if solana_sdk::sysvar::instructions::is_enabled(epoch, cluster_type) {
for (i, key) in message.account_keys.iter().enumerate() {
if solana_sdk::sysvar::instructions::check_id(key) {
let mut mut_account_ref = accounts[i].borrow_mut();
solana_sdk::sysvar::instructions::store_current_index(
&mut mut_account_ref.data,
instruction_index as u16,
);
break;
}
}
}
@@ -716,6 +722,8 @@ impl MessageProcessor {
rent_collector: &RentCollector,
log_collector: Option<Rc<LogCollector>>,
executors: Rc<RefCell<Executors>>,
cluster_type: ClusterType,
epoch: Epoch,
) -> Result<(), TransactionError> {
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
self.execute_instruction(
@@ -727,6 +735,8 @@ impl MessageProcessor {
log_collector.clone(),
executors.clone(),
instruction_index,
cluster_type,
epoch,
)
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
}
@@ -1319,6 +1329,8 @@ mod tests {
&rent_collector,
None,
executors.clone(),
ClusterType::Development,
0,
);
assert_eq!(result, Ok(()));
assert_eq!(accounts[0].borrow().lamports, 100);
@@ -1340,6 +1352,8 @@ mod tests {
&rent_collector,
None,
executors.clone(),
ClusterType::Development,
0,
);
assert_eq!(
result,
@@ -1365,6 +1379,8 @@ mod tests {
&rent_collector,
None,
executors,
ClusterType::Development,
0,
);
assert_eq!(
result,
@@ -1473,6 +1489,8 @@ mod tests {
&rent_collector,
None,
executors.clone(),
ClusterType::Development,
0,
);
assert_eq!(
result,
@@ -1498,6 +1516,8 @@ mod tests {
&rent_collector,
None,
executors.clone(),
ClusterType::Development,
0,
);
assert_eq!(result, Ok(()));
@@ -1520,6 +1540,8 @@ mod tests {
&rent_collector,
None,
executors,
ClusterType::Development,
0,
);
assert_eq!(result, Ok(()));
assert_eq!(accounts[0].borrow().lamports, 80);