diff --git a/pool/src/pool.rs b/pool/src/pool.rs index b4bcb9b6f..03565853e 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -57,6 +57,11 @@ impl Pool { } } + /// Does the transaction pool contain an entry for the given transaction? + pub fn contains_tx(&self, tx: &Transaction) -> bool { + self.entries.iter().any(|x| x.tx.hash() == tx.hash()) + } + /// Query the tx pool for all known txs based on kernel short_ids /// from the provided compact_block. /// Note: does not validate that we return the full set of required txs. diff --git a/pool/src/transaction_pool.rs b/pool/src/transaction_pool.rs index 4ff236200..ce9b3ab5f 100644 --- a/pool/src/transaction_pool.rs +++ b/pool/src/transaction_pool.rs @@ -101,6 +101,12 @@ impl TransactionPool { stem: bool, block_hash: &Hash, ) -> Result<(), PoolError> { + // Quick check to deal with common case of seeing the *same* tx + // broadcast from multiple peers simultaneously. + if !stem && self.txpool.contains_tx(&tx) { + return Err(PoolError::DuplicateTx); + } + // Do we have the capacity to accept this transaction? self.is_acceptable(&tx)?;