Skip to content

Commit

Permalink
JobDeclaratordownstream modified
Browse files Browse the repository at this point in the history
Now the DeclaratorDownstream has a method that retrieves the the
recognized transactions in the mempool. This method is called inside the
JobdeclaratorDownstream::accept_incomin_connections().
  • Loading branch information
lorbax committed Mar 10, 2024
1 parent a654bae commit 7014e90
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions roles/jd-server/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,58 @@ impl JobDeclaratorDownstream {
}

async fn get_job_transactions_from_mempool(self_mutex: Arc<Mutex<JobDeclaratorDownstream>>) {
let mut missing_transactions: Vec<Txid> = Vec::new();
let mut transactions_to_be_retrieved: Vec<Txid> = Vec::new();
let mut new_transactions: Vec<Transaction> = Vec::new();
self_mutex.clone().safe_lock(|a| for tx_with_state in a.declared_mining_job.clone().unwrap().1 {
match tx_with_state {
TransactionState::Present(_) => continue,
TransactionState::ToBeRetrievedFromMempool(tx) => missing_transactions.push(tx),
TransactionState::ToBeRetrievedFromMempool(tx) => transactions_to_be_retrieved.push(tx),
TransactionState::Missing => continue,
}
});
let mempool_ = self_mutex.safe_lock(|a| a.mempool.clone()).unwrap();
let client = mempool_.safe_lock(|a| a.get_client()).unwrap().unwrap();
for txid in transactions_to_be_retrieved {
let transaction = client.get_raw_transaction(&txid.to_string(), None).await.unwrap();
new_transactions.push(transaction);
// let new_tx_data: Result<Transaction, JdsMempoolError> = mempool
// .safe_lock(|x| x.get_client())
// .map_err(|e| JdsMempoolError::PoisonLock(e.to_string()))?
// .ok_or(JdsMempoolError::NoClient)?
// .get_raw_transaction(&txid.to_string(), None)
// .await
// .map_err(JdsMempoolError::Rpc);
// if let Ok(transaction) = new_tx_data {
// new_transactions.push(transaction);
// //this unwrap is safe
// } else {
// // TODO propagate error
// todo!()
// };

};
for transaction in new_transactions {
self_mutex.clone().safe_lock(|a| for transaction_with_state in &mut a.declared_mining_job.as_mut().unwrap().1 {
match transaction_with_state {
TransactionState::Present(_) => continue,
TransactionState::ToBeRetrievedFromMempool(_) => {
*transaction_with_state = TransactionState::Present(transaction);
break;
},
TransactionState::Missing => continue,
}
}).unwrap()
};
//self_mutex.clone().safe_lock(|a| for transaction_with_state in a.declared_mining_job.unwrap().1 {
// match transaction_with_state {
// TransactionState::Present(_) => continue,
// TransactionState::ToBeRetrievedFromMempool(_) => {transaction_with_state = TransactionState::Present(new_transactions.clone()[1])},
// TransactionState::Missing => continue,
// }
//});

todo!()

}

fn get_block_hex(self_mutex: Arc<Mutex<Self>>, message: SubmitSolutionJd) -> Result<String, JdsError> {
Expand Down

0 comments on commit 7014e90

Please sign in to comment.