Skip to content

Commit

Permalink
feat: removed transaction validation redundant events (tari-project#3630
Browse files Browse the repository at this point in the history
)


Description
---
- Removed transaction validation events from the code base.
- Updated the `test_callback_handler` unit test in the `wallet_ffi` to take the changes into account.


Motivation and Context
---
Dead code has to be removed.

How Has This Been Tested?
---
Unit test
  • Loading branch information
hansieodendaal authored Nov 30, 2021
1 parent 73d862f commit c3dbdc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
4 changes: 0 additions & 4 deletions base_layer/wallet/src/transaction_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ pub enum TransactionEvent {
num_confirmations: u64,
is_valid: bool,
},
TransactionValidationTimedOut(u64),
TransactionValidationStateChanged(u64),
TransactionValidationFailure(u64),
TransactionValidationAborted(u64),
TransactionValidationDelayed(u64),
Error(String),
}

Expand Down
37 changes: 6 additions & 31 deletions base_layer/wallet_ffi/src/callback_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,10 @@ where TBackend: TransactionBackend + 'static
self.receive_transaction_mined_unconfirmed_event(tx_id, num_confirmations).await;
self.trigger_balance_refresh().await;
},
TransactionEvent::TransactionValidationStateChanged(tx_id) => {
self.transaction_validation_complete_event(tx_id, CallbackValidationResults::Success);
TransactionEvent::TransactionValidationStateChanged(request_key) => {
self.transaction_validation_complete_event(request_key);
self.trigger_balance_refresh().await;
},
TransactionEvent::TransactionValidationFailure(tx_id) => {
self.transaction_validation_complete_event(tx_id, CallbackValidationResults::Failure);
},
TransactionEvent::TransactionValidationAborted(tx_id) => {
self.transaction_validation_complete_event(tx_id, CallbackValidationResults::Aborted);
},
TransactionEvent::TransactionValidationDelayed(tx_id) => {
self.transaction_validation_complete_event(tx_id, CallbackValidationResults::BaseNodeNotInSync);
},
TransactionEvent::TransactionMinedRequestTimedOut(_tx_id) |
TransactionEvent::TransactionImported(_tx_id) |
TransactionEvent::TransactionCompletedImmediately(_tx_id)
Expand Down Expand Up @@ -505,29 +496,13 @@ where TBackend: TransactionBackend + 'static
}
}

fn transaction_validation_complete_event(&mut self, request_key: u64, result: CallbackValidationResults) {
fn transaction_validation_complete_event(&mut self, request_key: u64) {
debug!(
target: LOG_TARGET,
"Calling Transaction Validation Complete callback function for Request Key: {} with result {:?}",
request_key,
result as u8,
"Calling Transaction Validation Complete callback function for Request Key: {}", request_key,
);
match result {
CallbackValidationResults::Success => unsafe {
(self.callback_transaction_validation_complete)(request_key, CallbackValidationResults::Success as u8);
},
CallbackValidationResults::Aborted => unsafe {
(self.callback_transaction_validation_complete)(request_key, CallbackValidationResults::Aborted as u8);
},
CallbackValidationResults::Failure => unsafe {
(self.callback_transaction_validation_complete)(request_key, CallbackValidationResults::Failure as u8);
},
CallbackValidationResults::BaseNodeNotInSync => unsafe {
(self.callback_transaction_validation_complete)(
request_key,
CallbackValidationResults::BaseNodeNotInSync as u8,
);
},
unsafe {
(self.callback_transaction_validation_complete)(request_key, CallbackValidationResults::Success as u8);
}
}

Expand Down
13 changes: 7 additions & 6 deletions base_layer/wallet_ffi/src/callback_handler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod test {
use crate::{callback_handler::CallbackHandler, output_manager_service_mock::MockOutputManagerService};
use tari_wallet::transaction_service::protocols::TxRejection;

#[derive(Debug)]
struct CallbackState {
pub received_tx_callback_called: bool,
pub received_tx_reply_callback_called: bool,
Expand Down Expand Up @@ -194,9 +195,9 @@ mod test {
Box::from_raw(balance);
}

unsafe extern "C" fn transaction_validation_complete_callback(_tx_id: u64, result: u8) {
unsafe extern "C" fn transaction_validation_complete_callback(request_key: u64, _result: u8) {
let mut lock = CALLBACK_STATE.lock().unwrap();
lock.callback_transaction_validation_complete += result as u32;
lock.callback_transaction_validation_complete += request_key as u32;
drop(lock);
}

Expand Down Expand Up @@ -492,7 +493,7 @@ mod test {
.unwrap();

transaction_event_sender
.send(Arc::new(TransactionEvent::TransactionValidationFailure(1u64)))
.send(Arc::new(TransactionEvent::TransactionValidationStateChanged(2u64)))
.unwrap();

oms_event_sender
Expand All @@ -508,7 +509,7 @@ mod test {
.unwrap();

transaction_event_sender
.send(Arc::new(TransactionEvent::TransactionValidationAborted(1u64)))
.send(Arc::new(TransactionEvent::TransactionValidationStateChanged(3u64)))
.unwrap();

oms_event_sender
Expand All @@ -524,7 +525,7 @@ mod test {
.unwrap();

transaction_event_sender
.send(Arc::new(TransactionEvent::TransactionValidationDelayed(1u64)))
.send(Arc::new(TransactionEvent::TransactionValidationStateChanged(4u64)))
.unwrap();

dht_event_sender
Expand All @@ -548,7 +549,7 @@ mod test {
assert!(lock.saf_messages_received);
assert_eq!(lock.callback_txo_validation_complete, 18);
assert_eq!(lock.callback_balance_updated, 5);
assert_eq!(lock.callback_transaction_validation_complete, 6);
assert_eq!(lock.callback_transaction_validation_complete, 10);

drop(lock);
}
Expand Down

0 comments on commit c3dbdc9

Please sign in to comment.