Skip to content

Commit

Permalink
Error management
Browse files Browse the repository at this point in the history
Error management when some transactions are missing. The jds should not
break. Instead, tries to recover it by triggering the jds mempool to
retrieve the transactions from its bitcoin node
  • Loading branch information
lorbax committed Mar 20, 2024
1 parent d9118d4 commit 1833c24
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 116 deletions.
15 changes: 7 additions & 8 deletions roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
// mempool which use the rpc client to retrieve the whole data for each transactions.
// 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::new();
let unknown_transactions: Vec<Transaction> = Vec::new();
let mut known_transactions: Vec<Txid> = vec![];
self.tx_hash_list_hash = Some(message.tx_hash_list_hash.clone().into_static());
if self.verify_job(&message) {
let short_hash_list: Vec<ShortTxId> = message
Expand All @@ -92,7 +91,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
Some(tx_data) => {
transactions_with_state[i] = TransactionState::PresentInMempool(tx_data.id);
known_transactions.push(tx_data.id);
},
}
None => {
transactions_with_state[i] = TransactionState::Missing;
missing_txs.push(i as u16);
Expand All @@ -105,7 +104,8 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
missing_txs.clone(),
);
// here we send the transactions that we want to be stored in jds mempool with full data
self.sender_add_txs_to_mempool.send(super::AddTrasactionsToMempool { known_transactions, unknown_transactions});

self.add_txs_to_mempool.add_txs_to_mempool_inner.known_transactions.append(&mut known_transactions);

if missing_txs.is_empty() {
let message_success = DeclareMiningJobSuccess {
Expand Down Expand Up @@ -152,13 +152,12 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
message: ProvideMissingTransactionsSuccess,
) -> Result<SendTo, Error> {
let (_, ref mut transactions_with_state, missing_indexes) = &mut self.declared_mining_job;
let mut unknown_transactions: Vec<Transaction> = Vec::new();
let known_transactions: Vec<Txid> = Vec::new();
let mut unknown_transactions: Vec<Transaction> = vec![];
for (i, tx) in message.transaction_list.inner_as_ref().iter().enumerate() {
let mut cursor = Cursor::new(tx);
let transaction = Transaction::consensus_decode_from_finite_reader(&mut cursor)
.map_err(|e| Error::TxDecodingError(e.to_string()))?;
&unknown_transactions.push(transaction.clone());
Vec::push(&mut unknown_transactions, transaction.clone());
let index = *missing_indexes
.get(i)
.ok_or(Error::LogicErrorMessage(Box::new(
Expand All @@ -169,7 +168,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
// insert the missing transactions in the mempool
transactions_with_state[index] = TransactionState::PresentInMempool(transaction.txid());
}
self.sender_add_txs_to_mempool.send(super::AddTrasactionsToMempool { known_transactions, unknown_transactions: unknown_transactions.clone()});
self.add_txs_to_mempool.add_txs_to_mempool_inner.unknown_transactions.append(&mut unknown_transactions);
// if there still a missing transaction return an error
for tx_with_state in transactions_with_state {
match tx_with_state {
Expand Down
Loading

0 comments on commit 1833c24

Please sign in to comment.