Skip to content

Commit

Permalink
feat: do validation after adding utxos and txs (#6114)
Browse files Browse the repository at this point in the history
Description
---
Trigger a validation task after recovery of outputs

Motivation and Context
---
During testing, new outputs are added slower than validation and an edge
case occurs where outputs will only be validated after a new block is
added again.
  • Loading branch information
SWvheerden authored Feb 1, 2024
1 parent 92e715c commit 7d886e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ where
Some(peer) => match self.attempt_sync(peer.clone()).await {
Ok((num_outputs_recovered, final_height, final_amount, elapsed)) => {
debug!(target: LOG_TARGET, "Scanned to height #{}", final_height);
self.finalize(num_outputs_recovered, final_height, final_amount, elapsed)?;
self.finalize(num_outputs_recovered, final_height, final_amount, elapsed)
.await?;
return Ok(());
},
Err(e) => {
Expand Down Expand Up @@ -146,13 +147,18 @@ where
}
}

fn finalize(
&self,
async fn finalize(
&mut self,
num_outputs_recovered: u64,
final_height: u64,
total_value: MicroMinotari,
elapsed: Duration,
) -> Result<(), UtxoScannerError> {
if num_outputs_recovered > 0 {
// this is a best effort, if this fails, its very likely that it's already busy with a validation.
let _result = self.resources.output_manager_service.validate_txos().await;
let _result = self.resources.transaction_service.validate_transactions().await;
}
self.publish_event(UtxoScannerEvent::Progress {
current_height: final_height,
tip_height: final_height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl OutputManagerServiceMock {
e
});
},
OutputManagerRequest::ValidateUtxos => {},
_ => panic!("Output Manager Service Mock does not support this call"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl TransactionServiceMock {
e
});
},
TransactionServiceRequest::ValidateTransactions => {},
_ => panic!("Transaction Service Mock does not support this call"),
}
}
Expand Down

0 comments on commit 7d886e6

Please sign in to comment.