Use saturating_add_assign macro
This commit is contained in:
committed by
Trent Nelson
parent
deb9344e49
commit
72fc6096a0
@ -24,6 +24,7 @@ use {
|
|||||||
native_loader,
|
native_loader,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
saturating_add_assign,
|
||||||
sysvar::Sysvar,
|
sysvar::Sysvar,
|
||||||
transaction_context::{InstructionAccount, TransactionAccount, TransactionContext},
|
transaction_context::{InstructionAccount, TransactionAccount, TransactionContext},
|
||||||
},
|
},
|
||||||
@ -800,12 +801,12 @@ impl<'a> InvokeContext<'a> {
|
|||||||
let mut verify_caller_time = Measure::start("verify_caller_time");
|
let mut verify_caller_time = Measure::start("verify_caller_time");
|
||||||
let verify_caller_result = self.verify_and_update(instruction_accounts, true);
|
let verify_caller_result = self.verify_and_update(instruction_accounts, true);
|
||||||
verify_caller_time.stop();
|
verify_caller_time.stop();
|
||||||
timings
|
saturating_add_assign!(
|
||||||
.execute_accessories
|
timings
|
||||||
.process_instruction_verify_caller_us = timings
|
.execute_accessories
|
||||||
.execute_accessories
|
.process_instruction_verify_caller_us,
|
||||||
.process_instruction_verify_caller_us
|
verify_caller_time.as_us()
|
||||||
.saturating_add(verify_caller_time.as_us());
|
);
|
||||||
verify_caller_result?;
|
verify_caller_result?;
|
||||||
|
|
||||||
// Record instruction
|
// Record instruction
|
||||||
@ -851,18 +852,18 @@ impl<'a> InvokeContext<'a> {
|
|||||||
});
|
});
|
||||||
verify_callee_time.stop();
|
verify_callee_time.stop();
|
||||||
|
|
||||||
timings
|
saturating_add_assign!(
|
||||||
.execute_accessories
|
timings
|
||||||
.process_instruction_process_executable_chain_us = timings
|
.execute_accessories
|
||||||
.execute_accessories
|
.process_instruction_process_executable_chain_us,
|
||||||
.process_instruction_process_executable_chain_us
|
process_executable_chain_time.as_us()
|
||||||
.saturating_add(process_executable_chain_time.as_us());
|
);
|
||||||
timings
|
saturating_add_assign!(
|
||||||
.execute_accessories
|
timings
|
||||||
.process_instruction_verify_callee_us = timings
|
.execute_accessories
|
||||||
.execute_accessories
|
.process_instruction_verify_callee_us,
|
||||||
.process_instruction_verify_callee_us
|
verify_callee_time.as_us()
|
||||||
.saturating_add(verify_callee_time.as_us());
|
);
|
||||||
|
|
||||||
result
|
result
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use {solana_sdk::pubkey::Pubkey, std::collections::HashMap};
|
use {
|
||||||
|
solana_sdk::{pubkey::Pubkey, saturating_add_assign},
|
||||||
|
std::collections::HashMap,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq)]
|
#[derive(Default, Debug, PartialEq)]
|
||||||
pub struct ProgramTiming {
|
pub struct ProgramTiming {
|
||||||
@ -15,23 +18,19 @@ impl ProgramTiming {
|
|||||||
for tx_error_compute_consumed in self.errored_txs_compute_consumed.drain(..) {
|
for tx_error_compute_consumed in self.errored_txs_compute_consumed.drain(..) {
|
||||||
let compute_units_update =
|
let compute_units_update =
|
||||||
std::cmp::max(current_estimated_program_cost, tx_error_compute_consumed);
|
std::cmp::max(current_estimated_program_cost, tx_error_compute_consumed);
|
||||||
self.accumulated_units = self.accumulated_units.saturating_add(compute_units_update);
|
saturating_add_assign!(self.accumulated_units, compute_units_update);
|
||||||
self.count = self.count.saturating_add(1);
|
saturating_add_assign!(self.count, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn accumulate_program_timings(&mut self, other: &ProgramTiming) {
|
pub fn accumulate_program_timings(&mut self, other: &ProgramTiming) {
|
||||||
self.accumulated_us = self.accumulated_us.saturating_add(other.accumulated_us);
|
saturating_add_assign!(self.accumulated_us, other.accumulated_us);
|
||||||
self.accumulated_units = self
|
saturating_add_assign!(self.accumulated_units, other.accumulated_units);
|
||||||
.accumulated_units
|
saturating_add_assign!(self.count, other.count);
|
||||||
.saturating_add(other.accumulated_units);
|
|
||||||
self.count = self.count.saturating_add(other.count);
|
|
||||||
// Clones the entire vector, maybe not great...
|
// Clones the entire vector, maybe not great...
|
||||||
self.errored_txs_compute_consumed
|
self.errored_txs_compute_consumed
|
||||||
.extend(other.errored_txs_compute_consumed.clone());
|
.extend(other.errored_txs_compute_consumed.clone());
|
||||||
self.total_errored_units = self
|
saturating_add_assign!(self.total_errored_units, other.total_errored_units);
|
||||||
.total_errored_units
|
|
||||||
.saturating_add(other.total_errored_units);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,20 +50,14 @@ pub struct ExecuteTimings {
|
|||||||
|
|
||||||
impl ExecuteTimings {
|
impl ExecuteTimings {
|
||||||
pub fn accumulate(&mut self, other: &ExecuteTimings) {
|
pub fn accumulate(&mut self, other: &ExecuteTimings) {
|
||||||
self.check_us = self.check_us.saturating_add(other.check_us);
|
saturating_add_assign!(self.check_us, other.check_us);
|
||||||
self.load_us = self.load_us.saturating_add(other.load_us);
|
saturating_add_assign!(self.load_us, other.load_us);
|
||||||
self.execute_us = self.execute_us.saturating_add(other.execute_us);
|
saturating_add_assign!(self.execute_us, other.execute_us);
|
||||||
self.store_us = self.store_us.saturating_add(other.store_us);
|
saturating_add_assign!(self.store_us, other.store_us);
|
||||||
self.update_stakes_cache_us = self
|
saturating_add_assign!(self.update_stakes_cache_us, other.update_stakes_cache_us);
|
||||||
.update_stakes_cache_us
|
saturating_add_assign!(self.total_batches_len, other.total_batches_len);
|
||||||
.saturating_add(other.update_stakes_cache_us);
|
saturating_add_assign!(self.num_execute_batches, other.num_execute_batches);
|
||||||
self.total_batches_len = self
|
saturating_add_assign!(self.collect_logs_us, other.collect_logs_us);
|
||||||
.total_batches_len
|
|
||||||
.saturating_add(other.total_batches_len);
|
|
||||||
self.num_execute_batches = self
|
|
||||||
.num_execute_batches
|
|
||||||
.saturating_add(other.num_execute_batches);
|
|
||||||
self.collect_logs_us = self.collect_logs_us.saturating_add(other.collect_logs_us);
|
|
||||||
self.details.accumulate(&other.details);
|
self.details.accumulate(&other.details);
|
||||||
self.execute_accessories
|
self.execute_accessories
|
||||||
.accumulate(&other.execute_accessories);
|
.accumulate(&other.execute_accessories);
|
||||||
@ -86,31 +79,30 @@ pub struct ExecuteAccessoryTimings {
|
|||||||
|
|
||||||
impl ExecuteAccessoryTimings {
|
impl ExecuteAccessoryTimings {
|
||||||
pub fn accumulate(&mut self, other: &ExecuteAccessoryTimings) {
|
pub fn accumulate(&mut self, other: &ExecuteAccessoryTimings) {
|
||||||
self.compute_budget_process_transaction_us = self
|
saturating_add_assign!(
|
||||||
.feature_set_clone_us
|
self.compute_budget_process_transaction_us,
|
||||||
.saturating_add(other.feature_set_clone_us);
|
other.feature_set_clone_us
|
||||||
self.compute_budget_process_transaction_us = self
|
);
|
||||||
.compute_budget_process_transaction_us
|
saturating_add_assign!(
|
||||||
.saturating_add(other.compute_budget_process_transaction_us);
|
self.compute_budget_process_transaction_us,
|
||||||
self.get_executors_us = self.get_executors_us.saturating_add(other.get_executors_us);
|
other.compute_budget_process_transaction_us
|
||||||
self.process_message_us = self
|
);
|
||||||
.process_message_us
|
saturating_add_assign!(self.get_executors_us, other.get_executors_us);
|
||||||
.saturating_add(other.process_message_us);
|
saturating_add_assign!(self.process_message_us, other.process_message_us);
|
||||||
self.update_executors_us = self
|
saturating_add_assign!(self.update_executors_us, other.update_executors_us);
|
||||||
.update_executors_us
|
saturating_add_assign!(self.process_instructions_us, other.process_instructions_us);
|
||||||
.saturating_add(other.update_executors_us);
|
saturating_add_assign!(
|
||||||
self.process_instructions_us = self
|
self.process_instruction_verify_caller_us,
|
||||||
.process_instructions_us
|
other.process_instruction_verify_caller_us
|
||||||
.saturating_add(other.process_instructions_us);
|
);
|
||||||
self.process_instruction_verify_caller_us = self
|
saturating_add_assign!(
|
||||||
.process_instruction_verify_caller_us
|
self.process_instruction_process_executable_chain_us,
|
||||||
.saturating_add(other.process_instruction_verify_caller_us);
|
other.process_instruction_process_executable_chain_us
|
||||||
self.process_instruction_process_executable_chain_us = self
|
);
|
||||||
.process_instruction_process_executable_chain_us
|
saturating_add_assign!(
|
||||||
.saturating_add(other.process_instruction_process_executable_chain_us);
|
self.process_instruction_verify_callee_us,
|
||||||
self.process_instruction_verify_callee_us = self
|
other.process_instruction_verify_callee_us
|
||||||
.process_instruction_verify_callee_us
|
);
|
||||||
.saturating_add(other.process_instruction_verify_callee_us);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,35 +125,34 @@ pub struct ExecuteDetailsTimings {
|
|||||||
}
|
}
|
||||||
impl ExecuteDetailsTimings {
|
impl ExecuteDetailsTimings {
|
||||||
pub fn accumulate(&mut self, other: &ExecuteDetailsTimings) {
|
pub fn accumulate(&mut self, other: &ExecuteDetailsTimings) {
|
||||||
self.serialize_us = self.serialize_us.saturating_add(other.serialize_us);
|
saturating_add_assign!(self.serialize_us, other.serialize_us);
|
||||||
self.create_vm_us = self.create_vm_us.saturating_add(other.create_vm_us);
|
saturating_add_assign!(self.create_vm_us, other.create_vm_us);
|
||||||
self.execute_us = self.execute_us.saturating_add(other.execute_us);
|
saturating_add_assign!(self.execute_us, other.execute_us);
|
||||||
self.deserialize_us = self.deserialize_us.saturating_add(other.deserialize_us);
|
saturating_add_assign!(self.deserialize_us, other.deserialize_us);
|
||||||
self.get_or_create_executor_us = self
|
saturating_add_assign!(
|
||||||
.get_or_create_executor_us
|
self.get_or_create_executor_us,
|
||||||
.saturating_add(other.get_or_create_executor_us);
|
other.get_or_create_executor_us
|
||||||
self.changed_account_count = self
|
);
|
||||||
.changed_account_count
|
saturating_add_assign!(self.changed_account_count, other.changed_account_count);
|
||||||
.saturating_add(other.changed_account_count);
|
saturating_add_assign!(self.total_account_count, other.total_account_count);
|
||||||
self.total_account_count = self
|
saturating_add_assign!(self.total_data_size, other.total_data_size);
|
||||||
.total_account_count
|
saturating_add_assign!(self.data_size_changed, other.data_size_changed);
|
||||||
.saturating_add(other.total_account_count);
|
saturating_add_assign!(
|
||||||
self.total_data_size = self.total_data_size.saturating_add(other.total_data_size);
|
self.create_executor_register_syscalls_us,
|
||||||
self.data_size_changed = self
|
other.create_executor_register_syscalls_us
|
||||||
.data_size_changed
|
);
|
||||||
.saturating_add(other.data_size_changed);
|
saturating_add_assign!(
|
||||||
self.create_executor_register_syscalls_us = self
|
self.create_executor_load_elf_us,
|
||||||
.create_executor_register_syscalls_us
|
other.create_executor_load_elf_us
|
||||||
.saturating_add(other.create_executor_register_syscalls_us);
|
);
|
||||||
self.create_executor_load_elf_us = self
|
saturating_add_assign!(
|
||||||
.create_executor_load_elf_us
|
self.create_executor_verify_code_us,
|
||||||
.saturating_add(other.create_executor_load_elf_us);
|
other.create_executor_verify_code_us
|
||||||
self.create_executor_verify_code_us = self
|
);
|
||||||
.create_executor_verify_code_us
|
saturating_add_assign!(
|
||||||
.saturating_add(other.create_executor_verify_code_us);
|
self.create_executor_jit_compile_us,
|
||||||
self.create_executor_jit_compile_us = self
|
other.create_executor_jit_compile_us
|
||||||
.create_executor_jit_compile_us
|
);
|
||||||
.saturating_add(other.create_executor_jit_compile_us);
|
|
||||||
for (id, other) in &other.per_program_timings {
|
for (id, other) in &other.per_program_timings {
|
||||||
let program_timing = self.per_program_timings.entry(*id).or_default();
|
let program_timing = self.per_program_timings.entry(*id).or_default();
|
||||||
program_timing.accumulate_program_timings(other);
|
program_timing.accumulate_program_timings(other);
|
||||||
|
@ -51,6 +51,7 @@ use {
|
|||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
saturating_add_assign,
|
||||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||||
},
|
},
|
||||||
std::{cell::RefCell, fmt::Debug, pin::Pin, rc::Rc, sync::Arc},
|
std::{cell::RefCell, fmt::Debug, pin::Pin, rc::Rc, sync::Arc},
|
||||||
@ -335,7 +336,10 @@ fn process_instruction_common(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
get_or_create_executor_time.stop();
|
get_or_create_executor_time.stop();
|
||||||
invoke_context.timings.get_or_create_executor_us += get_or_create_executor_time.as_us();
|
saturating_add_assign!(
|
||||||
|
invoke_context.timings.get_or_create_executor_us,
|
||||||
|
get_or_create_executor_time.as_us()
|
||||||
|
);
|
||||||
|
|
||||||
executor.execute(
|
executor.execute(
|
||||||
next_first_instruction_account,
|
next_first_instruction_account,
|
||||||
|
@ -115,7 +115,7 @@ use {
|
|||||||
precompiles::get_precompiles,
|
precompiles::get_precompiles,
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
secp256k1_program,
|
saturating_add_assign, secp256k1_program,
|
||||||
signature::{Keypair, Signature},
|
signature::{Keypair, Signature},
|
||||||
slot_hashes::SlotHashes,
|
slot_hashes::SlotHashes,
|
||||||
slot_history::SlotHistory,
|
slot_history::SlotHistory,
|
||||||
@ -3561,7 +3561,10 @@ impl Bank {
|
|||||||
&loaded_transaction.program_indices,
|
&loaded_transaction.program_indices,
|
||||||
);
|
);
|
||||||
get_executors_time.stop();
|
get_executors_time.stop();
|
||||||
timings.execute_accessories.get_executors_us += get_executors_time.as_us();
|
saturating_add_assign!(
|
||||||
|
timings.execute_accessories.get_executors_us,
|
||||||
|
get_executors_time.as_us()
|
||||||
|
);
|
||||||
|
|
||||||
let mut transaction_accounts = Vec::new();
|
let mut transaction_accounts = Vec::new();
|
||||||
std::mem::swap(&mut loaded_transaction.accounts, &mut transaction_accounts);
|
std::mem::swap(&mut loaded_transaction.accounts, &mut transaction_accounts);
|
||||||
@ -3605,12 +3608,18 @@ impl Bank {
|
|||||||
self.load_accounts_data_len(),
|
self.load_accounts_data_len(),
|
||||||
);
|
);
|
||||||
process_message_time.stop();
|
process_message_time.stop();
|
||||||
timings.execute_accessories.process_message_us += process_message_time.as_us();
|
saturating_add_assign!(
|
||||||
|
timings.execute_accessories.process_message_us,
|
||||||
|
process_message_time.as_us()
|
||||||
|
);
|
||||||
|
|
||||||
let mut update_executors_time = Measure::start("update_executors_time");
|
let mut update_executors_time = Measure::start("update_executors_time");
|
||||||
self.update_executors(process_result.is_ok(), executors);
|
self.update_executors(process_result.is_ok(), executors);
|
||||||
update_executors_time.stop();
|
update_executors_time.stop();
|
||||||
timings.execute_accessories.update_executors_us += update_executors_time.as_us();
|
saturating_add_assign!(
|
||||||
|
timings.execute_accessories.update_executors_us,
|
||||||
|
update_executors_time.as_us()
|
||||||
|
);
|
||||||
|
|
||||||
let status = process_result
|
let status = process_result
|
||||||
.map(|info| {
|
.map(|info| {
|
||||||
@ -3712,8 +3721,10 @@ impl Bank {
|
|||||||
let mut feature_set_clone_time = Measure::start("feature_set_clone");
|
let mut feature_set_clone_time = Measure::start("feature_set_clone");
|
||||||
let feature_set = self.feature_set.clone();
|
let feature_set = self.feature_set.clone();
|
||||||
feature_set_clone_time.stop();
|
feature_set_clone_time.stop();
|
||||||
timings.execute_accessories.feature_set_clone_us +=
|
saturating_add_assign!(
|
||||||
feature_set_clone_time.as_us();
|
timings.execute_accessories.feature_set_clone_us,
|
||||||
|
feature_set_clone_time.as_us()
|
||||||
|
);
|
||||||
|
|
||||||
signature_count += u64::from(tx.message().header().num_required_signatures);
|
signature_count += u64::from(tx.message().header().num_required_signatures);
|
||||||
|
|
||||||
@ -3724,10 +3735,12 @@ impl Bank {
|
|||||||
let process_transaction_result =
|
let process_transaction_result =
|
||||||
compute_budget.process_transaction(tx, feature_set);
|
compute_budget.process_transaction(tx, feature_set);
|
||||||
compute_budget_process_transaction_time.stop();
|
compute_budget_process_transaction_time.stop();
|
||||||
timings
|
saturating_add_assign!(
|
||||||
.execute_accessories
|
timings
|
||||||
.compute_budget_process_transaction_us +=
|
.execute_accessories
|
||||||
compute_budget_process_transaction_time.as_us();
|
.compute_budget_process_transaction_us,
|
||||||
|
compute_budget_process_transaction_time.as_us()
|
||||||
|
);
|
||||||
if let Err(err) = process_transaction_result {
|
if let Err(err) = process_transaction_result {
|
||||||
return TransactionExecutionResult::NotExecuted(err);
|
return TransactionExecutionResult::NotExecuted(err);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ use {
|
|||||||
precompiles::is_precompile,
|
precompiles::is_precompile,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
saturating_add_assign,
|
||||||
sysvar::instructions,
|
sysvar::instructions,
|
||||||
transaction::TransactionError,
|
transaction::TransactionError,
|
||||||
transaction_context::{InstructionAccount, TransactionContext},
|
transaction_context::{InstructionAccount, TransactionContext},
|
||||||
@ -144,7 +145,10 @@ impl MessageProcessor {
|
|||||||
result.is_err(),
|
result.is_err(),
|
||||||
);
|
);
|
||||||
timings.details.accumulate(&invoke_context.timings);
|
timings.details.accumulate(&invoke_context.timings);
|
||||||
timings.execute_accessories.process_instructions_us += time.as_us();
|
saturating_add_assign!(
|
||||||
|
timings.execute_accessories.process_instructions_us,
|
||||||
|
time.as_us()
|
||||||
|
);
|
||||||
result
|
result
|
||||||
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user