diff --git a/base_layer/core/src/mempool/mempool_storage.rs b/base_layer/core/src/mempool/mempool_storage.rs index b7365a8227..e00d970975 100644 --- a/base_layer/core/src/mempool/mempool_storage.rs +++ b/base_layer/core/src/mempool/mempool_storage.rs @@ -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(()) => { @@ -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, @@ -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 {