Count compute units even when transaction errors (backport #22182) (#22199)

* Count compute units even when transaction errors (#22182)

(cherry picked from commit d06e6c7425)

# Conflicts:
#	program-runtime/src/invoke_context.rs
#	runtime/src/cost_model.rs
#	runtime/src/message_processor.rs

* Resolve conflicts

Co-authored-by: carllin <carl@solana.com>
This commit is contained in:
mergify[bot]
2021-12-31 21:14:00 +00:00
committed by GitHub
parent c6ab915668
commit 113d261a2c
7 changed files with 349 additions and 61 deletions

View File

@@ -136,6 +136,20 @@ impl CostModel {
self.instruction_execution_cost_table.get_cost_table()
}
pub fn find_instruction_cost(&self, program_key: &Pubkey) -> u64 {
match self.instruction_execution_cost_table.get_cost(program_key) {
Some(cost) => *cost,
None => {
let default_value = self.instruction_execution_cost_table.get_mode();
debug!(
"Program key {:?} does not have assigned cost, using mode {}",
program_key, default_value
);
default_value
}
}
}
fn get_signature_cost(&self, transaction: &SanitizedTransaction) -> u64 {
transaction.signatures().len() as u64 * SIGNATURE_COST
}
@@ -182,20 +196,6 @@ impl CostModel {
cost
}
fn find_instruction_cost(&self, program_key: &Pubkey) -> u64 {
match self.instruction_execution_cost_table.get_cost(program_key) {
Some(cost) => *cost,
None => {
let default_value = self.instruction_execution_cost_table.get_mode();
debug!(
"Program key {:?} does not have assigned cost, using mode {}",
program_key, default_value
);
default_value
}
}
}
fn calculate_cost_weight(&self, transaction: &SanitizedTransaction) -> u32 {
if is_simple_vote_transaction(transaction) {
// vote has zero cost weight, so it bypasses block cost limit checking

View File

@@ -3,7 +3,10 @@ use {
solana_measure::measure::Measure,
solana_program_runtime::{
instruction_recorder::InstructionRecorder,
invoke_context::{BuiltinProgram, Executors, InvokeContext, TransactionAccountRefCell},
invoke_context::{
BuiltinProgram, Executors, InvokeContext, ProcessInstructionResult,
TransactionAccountRefCell,
},
log_collector::LogCollector,
timings::ExecuteDetailsTimings,
},
@@ -105,16 +108,20 @@ impl MessageProcessor {
Some(&instruction_recorders[instruction_index]);
}
let mut time = Measure::start("execute_instruction");
let compute_meter_consumption = invoke_context
.process_instruction(message, instruction, program_indices, &[], &[])
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
let ProcessInstructionResult {
compute_units_consumed,
result,
} = invoke_context.process_instruction(message, instruction, program_indices, &[], &[]);
time.stop();
timings.accumulate_program(
instruction.program_id(&message.account_keys),
time.as_us(),
compute_meter_consumption,
compute_units_consumed,
result.is_err(),
);
timings.accumulate(&invoke_context.timings);
result
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
}
Ok(())
}