Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve the TMS validation process #4694

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions base_layer/wallet/src/transaction_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 11 additions & 2 deletions base_layer/wallet/src/transaction_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -171,6 +171,7 @@ pub struct TransactionService<
wallet_db: WalletDatabase<TWalletBackend>,
base_node_service: BaseNodeServiceHandle,
last_seen_tip_height: Option<u64>,
validation_in_progress: Arc<Mutex<()>>,
}

impl<
Expand Down Expand Up @@ -269,6 +270,7 @@ where
base_node_service,
wallet_db,
last_seen_tip_height: None,
validation_in_progress: Arc::new(Mutex::new(())),
}
}

Expand Down Expand Up @@ -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)
})?;
Comment on lines +2206 to +2212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this safeguard.

let exec_fut = protocol.execute();
tokio::pin!(exec_fut);
loop {
Expand Down