Record instructions which are precompiles (#24743)
* Record instructions which are "is_precompile".
This commit is contained in:
parent
e1866aacad
commit
eae9a66531
|
@ -10,7 +10,10 @@ use {
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::WritableAccount,
|
account::WritableAccount,
|
||||||
feature_set::{prevent_calling_precompiles_as_programs, FeatureSet},
|
feature_set::{
|
||||||
|
prevent_calling_precompiles_as_programs,
|
||||||
|
record_instruction_in_transaction_context_push, FeatureSet,
|
||||||
|
},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
message::SanitizedMessage,
|
message::SanitizedMessage,
|
||||||
precompiles::is_precompile,
|
precompiles::is_precompile,
|
||||||
|
@ -86,10 +89,14 @@ impl MessageProcessor {
|
||||||
.zip(program_indices.iter())
|
.zip(program_indices.iter())
|
||||||
.enumerate()
|
.enumerate()
|
||||||
{
|
{
|
||||||
if invoke_context
|
let is_precompile = invoke_context
|
||||||
.feature_set
|
.feature_set
|
||||||
.is_active(&prevent_calling_precompiles_as_programs::id())
|
.is_active(&prevent_calling_precompiles_as_programs::id())
|
||||||
&& is_precompile(program_id, |id| invoke_context.feature_set.is_active(id))
|
&& is_precompile(program_id, |id| invoke_context.feature_set.is_active(id));
|
||||||
|
if is_precompile
|
||||||
|
&& !invoke_context
|
||||||
|
.feature_set
|
||||||
|
.is_active(&record_instruction_in_transaction_context_push::id())
|
||||||
{
|
{
|
||||||
// Precompiled programs don't have an instruction processor
|
// Precompiled programs don't have an instruction processor
|
||||||
continue;
|
continue;
|
||||||
|
@ -125,29 +132,48 @@ impl MessageProcessor {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut time = Measure::start("execute_instruction");
|
|
||||||
let mut compute_units_consumed = 0;
|
let result = if is_precompile
|
||||||
let result = invoke_context.process_instruction(
|
&& invoke_context
|
||||||
&instruction.data,
|
.feature_set
|
||||||
&instruction_accounts,
|
.is_active(&record_instruction_in_transaction_context_push::id())
|
||||||
program_indices,
|
{
|
||||||
&mut compute_units_consumed,
|
invoke_context
|
||||||
timings,
|
.transaction_context
|
||||||
);
|
.push(
|
||||||
time.stop();
|
program_indices,
|
||||||
*accumulated_consumed_units =
|
&instruction_accounts,
|
||||||
accumulated_consumed_units.saturating_add(compute_units_consumed);
|
&instruction.data,
|
||||||
timings.details.accumulate_program(
|
true,
|
||||||
program_id,
|
)
|
||||||
time.as_us(),
|
.and_then(|_| invoke_context.transaction_context.pop())
|
||||||
compute_units_consumed,
|
} else {
|
||||||
result.is_err(),
|
let mut time = Measure::start("execute_instruction");
|
||||||
);
|
let mut compute_units_consumed = 0;
|
||||||
timings.details.accumulate(&invoke_context.timings);
|
let result = invoke_context.process_instruction(
|
||||||
saturating_add_assign!(
|
&instruction.data,
|
||||||
timings.execute_accessories.process_instructions.total_us,
|
&instruction_accounts,
|
||||||
time.as_us()
|
program_indices,
|
||||||
);
|
&mut compute_units_consumed,
|
||||||
|
timings,
|
||||||
|
);
|
||||||
|
time.stop();
|
||||||
|
*accumulated_consumed_units =
|
||||||
|
accumulated_consumed_units.saturating_add(compute_units_consumed);
|
||||||
|
timings.details.accumulate_program(
|
||||||
|
program_id,
|
||||||
|
time.as_us(),
|
||||||
|
compute_units_consumed,
|
||||||
|
result.is_err(),
|
||||||
|
);
|
||||||
|
timings.details.accumulate(&invoke_context.timings);
|
||||||
|
saturating_add_assign!(
|
||||||
|
timings.execute_accessories.process_instructions.total_us,
|
||||||
|
time.as_us()
|
||||||
|
);
|
||||||
|
result
|
||||||
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||||
}
|
}
|
||||||
|
@ -625,7 +651,7 @@ mod tests {
|
||||||
(secp256k1_program::id(), secp256k1_account),
|
(secp256k1_program::id(), secp256k1_account),
|
||||||
(mock_program_id, mock_program_account),
|
(mock_program_id, mock_program_account),
|
||||||
];
|
];
|
||||||
let mut transaction_context = TransactionContext::new(accounts, 1, 1);
|
let mut transaction_context = TransactionContext::new(accounts, 1, 2);
|
||||||
|
|
||||||
let message = SanitizedMessage::Legacy(Message::new(
|
let message = SanitizedMessage::Legacy(Message::new(
|
||||||
&[
|
&[
|
||||||
|
@ -663,5 +689,6 @@ mod tests {
|
||||||
InstructionError::Custom(0xbabb1e)
|
InstructionError::Custom(0xbabb1e)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
assert_eq!(transaction_context.get_instruction_trace().len(), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue