From 7d886e6c85e463a4f7f4dacc5115e625bb1f37f5 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Thu, 1 Feb 2024 13:25:23 +0200 Subject: [PATCH] feat: do validation after adding utxos and txs (#6114) 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. --- .../src/utxo_scanner_service/utxo_scanner_task.rs | 12 +++++++++--- .../tests/support/output_manager_service_mock.rs | 1 + .../wallet/tests/support/transaction_service_mock.rs | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs index 4fb0fdbea8..ebd3e6f544 100644 --- a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs +++ b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs @@ -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) => { @@ -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, diff --git a/base_layer/wallet/tests/support/output_manager_service_mock.rs b/base_layer/wallet/tests/support/output_manager_service_mock.rs index 87cc1b4b1c..9f9e6ea3fc 100644 --- a/base_layer/wallet/tests/support/output_manager_service_mock.rs +++ b/base_layer/wallet/tests/support/output_manager_service_mock.rs @@ -146,6 +146,7 @@ impl OutputManagerServiceMock { e }); }, + OutputManagerRequest::ValidateUtxos => {}, _ => panic!("Output Manager Service Mock does not support this call"), } } diff --git a/base_layer/wallet/tests/support/transaction_service_mock.rs b/base_layer/wallet/tests/support/transaction_service_mock.rs index 7365cf9935..59cdba9e91 100644 --- a/base_layer/wallet/tests/support/transaction_service_mock.rs +++ b/base_layer/wallet/tests/support/transaction_service_mock.rs @@ -110,6 +110,7 @@ impl TransactionServiceMock { e }); }, + TransactionServiceRequest::ValidateTransactions => {}, _ => panic!("Transaction Service Mock does not support this call"), } }