Skip to content

Commit

Permalink
Remove lamports_per_signature before fee calculation; removed bank.ge…
Browse files Browse the repository at this point in the history
…t_fee_for_message_with_lamports_per_signature() as it is redandent.
  • Loading branch information
tao-stones committed Jan 25, 2024
1 parent 62e7ebd commit 446abbd
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 158 deletions.
2 changes: 1 addition & 1 deletion banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl Banks for BanksServer {
) -> Option<u64> {
let bank = self.bank(commitment);
let sanitized_message = SanitizedMessage::try_from(message).ok()?;
bank.get_fee_for_message(&sanitized_message)
Some(bank.get_fee_for_message(&sanitized_message))
}
}

Expand Down
1 change: 0 additions & 1 deletion core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ impl Consumer {
process_compute_budget_instructions(message.program_instructions_iter())?.into();
let fee = bank.fee_structure.calculate_fee(
message,
bank.get_lamports_per_signature(),
&budget_limits,
bank.feature_set.is_active(
&feature_set::include_loaded_accounts_data_size_in_fee_calculation::id(),
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4017,7 +4017,7 @@ pub mod rpc_full {
.map_err(|err| {
Error::invalid_params(format!("invalid transaction message: {err}"))
})?;
let fee = bank.get_fee_for_message(&sanitized_message);
let fee = Some(bank.get_fee_for_message(&sanitized_message));
Ok(new_response(bank, fee))
}

Expand Down
19 changes: 3 additions & 16 deletions rpc/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
crate::transaction_notifier_interface::TransactionNotifierArc,
crossbeam_channel::{Receiver, RecvTimeoutError},
itertools::izip,
solana_accounts_db::transaction_results::{DurableNonceFee, TransactionExecutionDetails},
solana_accounts_db::transaction_results::TransactionExecutionDetails,
solana_ledger::{
blockstore::Blockstore,
blockstore_processor::{TransactionStatusBatch, TransactionStatusMessage},
Expand Down Expand Up @@ -99,25 +99,11 @@ impl TransactionStatusService {
status,
log_messages,
inner_instructions,
durable_nonce_fee,
return_data,
executed_units,
..
} = details;
let lamports_per_signature = match durable_nonce_fee {
Some(DurableNonceFee::Valid(lamports_per_signature)) => {
Some(lamports_per_signature)
}
Some(DurableNonceFee::Invalid) => None,
None => bank.get_lamports_per_signature_for_blockhash(
transaction.message().recent_blockhash(),
),
}
.expect("lamports_per_signature must be available");
let fee = bank.get_fee_for_message_with_lamports_per_signature(
transaction.message(),
lamports_per_signature,
);
let fee = bank.get_fee_for_message(transaction.message());
let tx_account_locks = transaction.get_account_locks_unchecked();

let inner_instructions = inner_instructions.map(|inner_instructions| {
Expand Down Expand Up @@ -215,6 +201,7 @@ pub(crate) mod tests {
solana_accounts_db::{
nonce_info::{NonceFull, NoncePartial},
rent_debits::RentDebits,
transaction_results::DurableNonceFee,
},
solana_ledger::{genesis_utils::create_genesis_config, get_tmp_ledger_path_auto_delete},
solana_runtime::bank::{Bank, TransactionBalancesSet},
Expand Down
42 changes: 7 additions & 35 deletions runtime/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use {
accounts::{LoadedTransaction, TransactionLoadResult, TransactionRent},
accounts_db::AccountsDb,
ancestors::Ancestors,
blockhash_queue::BlockhashQueue,
nonce_info::{NonceFull, NonceInfo},
nonce_info::NonceFull,
rent_collector::{RentCollector, RENT_EXEMPT_RENT_EPOCH},
rent_debits::RentDebits,
transaction_error_metrics::TransactionErrorMetrics,
Expand Down Expand Up @@ -50,7 +49,6 @@ pub(super) fn load_accounts(
ancestors: &Ancestors,
txs: &[SanitizedTransaction],
lock_results: &[TransactionCheckResult],
hash_queue: &BlockhashQueue,
error_counters: &mut TransactionErrorMetrics,
rent_collector: &RentCollector,
feature_set: &FeatureSet,
Expand All @@ -65,27 +63,14 @@ pub(super) fn load_accounts(
.zip(lock_results)
.map(|etx| match etx {
(tx, (Ok(()), nonce)) => {
let lamports_per_signature = nonce
.as_ref()
.map(|nonce| nonce.lamports_per_signature())
.unwrap_or_else(|| {
hash_queue.get_lamports_per_signature(tx.message().recent_blockhash())
});
let fee = if let Some(lamports_per_signature) = lamports_per_signature {
fee_structure.calculate_fee(
tx.message(),
lamports_per_signature,
&process_compute_budget_instructions(
tx.message().program_instructions_iter(),
)
let fee = fee_structure.calculate_fee(
tx.message(),
&process_compute_budget_instructions(tx.message().program_instructions_iter())
.unwrap_or_default()
.into(),
feature_set
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()),
)
} else {
return (Err(TransactionError::BlockhashNotFound), None);
};
feature_set
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()),
);

// load transactions
let loaded_transaction = match load_transaction_accounts(
Expand Down Expand Up @@ -524,14 +509,11 @@ mod tests {
fn load_accounts_with_fee_and_rent(
tx: Transaction,
ka: &[TransactionAccount],
lamports_per_signature: u64,
rent_collector: &RentCollector,
error_counters: &mut TransactionErrorMetrics,
feature_set: &FeatureSet,
fee_structure: &FeeStructure,
) -> Vec<TransactionLoadResult> {
let mut hash_queue = BlockhashQueue::new(100);
hash_queue.register_hash(&tx.message().recent_blockhash, lamports_per_signature);
let accounts_db = AccountsDb::new_single_for_tests();
let accounts = Accounts::new(Arc::new(accounts_db));
for ka in ka.iter() {
Expand All @@ -545,7 +527,6 @@ mod tests {
&ancestors,
&[sanitized_tx],
&[(Ok(()), None)],
&hash_queue,
error_counters,
rent_collector,
feature_set,
Expand Down Expand Up @@ -578,7 +559,6 @@ mod tests {
load_accounts_with_fee_and_rent(
tx,
ka,
lamports_per_signature,
&RentCollector::default(),
error_counters,
&all_features_except(exclude_features),
Expand Down Expand Up @@ -690,7 +670,6 @@ mod tests {
let message = SanitizedMessage::try_from(tx.message().clone()).unwrap();
let fee = FeeStructure::default().calculate_fee(
&message,
lamports_per_signature,
&process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into(),
Expand Down Expand Up @@ -781,7 +760,6 @@ mod tests {
let loaded_accounts = load_accounts_with_fee_and_rent(
tx.clone(),
&accounts,
lamports_per_signature,
&rent_collector,
&mut error_counters,
&all_features_except(None),
Expand All @@ -797,7 +775,6 @@ mod tests {
let loaded_accounts = load_accounts_with_fee_and_rent(
tx.clone(),
&accounts,
lamports_per_signature,
&rent_collector,
&mut error_counters,
&FeatureSet::all_enabled(),
Expand All @@ -814,7 +791,6 @@ mod tests {
let loaded_accounts = load_accounts_with_fee_and_rent(
tx,
&accounts,
lamports_per_signature,
&rent_collector,
&mut error_counters,
&FeatureSet::all_enabled(),
Expand Down Expand Up @@ -1013,8 +989,6 @@ mod tests {
) -> Vec<TransactionLoadResult> {
let tx = SanitizedTransaction::from_transaction_for_tests(tx);
let rent_collector = RentCollector::default();
let mut hash_queue = BlockhashQueue::new(100);
hash_queue.register_hash(tx.message().recent_blockhash(), 10);

let ancestors = vec![(0, 0)].into_iter().collect();
let mut error_counters = TransactionErrorMetrics::default();
Expand All @@ -1023,7 +997,6 @@ mod tests {
&ancestors,
&[tx],
&[(Ok(()), None)],
&hash_queue,
&mut error_counters,
&rent_collector,
&FeatureSet::all_enabled(),
Expand Down Expand Up @@ -1224,7 +1197,6 @@ mod tests {
let message = SanitizedMessage::try_from(tx.message().clone()).unwrap();
let fee = FeeStructure::default().calculate_fee(
&message,
lamports_per_signature,
&process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into(),
Expand Down
31 changes: 3 additions & 28 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4013,20 +4013,6 @@ impl Bank {
&self.fee_rate_governor
}

pub fn get_fee_for_message(&self, message: &SanitizedMessage) -> Option<u64> {
let lamports_per_signature = {
let blockhash_queue = self.blockhash_queue.read().unwrap();
blockhash_queue.get_lamports_per_signature(message.recent_blockhash())
}
.or_else(|| {
self.check_message_for_nonce(message)
.and_then(|(address, account)| {
NoncePartial::new(address, account).lamports_per_signature()
})
})?;
Some(self.get_fee_for_message_with_lamports_per_signature(message, lamports_per_signature))
}

/// Returns true when startup accounts hash verification has completed or never had to run in background.
pub fn get_startup_verification_complete(&self) -> &Arc<AtomicBool> {
&self
Expand Down Expand Up @@ -4058,14 +4044,9 @@ impl Bank {
.verification_complete()
}

pub fn get_fee_for_message_with_lamports_per_signature(
&self,
message: &SanitizedMessage,
lamports_per_signature: u64,
) -> u64 {
pub fn get_fee_for_message(&self, message: &SanitizedMessage) -> u64 {
self.fee_structure.calculate_fee(
message,
lamports_per_signature,
&process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into(),
Expand Down Expand Up @@ -5235,7 +5216,6 @@ impl Bank {
&self.ancestors,
sanitized_txs,
check_results,
&self.blockhash_queue.read().unwrap(),
error_counters,
&self.rent_collector,
&self.feature_set,
Expand Down Expand Up @@ -5539,7 +5519,7 @@ impl Bank {
TransactionExecutionResult::NotExecuted(err) => Err(err.clone()),
}?;

let (lamports_per_signature, is_nonce) = durable_nonce_fee
let (_lamports_per_signature, is_nonce) = durable_nonce_fee
.map(|durable_nonce_fee| durable_nonce_fee.lamports_per_signature())
.map(|maybe_lamports_per_signature| (maybe_lamports_per_signature, true))
.unwrap_or_else(|| {
Expand All @@ -5549,12 +5529,7 @@ impl Bank {
)
});

let lamports_per_signature =
lamports_per_signature.ok_or(TransactionError::BlockhashNotFound)?;
let fee = self.get_fee_for_message_with_lamports_per_signature(
tx.message(),
lamports_per_signature,
);
let fee = self.get_fee_for_message(tx.message());

// In case of instruction error, even though no accounts
// were stored we still need to charge the payer the
Expand Down
Loading

0 comments on commit 446abbd

Please sign in to comment.