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 451e0fd90f..4e721cc5bf 100644 --- a/roles/jd-server/src/lib/job_declarator/message_handler.rs +++ b/roles/jd-server/src/lib/job_declarator/message_handler.rs @@ -226,7 +226,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { } } -pub fn clear_declared_mining_job( +fn clear_declared_mining_job( old_mining_job: DeclareMiningJob, new_mining_job: &DeclareMiningJob, mempool: Arc>, @@ -241,39 +241,50 @@ pub fn clear_declared_mining_job( let nonce = old_mining_job.tx_short_hash_nonce; - let result = mempool.safe_lock(|mempool_| -> Result<(), Error> { - let short_ids_map = mempool_ - .to_short_ids(nonce) - .ok_or(Error::JDSMissingTransactions)?; + let result = mempool + .safe_lock(|mempool_| -> Result<(), Error> { + let short_ids_map = mempool_ + .to_short_ids(nonce) + .ok_or(Error::JDSMissingTransactions)?; - for short_id in old_transactions { - if !new_transactions.contains(&short_id) { - if let Some(transaction_with_hash) = short_ids_map.get(short_id) { + for short_id in old_transactions + .iter() + .filter(|&id| !new_transactions.contains(id)) + { + if let Some(transaction_with_hash) = short_ids_map.get(*short_id) { let txid = transaction_with_hash.id; match mempool_.mempool.get_mut(&txid) { - Some(Some((transaction, counter))) => { + Some(Some((_transaction, counter))) => { if *counter > 1 { *counter -= 1; - info!("Fat transaction {:?} decreased mempool counter because job id {:?} was dropped", txid, old_mining_job.request_id); + debug!( + "Fat transaction {:?} counter decremented; job id {:?} dropped", + txid, old_mining_job.request_id + ); } else { mempool_.mempool.remove(&txid); - info!("Fat transaction {:?} in job with request id {:?} removed from mempool", txid, old_mining_job.request_id); + debug!( + "Fat transaction {:?} with job id {:?} removed from mempool", + txid, old_mining_job.request_id + ); } - }, - Some(None) => info!("Thin transaction {:?} in job with request id {:?} removed from mempool", txid, old_mining_job.request_id), - None => {}, + } + Some(None) => debug!( + "Thin transaction {:?} with job id {:?} removed from mempool", + txid, old_mining_job.request_id + ), + None => {} } } else { - debug!("Transaction with short id {:?} not found in mempool while clearing old jobs", short_id); + debug!( + "Transaction with short id {:?} not found in mempool for old jobs", + short_id + ); } } - } - Ok(()) - }); - - if let Err(err) = result { - return Err(Error::PoisonLock(err.to_string())); - } + Ok(()) + }) + .map_err(|e| Error::PoisonLock(e.to_string()))?; - Ok(()) + result.map_err(|err| Error::PoisonLock(err.to_string())) }