From d99d438268660bf31bc4d10cd7c30f7244887141 Mon Sep 17 00:00:00 2001 From: lorban Date: Thu, 21 Mar 2024 10:03:48 +0100 Subject: [PATCH] Check if a tx is already present in mempool apply Fi3 suggestion https://github.com/GitGab19/stratum/pull/16#discussion_r1532513707 --- .../src/lib/job_declarator/message_handler.rs | 2 +- roles/jd-server/src/lib/mempool/mod.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/roles/jd-server/src/lib/job_declarator/message_handler.rs b/roles/jd-server/src/lib/job_declarator/message_handler.rs index 8d0f04011..58a40fcba 100644 --- a/roles/jd-server/src/lib/job_declarator/message_handler.rs +++ b/roles/jd-server/src/lib/job_declarator/message_handler.rs @@ -62,7 +62,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { fn handle_declare_mining_job(&mut self, message: DeclareMiningJob) -> Result { // the transactions that are present in the mempool are stored here, that is sent to the - // mempool which use the rpc client to retrieve the whole data for each transactions. + // mempool which use the rpc client to retrieve the whole data for each transaction. // The unknown transactions is a vector that contains the transactions that are not in the // jds mempool, and will be non-empty in the ProvideMissingTransactionsSuccess message let mut known_transactions: Vec = vec![]; diff --git a/roles/jd-server/src/lib/mempool/mod.rs b/roles/jd-server/src/lib/mempool/mod.rs index f176fb3e1..d6a7bbd87 100644 --- a/roles/jd-server/src/lib/mempool/mod.rs +++ b/roles/jd-server/src/lib/mempool/mod.rs @@ -75,11 +75,13 @@ impl JDsMempool { // fill in the mempool the transactions id in the mempool with the full transactions // retrieved from the jd client for txid in txids { - let transaction = client - .get_raw_transaction(&txid.to_string(), None) - .await - .map_err(JdsMempoolError::Rpc)?; - let _ = self_.safe_lock(|a| a.mempool.insert(transaction.txid(), Some(transaction))); + if let None = self_.safe_lock(|a| a.mempool.get(&txid).cloned()).map_err(|e| JdsMempoolError::PoisonLock(e.to_string()))? { + let transaction = client + .get_raw_transaction(&txid.to_string(), None) + .await + .map_err(JdsMempoolError::Rpc)?; + let _ = self_.safe_lock(|a| a.mempool.insert(transaction.txid(), Some(transaction))); + } } // fill in the mempool the transactions given in input