From 8c820a8929ca97de4f4ccd09e27f6aa6eeb3ef06 Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Mon, 20 Aug 2018 23:02:28 +0100 Subject: [PATCH] Fast check for duplicate tx in the pool (#1392) --- pool/src/pool.rs | 6 ++++++ pool/src/types.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/pool/src/pool.rs b/pool/src/pool.rs index d8cac9c39..ea67989ab 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -179,6 +179,12 @@ where // Combine all the txs from the pool with any extra txs provided. let mut txs = self.all_transactions(); + + // Quick check to see if we have seen this tx before. + if txs.contains(&entry.tx) { + return Err(PoolError::DuplicateTx); + } + txs.extend(extra_txs); let agg_tx = if txs.is_empty() { diff --git a/pool/src/types.rs b/pool/src/types.rs index 8dcdec9dd..58756a164 100644 --- a/pool/src/types.rs +++ b/pool/src/types.rs @@ -174,6 +174,8 @@ pub enum PoolError { LowFeeTransaction(u64), /// Attempt to add a duplicate output to the pool. DuplicateCommitment, + /// Attempt to add a duplicate tx to the pool. + DuplicateTx, /// Other kinds of error (not yet pulled out into meaningful errors). Other(String), }