Skip to content

Commit

Permalink
bug: clear fat transactions from mempool before new mining jobs are d…
Browse files Browse the repository at this point in the history
…eclared
  • Loading branch information
NonsoAmadi10 committed May 10, 2024
1 parent b46355b commit 815f09a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use roles_logic_sv2::{
},
parsers::JobDeclaration,
};

use std::{convert::TryInto, io::Cursor};
use stratum_common::bitcoin::{Transaction, Txid};
pub type SendTo = SendTo_<JobDeclaration<'static>, ()>;
Expand Down Expand Up @@ -61,6 +62,19 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
}

fn handle_declare_mining_job(&mut self, message: DeclareMiningJob) -> Result<SendTo, Error> {
{
// Clear previous declared job data
self.declared_mining_job.0 = None;
let clear_mempool = self.mempool.safe_lock(|x| x.mempool.clear());

if let Err(e) = clear_mempool {
return Err(roles_logic_sv2::Error::PoisonLock(format!(
"Failed to lock and clear mempool: {}",
e
)));
}
}

// 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 transaction.
// The unknown transactions is a vector that contains the transactions that are not in the
Expand Down
12 changes: 12 additions & 0 deletions roles/jd-server/src/lib/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ impl JDsMempool {
.ok_or(JdsMempoolError::NoClient)?;

let mempool: Vec<String> = client.get_raw_mempool().await?;

let mempool_txids: Vec<Txid> = mempool
.iter()
.map(|s| Txid::from_str(s))
.filter_map(Result::ok) // Handle invalid conversions
.collect();
for txid in &mempool_txids {
if !mempool_ordered.contains_key(txid) {
mempool_ordered.insert(*txid, None);
}
}

for id in &mempool {
let key_id = Txid::from_str(id)
.map_err(|err| JdsMempoolError::Rpc(RpcError::Deserialization(err.to_string())))?;
Expand Down

0 comments on commit 815f09a

Please sign in to comment.