Skip to content

Commit

Permalink
Removing saturating_add_assign and replacing with Saturating struct (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
roryharr authored Dec 11, 2024
1 parent 76698c5 commit 695b3f4
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 151 deletions.
51 changes: 27 additions & 24 deletions core/src/banking_stage/consume_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,76 +357,79 @@ impl ConsumeWorkerMetrics {
) {
self.error_metrics
.total
.fetch_add(*total, Ordering::Relaxed);
.fetch_add(total.0, Ordering::Relaxed);
self.error_metrics
.account_in_use
.fetch_add(*account_in_use, Ordering::Relaxed);
.fetch_add(account_in_use.0, Ordering::Relaxed);
self.error_metrics
.too_many_account_locks
.fetch_add(*too_many_account_locks, Ordering::Relaxed);
.fetch_add(too_many_account_locks.0, Ordering::Relaxed);
self.error_metrics
.account_loaded_twice
.fetch_add(*account_loaded_twice, Ordering::Relaxed);
.fetch_add(account_loaded_twice.0, Ordering::Relaxed);
self.error_metrics
.account_not_found
.fetch_add(*account_not_found, Ordering::Relaxed);
.fetch_add(account_not_found.0, Ordering::Relaxed);
self.error_metrics
.blockhash_not_found
.fetch_add(*blockhash_not_found, Ordering::Relaxed);
.fetch_add(blockhash_not_found.0, Ordering::Relaxed);
self.error_metrics
.blockhash_too_old
.fetch_add(*blockhash_too_old, Ordering::Relaxed);
.fetch_add(blockhash_too_old.0, Ordering::Relaxed);
self.error_metrics
.call_chain_too_deep
.fetch_add(*call_chain_too_deep, Ordering::Relaxed);
.fetch_add(call_chain_too_deep.0, Ordering::Relaxed);
self.error_metrics
.already_processed
.fetch_add(*already_processed, Ordering::Relaxed);
.fetch_add(already_processed.0, Ordering::Relaxed);
self.error_metrics
.instruction_error
.fetch_add(*instruction_error, Ordering::Relaxed);
.fetch_add(instruction_error.0, Ordering::Relaxed);
self.error_metrics
.insufficient_funds
.fetch_add(*insufficient_funds, Ordering::Relaxed);
.fetch_add(insufficient_funds.0, Ordering::Relaxed);
self.error_metrics
.invalid_account_for_fee
.fetch_add(*invalid_account_for_fee, Ordering::Relaxed);
.fetch_add(invalid_account_for_fee.0, Ordering::Relaxed);
self.error_metrics
.invalid_account_index
.fetch_add(*invalid_account_index, Ordering::Relaxed);
.fetch_add(invalid_account_index.0, Ordering::Relaxed);
self.error_metrics
.invalid_program_for_execution
.fetch_add(*invalid_program_for_execution, Ordering::Relaxed);
.fetch_add(invalid_program_for_execution.0, Ordering::Relaxed);
self.error_metrics
.invalid_compute_budget
.fetch_add(*invalid_compute_budget, Ordering::Relaxed);
.fetch_add(invalid_compute_budget.0, Ordering::Relaxed);
self.error_metrics
.not_allowed_during_cluster_maintenance
.fetch_add(*not_allowed_during_cluster_maintenance, Ordering::Relaxed);
.fetch_add(not_allowed_during_cluster_maintenance.0, Ordering::Relaxed);
self.error_metrics
.invalid_writable_account
.fetch_add(*invalid_writable_account, Ordering::Relaxed);
.fetch_add(invalid_writable_account.0, Ordering::Relaxed);
self.error_metrics
.invalid_rent_paying_account
.fetch_add(*invalid_rent_paying_account, Ordering::Relaxed);
.fetch_add(invalid_rent_paying_account.0, Ordering::Relaxed);
self.error_metrics
.would_exceed_max_block_cost_limit
.fetch_add(*would_exceed_max_block_cost_limit, Ordering::Relaxed);
.fetch_add(would_exceed_max_block_cost_limit.0, Ordering::Relaxed);
self.error_metrics
.would_exceed_max_account_cost_limit
.fetch_add(*would_exceed_max_account_cost_limit, Ordering::Relaxed);
.fetch_add(would_exceed_max_account_cost_limit.0, Ordering::Relaxed);
self.error_metrics
.would_exceed_max_vote_cost_limit
.fetch_add(*would_exceed_max_vote_cost_limit, Ordering::Relaxed);
.fetch_add(would_exceed_max_vote_cost_limit.0, Ordering::Relaxed);
self.error_metrics
.would_exceed_account_data_block_limit
.fetch_add(*would_exceed_account_data_block_limit, Ordering::Relaxed);
.fetch_add(would_exceed_account_data_block_limit.0, Ordering::Relaxed);
self.error_metrics
.max_loaded_accounts_data_size_exceeded
.fetch_add(*max_loaded_accounts_data_size_exceeded, Ordering::Relaxed);
.fetch_add(max_loaded_accounts_data_size_exceeded.0, Ordering::Relaxed);
self.error_metrics
.program_execution_temporarily_restricted
.fetch_add(*program_execution_temporarily_restricted, Ordering::Relaxed);
.fetch_add(
program_execution_temporarily_restricted.0,
Ordering::Relaxed,
);
}
}

