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

Conversation

SWvheerden
Copy link
Collaborator

Description

Adds a mutex on the TMS validation process to stop multiple validations running per time.

Motivation and Context

Validation on the transactions is run when the Base_node state changes, which is an automated event triggered when a base_node lags, a new block is received, or the wallet connects to a new base node. The other path for this is user triggered where the user manually triggers a validation.

Triggering more than one validation at a time is a waste of resources and network traffic as the wallet now asks the same basenode for the same data more than once.

@SWvheerden SWvheerden changed the title fix: improve the TMS validation process feat: improve the TMS validation process Sep 19, 2022
Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

I agree with the added safeguard to ignore concurrent requests, but have some doubts about handling the inconsistent data errors (see below).

Any opinions, anyone?

)
})
.for_protocol(op_id)?;
.expect("Tx validation mined height is missing");
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not believe this is an improvement. In my mind the previous code that returned an error was better, but still not ideal.

I would prefer that we just log an error message and continue to the next last mined transaction should we have data inconsistencies. This way the protocol will not stop and do an endless repeat should we have a single row with problematic data.

Copy link
Collaborator Author

@SWvheerden SWvheerden Sep 19, 2022

Choose a reason for hiding this comment

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

I removed this as the TMS defines a mined transaction as a tx with a mined_height and mined_block.
The above query we ask to get us a transaction with these properties explicitly asks the db for this.

See:

let tx = completed_transactions::table
// Note: Check 'mined_in_block' as well as 'mined_height' is populated for faux transactions before it is confirmed
.filter(completed_transactions::mined_in_block.is_not_null())
.filter(completed_transactions::mined_height.is_not_null())
.filter(completed_transactions::mined_height.gt(0))
.order_by(completed_transactions::mined_height.desc())
.first::<CompletedTransactionSql>(&*conn)

So the only reason this can be None is if somehow the memory got corrupted between asking the db and us now getting the value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this can't be an expect

Comment on lines +2206 to +2212
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)
})?;
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.

@stringhandler stringhandler added the P-controversial Process - This PR or Issue is controversial and/or requires more attention that simpler issues label Sep 20, 2022
@stringhandler
Copy link
Collaborator

How does a user manually trigger a validation?

@stringhandler stringhandler merged commit 030bece into tari-project:development Sep 20, 2022
@SWvheerden SWvheerden deleted the sw_improve_tx_validation branch October 5, 2022 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-controversial Process - This PR or Issue is controversial and/or requires more attention that simpler issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants