diff --git a/base_layer/wallet/src/transaction_service/error.rs b/base_layer/wallet/src/transaction_service/error.rs index fe5107bb3e..0d96676711 100644 --- a/base_layer/wallet/src/transaction_service/error.rs +++ b/base_layer/wallet/src/transaction_service/error.rs @@ -162,6 +162,8 @@ pub enum TransactionServiceError { ServiceError(String), #[error("Wallet Recovery in progress so Transaction Service Messaging Requests ignored")] WalletRecoveryInProgress, + #[error("Wallet Transaction Validation already in progress, request ignored")] + TransactionValidationInProgress, #[error("Connectivity error: {source}")] ConnectivityError { #[from] diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 094ebae3b3..33f484398b 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -74,7 +74,7 @@ use tari_script::{inputs, script, TariScript}; use tari_service_framework::{reply_channel, reply_channel::Receiver}; use tari_shutdown::ShutdownSignal; use tokio::{ - sync::{mpsc, mpsc::Sender, oneshot}, + sync::{mpsc, mpsc::Sender, oneshot, Mutex}, task::JoinHandle, }; @@ -171,6 +171,7 @@ pub struct TransactionService< wallet_db: WalletDatabase, base_node_service: BaseNodeServiceHandle, last_seen_tip_height: Option, + validation_in_progress: Arc>, } impl< @@ -269,6 +270,7 @@ where base_node_service, wallet_db, last_seen_tip_height: None, + validation_in_progress: Arc::new(Mutex::new(())), } } @@ -2199,8 +2201,15 @@ where ); let mut base_node_watch = self.connectivity().get_current_base_node_watcher(); - + let validation_in_progress = self.validation_in_progress.clone(); let join_handle = tokio::spawn(async move { + let mut _lock = validation_in_progress.try_lock().map_err(|_| { + debug!( + target: LOG_TARGET, + "Transaction Validation Protocol (Id: {}) spawned while a previous protocol was busy, ignored", id + ); + TransactionServiceProtocolError::new(id, TransactionServiceError::TransactionValidationInProgress) + })?; let exec_fut = protocol.execute(); tokio::pin!(exec_fut); loop {