Skip to content

Commit

Permalink
chore: compare tx in nodemempool and jds mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
NonsoAmadi10 committed May 3, 2024
1 parent 58fef45 commit 6c91bb6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions roles/jd-server/src/lib/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,27 @@ impl JDsMempool {
JdsMempoolError::Rpc(RpcError::Deserialization(err_msg))
})?;

// Populate mempool_ordered with existing JDS mempool data
mempool_ordered.extend(current_jds_mempool);
// Convert raw mempool to a vector of Txids
let mempool_txids: Vec<Txid> = mempool
.iter()
.map(|id| Txid::from_str(id))
.collect::<Result<Vec<_>, _>>()
.map_err(|err| JdsMempoolError::Rpc(RpcError::Deserialization(format!("Error converting Txid: {:?}", err))))?;


// Populate mempool_ordered using match
for txid in &mempool_txids {
match current_jds_mempool.get(txid) {
Some(Some(transaction)) => {
// If a known transaction, store it in mempool_ordered
mempool_ordered.insert(*txid, Some(transaction.clone()));
}
Some(None) | None => {
// If the transaction is unknown or it's an empty entry, store as a placeholder
mempool_ordered.insert(*txid, None);
}
}
}

for id in &mempool {
let key_id = Txid::from_str(id).map_err(|err| {
Expand Down

0 comments on commit 6c91bb6

Please sign in to comment.