Skip to content

Commit

Permalink
chore: move mempool fee check (#5777)
Browse files Browse the repository at this point in the history
Description
---
Moves the mempool fee check to before validation

Motivation and Context
---
This is a very cheap check compared to full validation. We should do
this before we check if the tx is valid so that we don't do validation
and then through away the tx because the fee is too low.
  • Loading branch information
SWvheerden authored Sep 18, 2023
1 parent 4cb3658 commit cbc2864
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions base_layer/core/src/mempool/mempool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ impl MempoolStorage {
.map(|k| k.excess_sig.get_signature().to_hex())
.unwrap_or_else(|| "None?!".into());
let timer = Instant::now();
// This check is almost free, so lets check this before we do any expensive validation.
if tx.body.get_total_fee().as_u64() < self.unconfirmed_pool.config.min_fee {
debug!(target: LOG_TARGET, "Tx: ({}) fee too low, rejecting",tx_id);
return Ok(TxStorageResponse::NotStoredFeeTooLow);
}
debug!(target: LOG_TARGET, "Inserting tx into mempool: {}", tx_id);
match self.validator.validate(&tx) {
Ok(()) => {
Expand All @@ -88,10 +93,6 @@ impl MempoolStorage {
);
let timer = Instant::now();
let weight = self.get_transaction_weighting();
if tx.body.get_total_fee().as_u64() < self.unconfirmed_pool.config.min_fee {
debug!(target: LOG_TARGET, "Tx: ({}) fee too low, rejecting",tx_id);
return Ok(TxStorageResponse::NotStoredFeeTooLow);
}
self.unconfirmed_pool.insert(tx, None, &weight)?;
debug!(
target: LOG_TARGET,
Expand All @@ -104,10 +105,6 @@ impl MempoolStorage {
Err(ValidationError::UnknownInputs(dependent_outputs)) => {
if self.unconfirmed_pool.contains_all_outputs(&dependent_outputs) {
let weight = self.get_transaction_weighting();
if tx.body.get_total_fee().as_u64() < self.unconfirmed_pool.config.min_fee {
debug!(target: LOG_TARGET, "Tx: ({}) fee too low, rejecting",tx_id);
return Ok(TxStorageResponse::NotStoredFeeTooLow);
}
self.unconfirmed_pool.insert(tx, Some(dependent_outputs), &weight)?;
Ok(TxStorageResponse::UnconfirmedPool)
} else {
Expand Down

0 comments on commit cbc2864

Please sign in to comment.