Skip to content

Commit

Permalink
Check if a tx is already present in mempool
Browse files Browse the repository at this point in the history
apply Fi3 suggestion
GitGab19#16 (comment)
  • Loading branch information
lorbax committed Mar 21, 2024
1 parent a94be13 commit d99d438
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {

fn handle_declare_mining_job(&mut self, message: DeclareMiningJob) -> Result<SendTo, Error> {
// 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<Txid> = vec![];
Expand Down
12 changes: 7 additions & 5 deletions roles/jd-server/src/lib/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d99d438

Please sign in to comment.