From bf5b7f5d7fed294f2f1bfc652a24692818bfb8d5 Mon Sep 17 00:00:00 2001
From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com>
Date: Thu, 2 Dec 2021 12:14:57 -0600
Subject: [PATCH] report compute units without tx_wide_compute_cap feature
 enabled (#21421)

---
 runtime/src/message_processor.rs | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs
index b53f4ea614e2b2..146a7d5e700940 100644
--- a/runtime/src/message_processor.rs
+++ b/runtime/src/message_processor.rs
@@ -70,7 +70,6 @@ impl MessageProcessor {
             blockhash,
             lamports_per_signature,
         );
-        let compute_meter = invoke_context.get_compute_meter();
 
         debug_assert_eq!(program_indices.len(), message.instructions.len());
         for (instruction_index, (instruction, program_indices)) in message
@@ -87,9 +86,6 @@ impl MessageProcessor {
                 continue;
             }
 
-            let mut time = Measure::start("execute_instruction");
-            let pre_remaining_units = compute_meter.borrow().get_remaining();
-
             // Fixup the special instructions key if present
             // before the account pre-values are taken care of
             for (pubkey, accont) in accounts.iter().take(message.account_keys.len()) {
@@ -107,22 +103,27 @@ impl MessageProcessor {
             let result = invoke_context
                 .push(message, instruction, program_indices, None)
                 .and_then(|_| {
+                    let pre_remaining_units =
+                        invoke_context.get_compute_meter().borrow().get_remaining();
+                    let mut time = Measure::start("execute_instruction");
+
                     invoke_context.process_instruction(&instruction.data)?;
                     invoke_context.verify(message, instruction, program_indices)?;
+
+                    time.stop();
+                    let post_remaining_units =
+                        invoke_context.get_compute_meter().borrow().get_remaining();
+                    timings.accumulate_program(
+                        instruction.program_id(&message.account_keys),
+                        time.as_us(),
+                        pre_remaining_units - post_remaining_units,
+                    );
                     timings.accumulate(&invoke_context.timings);
                     Ok(())
                 })
                 .map_err(|err| TransactionError::InstructionError(instruction_index as u8, err));
             invoke_context.pop();
 
-            time.stop();
-            let post_remaining_units = compute_meter.borrow().get_remaining();
-            timings.accumulate_program(
-                instruction.program_id(&message.account_keys),
-                time.as_us(),
-                pre_remaining_units - post_remaining_units,
-            );
-
             result?;
         }
         Ok(())