Expand Down
52 changes: 26 additions & 26 deletions core/src/banking_stage/leader_slot_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,88 +403,88 @@ fn report_transaction_error_metrics(errors: &TransactionErrorMetrics, id: &str,
"banking_stage-leader_slot_transaction_errors",
"id" => id,
("slot", slot as i64, i64),
("total", errors.total as i64, i64),
("account_in_use", errors.account_in_use as i64, i64),
("total", errors.total.0 as i64, i64),
("account_in_use", errors.account_in_use.0 as i64, i64),
(
"too_many_account_locks",
errors.too_many_account_locks as i64,
errors.too_many_account_locks.0 as i64,
i64
),
(
"account_loaded_twice",
errors.account_loaded_twice as i64,
errors.account_loaded_twice.0 as i64,
i64
),
("account_not_found", errors.account_not_found as i64, i64),
("blockhash_not_found", errors.blockhash_not_found as i64, i64),
("blockhash_too_old", errors.blockhash_too_old as i64, i64),
("call_chain_too_deep", errors.call_chain_too_deep as i64, i64),
("already_processed", errors.already_processed as i64, i64),
("instruction_error", errors.instruction_error as i64, i64),
("insufficient_funds", errors.insufficient_funds as i64, i64),
("account_not_found", errors.account_not_found.0 as i64, i64),
("blockhash_not_found", errors.blockhash_not_found.0 as i64, i64),
("blockhash_too_old", errors.blockhash_too_old.0 as i64, i64),
("call_chain_too_deep", errors.call_chain_too_deep.0 as i64, i64),
("already_processed", errors.already_processed.0 as i64, i64),
("instruction_error", errors.instruction_error.0 as i64, i64),
("insufficient_funds", errors.insufficient_funds.0 as i64, i64),
(
"invalid_account_for_fee",
errors.invalid_account_for_fee as i64,
errors.invalid_account_for_fee.0 as i64,
i64
),
(
"invalid_account_index",
errors.invalid_account_index as i64,
errors.invalid_account_index.0 as i64,
i64
),
(
"invalid_program_for_execution",
errors.invalid_program_for_execution as i64,
errors.invalid_program_for_execution.0 as i64,
i64
),
(
"invalid_compute_budget",
errors.invalid_compute_budget as i64,
errors.invalid_compute_budget.0 as i64,
i64
),
(
"not_allowed_during_cluster_maintenance",
errors.not_allowed_during_cluster_maintenance as i64,
errors.not_allowed_during_cluster_maintenance.0 as i64,
i64
),
(
"invalid_writable_account",
errors.invalid_writable_account as i64,
errors.invalid_writable_account.0 as i64,
i64
),
(
"invalid_rent_paying_account",
errors.invalid_rent_paying_account as i64,
errors.invalid_rent_paying_account.0 as i64,
i64
),
(
"would_exceed_max_block_cost_limit",
errors.would_exceed_max_block_cost_limit as i64,
errors.would_exceed_max_block_cost_limit.0 as i64,
i64
),
(
"would_exceed_max_account_cost_limit",
errors.would_exceed_max_account_cost_limit as i64,
errors.would_exceed_max_account_cost_limit.0 as i64,
i64
),
(
"would_exceed_max_vote_cost_limit",
errors.would_exceed_max_vote_cost_limit as i64,
errors.would_exceed_max_vote_cost_limit.0 as i64,
i64
),
(
"would_exceed_account_data_block_limit",
errors.would_exceed_account_data_block_limit as i64,
errors.would_exceed_account_data_block_limit.0 as i64,
i64
),
(
"max_loaded_accounts_data_size_exceeded",
errors.max_loaded_accounts_data_size_exceeded as i64,
errors.max_loaded_accounts_data_size_exceeded.0 as i64,
i64
),
(
"program_execution_temporarily_restricted",
errors.program_execution_temporarily_restricted as i64,
errors.program_execution_temporarily_restricted.0 as i64,
i64
),
);
Expand Down Expand Up @@ -745,14 +745,14 @@ impl LeaderSlotMetricsTracker {
leader_slot_metrics
.packet_count_metrics
.account_lock_throttled_transactions_count,
error_counters.account_in_use as u64
error_counters.account_in_use.0 as u64
);

