Skip to content

Commit 9f882b0

Browse files
authored
fix(mempool): provide finalize result for invalid transactions (tari-project#1307)
Description --- fix(mempool): provide finalize result for invalid transactions Motivation and Context --- If an invalid transaction is submitted to the mempool, the final execution result is not set. This causes the queried result of the transaction to still be pending. This PR creates an execution result for the invalid transaction. How Has This Been Tested? --- Submitting a transaction that calls a non-existant template. What process can a PR reviewer use to test or verify this change? --- As above Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced an enhanced transaction finalization mechanism that provides more consistent handling of failed validations, ensuring improved management of error states. - **Refactor** - Refined system logging to offer clearer, more nuanced operational feedback during runtime processes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c5a66c0 commit 9f882b0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

applications/tari_validator_node/src/p2p/services/mempool/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where TValidator: Validator<Transaction, Context = (), Error = TransactionValida
105105
info!(target: LOG_TARGET, "Mempool service subscribing transaction messages for {shard_group} in {epoch}");
106106
self.gossip.subscribe(shard_group).await?;
107107
} else {
108-
info!(target: LOG_TARGET, "Not registered for epoch {epoch}, unsubscribing from gossip");
108+
info!(target: LOG_TARGET, "Not registered for epoch {epoch}, unsubscribing from gossip if necessary");
109109
self.gossip.unsubscribe().await?;
110110
}
111111
},
@@ -227,7 +227,7 @@ where TValidator: Validator<Transaction, Context = (), Error = TransactionValida
227227
let transaction_id = *transaction.id();
228228
self.state_store.with_write_tx(|tx| {
229229
TransactionRecord::new(transaction)
230-
.abort(RejectReason::InvalidTransaction(format!(
230+
.abort_and_finalize(RejectReason::InvalidTransaction(format!(
231231
"Mempool validation failed: {e}"
232232
)))
233233
.insert(tx)

dan_layer/storage/src/consensus_models/transaction.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ impl TransactionRecord {
175175
self
176176
}
177177

178+
pub fn abort_and_finalize(&mut self, reason: RejectReason) -> &mut Self {
179+
self.abort(reason.clone());
180+
let exec_result = self.execution_result.as_ref().filter(|r| r.finalize.result.is_reject());
181+
let execution_time = exec_result.as_ref().map(|r| r.execution_time).unwrap_or_default();
182+
self.final_decision = Some(Decision::Abort(AbortReason::from(&reason)));
183+
self.finalized_time = Some(execution_time);
184+
self.execution_result = Some(ExecuteResult {
185+
finalize: exec_result
186+
.map(|r| r.finalize.clone())
187+
.unwrap_or_else(|| FinalizeResult::new_rejected(self.transaction.id().into_array().into(), reason)),
188+
execution_time,
189+
});
190+
self
191+
}
192+
178193
pub fn is_involved_in_inputs(&self, local_committee_info: &CommitteeInfo) -> bool {
179194
self.transaction
180195
.all_inputs_iter()

0 commit comments

Comments
 (0)