Skip to content

Commit

Permalink
ask missing transactions almost finished
Browse files Browse the repository at this point in the history
in the handler of ProvideMissingTransaction, the transactions are not
decoded and it is left a todo. Once did this, the JDS is able to
1. compare the DeclareMiningJob with the mempool
2. see if there are some missing transactions, and ask for them to the
   JDclient
  • Loading branch information
lorbax committed Oct 15, 2023
1 parent c03593c commit 70499eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
50 changes: 40 additions & 10 deletions roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
}
}


// TODO important check that all the transactions in declare mining job have different
// id and there are no collisions
self.declared_mining_job = declared_mining_job.clone();
self.tx_hash_list_hash = Some(message.clone().tx_hash_list_hash.into_static());
if !there_are_some_missing_transactions {
let message_success = DeclareMiningJobSuccess {
request_id: message.request_id,
new_mining_job_token: signed_token(
message.tx_hash_list_hash,
message.tx_hash_list_hash.clone(),
&self.public_key.clone(),
&self.private_key.clone(),
),
Expand Down Expand Up @@ -139,14 +141,42 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
&mut self,
message: ProvideMissingTransactionsSuccess,
) -> Result<SendTo, Error> {
//let mut transactions: Vec<bitcoin::Transaction> = Vec::new();
//message.transaction_list.to_vec().iter().map(|x| transactions.push(bitcoin::Txid::consensus_decode(x).unwrap()));
//let mut transactions_: Vec<(bitcoin::Txid, bitcoin::Transaction)> = Vec::new();
//transactions.iter().map(|x| transactions_.push((x.txid(), *x))).collect();
//self.identified_txs = self.identified_txs + &mut transactions;
////let message_enum = JobDeclaration::ProvideMissingTransactionsSuccess(message_success);
////Ok(SendTo::Respond(message_enum))
todo!()
let mut transactions: Vec<bitcoin::Transaction> = Vec::new();
for transaction_undecoded in message.transaction_list.to_vec() {

Check failure on line 145 in roles/jd-server/src/lib/job_declarator/message_handler.rs

View workflow job for this annotation

GitHub Actions / clippy-check (macos-latest)

unused variable: `transaction_undecoded`

Check failure on line 145 in roles/jd-server/src/lib/job_declarator/message_handler.rs

View workflow job for this annotation

GitHub Actions / clippy-check (ubuntu-latest)

unused variable: `transaction_undecoded`
// TODO decode transactions and push them into transaction varuiable
todo!()
};

for declared_transaction in self.declared_mining_job.iter_mut() {
match declared_transaction {
Some(_) => {},
None => *declared_transaction = transactions.pop(),
}
}
let mut still_misses_some_transaction: bool = false;
for declared_transaction in &self.declared_mining_job {
match declared_transaction {
Some(_) => {},
None => still_misses_some_transaction = true,
}
}
if still_misses_some_transaction {
// why there are still some missing transactions? here should send some relevant error
todo!()
} else {
let tx_hash_list_hash = self.tx_hash_list_hash.clone().unwrap().into_static();
let message_success = DeclareMiningJobSuccess {
request_id: message.request_id,
new_mining_job_token: signed_token(
tx_hash_list_hash,
&self.public_key.clone(),
&self.private_key.clone(),
),
};
let message_enum_success = JobDeclaration::DeclareMiningJobSuccess(message_success);
Ok(SendTo::Respond(message_enum_success))

}
}

fn handle_submit_shares_extended(
Expand Down
2 changes: 2 additions & 0 deletions roles/jd-server/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct JobDeclaratorDownstream {
private_key: Secp256k1SecretKey,
mempool: Arc<Mutex<JDsMempool>>,
declared_mining_job: Vec<Option<stratum_common::bitcoin::Transaction>>,
tx_hash_list_hash: Option<U256<'static>>,
}

impl JobDeclaratorDownstream {
Expand Down Expand Up @@ -64,6 +65,7 @@ impl JobDeclaratorDownstream {
private_key: config.authority_secret_key.clone(),
mempool,
declared_mining_job,
tx_hash_list_hash: None
}
}

Expand Down

0 comments on commit 70499eb

Please sign in to comment.