saturating_add_assign!(
leader_slot_metrics
.packet_count_metrics
.account_locks_limit_throttled_transactions_count,
error_counters.too_many_account_locks as u64
error_counters.too_many_account_locks.0 as u64
);

saturating_add_assign!(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3954,7 +3954,7 @@ impl Bank {
processed_counts.processed_with_successful_result_count += 1;
}
Err(err) => {
if *err_count == 0 {
if err_count.0 == 0 {
debug!("tx error: {:?} {:?}", err, tx);
}
*err_count += 1;
Expand Down
2 changes: 1 addition & 1 deletion svm/examples/json-rpc/server/src/rpc_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl JsonRpcRequestProcessor {
processed_counts.processed_with_successful_result_count += 1;
}
Err(err) => {
if *err_count == 0 {
if err_count.0 == 0 {
debug!("tx error: {:?} {:?}", err, tx);
}
*err_count += 1;
Expand Down
31 changes: 17 additions & 14 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use {
rent::RentDue,
rent_collector::{CollectedInfo, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
saturating_add_assign,
sysvar::{
self,
instructions::{construct_instructions_data, BorrowedAccountMeta, BorrowedInstruction},
Expand All @@ -32,7 +31,11 @@ use {
solana_svm_rent_collector::svm_rent_collector::SVMRentCollector,
solana_svm_transaction::svm_message::SVMMessage,
solana_system_program::{get_system_account_kind, SystemAccountKind},
std::{collections::HashMap, num::NonZeroU32, sync::Arc},
std::{
collections::HashMap,
num::{NonZeroU32, Saturating},
sync::Arc,
},
};

// for the load instructions
Expand Down Expand Up @@ -431,7 +434,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
let mut accounts = Vec::with_capacity(account_keys.len());
let mut validated_loaders = AHashSet::with_capacity(PROGRAM_OWNERS.len());
let mut rent_debits = RentDebits::default();
let mut accumulated_accounts_data_size: u32 = 0;
let mut accumulated_accounts_data_size: Saturating<u32> = Saturating(0);

let mut collect_loaded_account = |key, loaded_account| -> Result<()> {
let LoadedTransactionAccount {
Expand Down Expand Up @@ -564,7 +567,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
program_indices,
rent: tx_rent,
rent_debits,
loaded_accounts_data_size: accumulated_accounts_data_size,
loaded_accounts_data_size: accumulated_accounts_data_size.0,
})
}

Expand Down Expand Up @@ -637,7 +640,7 @@ fn account_shared_data_from_program(
/// `accumulated_accounts_data_size` exceeds
/// `requested_loaded_accounts_data_size_limit`.
fn accumulate_and_check_loaded_account_data_size(
accumulated_loaded_accounts_data_size: &mut u32,
accumulated_loaded_accounts_data_size: &mut Saturating<u32>,
account_data_size: usize,
requested_loaded_accounts_data_size_limit: NonZeroU32,
error_metrics: &mut TransactionErrorMetrics,
Expand All @@ -646,8 +649,8 @@ fn accumulate_and_check_loaded_account_data_size(
error_metrics.max_loaded_accounts_data_size_exceeded += 1;
return Err(TransactionError::MaxLoadedAccountsDataSizeExceeded);
};
saturating_add_assign!(*accumulated_loaded_accounts_data_size, account_data_size);
if *accumulated_loaded_accounts_data_size > requested_loaded_accounts_data_size_limit.get() {
*accumulated_loaded_accounts_data_size += account_data_size;
if accumulated_loaded_accounts_data_size.0 > requested_loaded_accounts_data_size_limit.get() {
error_metrics.max_loaded_accounts_data_size_exceeded += 1;
Err(TransactionError::MaxLoadedAccountsDataSizeExceeded)
} else {
Expand Down Expand Up @@ -906,7 +909,7 @@ mod tests {

let load_results = load_accounts_aux_test(tx, &accounts, &mut error_metrics);

assert_eq!(error_metrics.account_not_found, 1);
assert_eq!(error_metrics.account_not_found.0, 1);
assert!(matches!(
load_results,
TransactionLoadResult::FeesOnly(FeesOnlyTransaction {
Expand Down Expand Up @@ -945,7 +948,7 @@ mod tests {
let loaded_accounts =
load_accounts_with_excluded_features(tx, &accounts, &mut error_metrics, None);

assert_eq!(error_metrics.account_not_found, 0);
assert_eq!(error_metrics.account_not_found.0, 0);
match &loaded_accounts {
TransactionLoadResult::Loaded(loaded_transaction) => {
assert_eq!(loaded_transaction.accounts.len(), 3);
Expand Down Expand Up @@ -986,7 +989,7 @@ mod tests {

let load_results = load_accounts_aux_test(tx, &accounts, &mut error_metrics);

assert_eq!(error_metrics.account_not_found, 1);
assert_eq!(error_metrics.account_not_found.0, 1);
assert!(matches!(
load_results,
TransactionLoadResult::FeesOnly(FeesOnlyTransaction {
Expand Down Expand Up @@ -1030,7 +1033,7 @@ mod tests {
&mut feature_set,
);

assert_eq!(error_metrics.invalid_program_for_execution, 1);
assert_eq!(error_metrics.invalid_program_for_execution.0, 1);
assert!(matches!(
load_results,
TransactionLoadResult::FeesOnly(FeesOnlyTransaction {
Expand Down Expand Up @@ -1081,7 +1084,7 @@ mod tests {
let loaded_accounts =
load_accounts_with_excluded_features(tx, &accounts, &mut error_metrics, None);

assert_eq!(error_metrics.account_not_found, 0);
assert_eq!(error_metrics.account_not_found.0, 0);
match &loaded_accounts {
TransactionLoadResult::Loaded(loaded_transaction) => {
assert_eq!(loaded_transaction.accounts.len(), 3);
Expand Down Expand Up @@ -1188,7 +1191,7 @@ mod tests {
#[test]
fn test_accumulate_and_check_loaded_account_data_size() {
let mut error_metrics = TransactionErrorMetrics::default();
let mut accumulated_data_size: u32 = 0;
let mut accumulated_data_size: Saturating<u32> = Saturating(0);
let data_size: usize = 123;
let requested_data_size_limit = NonZeroU32::new(data_size as u32).unwrap();

Expand All @@ -1200,7 +1203,7 @@ mod tests {
&mut error_metrics
)
.is_ok());
assert_eq!(data_size as u32, accumulated_data_size);
assert_eq!(data_size as u32, accumulated_data_size.0);

// fail - loading more data that would exceed limit
let another_byte: usize = 1;
Expand Down
Loading

0 comments on commit 695b3f4

Please sign in to comment.