Skip to content

Commit

Permalink
feat: trigger validation on import (#4962)
Browse files Browse the repository at this point in the history
Description
---
Automatically try to trigger validation on import of utxos

Motivation and Context
---
Validation will only run once per instance, so we can try to trigger an instance of validation as soon as we added new transactions or utxos. 

Fixes: #4699
  • Loading branch information
SWvheerden authored Nov 30, 2022
1 parent 554e783 commit 163dce0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ where
OutputSource::default(),
)?;
self.resources.db.add_unvalidated_output(tx_id, output)?;

// Because we added new outputs, let try to trigger a validation for them
self.validate_outputs()?;
Ok(())
}

Expand Down
10 changes: 9 additions & 1 deletion base_layer/wallet/src/transaction_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,9 @@ where
tx_id,
current_height,
mined_timestamp,
transaction_validation_join_handles,
)
.await
.map(TransactionServiceResponse::UtxoImported),
TransactionServiceRequest::SubmitTransactionToSelf(tx_id, tx, fee, amount, message) => self
.submit_transaction_to_self(transaction_broadcast_join_handles, tx_id, tx, fee, amount, message)
Expand Down Expand Up @@ -2499,7 +2501,7 @@ where
}

/// Add a completed transaction to the Transaction Manager to record directly importing a spendable UTXO.
pub fn add_utxo_import_transaction_with_status(
pub async fn add_utxo_import_transaction_with_status(
&mut self,
value: MicroTari,
source_address: TariAddress,
Expand All @@ -2509,6 +2511,9 @@ where
tx_id: Option<TxId>,
current_height: Option<u64>,
mined_timestamp: Option<NaiveDateTime>,
transaction_validation_join_handles: &mut FuturesUnordered<
JoinHandle<Result<OperationId, TransactionServiceProtocolError<OperationId>>>,
>,
) -> Result<TxId, TransactionServiceError> {
let tx_id = if let Some(id) = tx_id { id } else { TxId::new_random() };
self.db.add_utxo_import_transaction_with_status(
Expand Down Expand Up @@ -2541,6 +2546,9 @@ where
);
e
});
// Because we added new transactions, let try to trigger a validation for them
self.start_transaction_validation_protocol(transaction_validation_join_handles)
.await?;
Ok(tx_id)
}

Expand Down
4 changes: 4 additions & 0 deletions base_layer/wallet/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@ async fn test_import_utxo() {
let output = utxo.as_transaction_output(&factories).unwrap();
let expected_output_hash = output.hash();
let node_address = TariAddress::new(node_identity.public_key().clone(), network);
alice_wallet
.set_base_node_peer(node_identity.public_key().clone(), node_identity.public_address())
.await
.unwrap();
let tx_id = alice_wallet
.import_external_utxo_as_non_rewindable(
utxo.value,
Expand Down

0 comments on commit 163dce0

Please sign in to comment.