Skip to content

Commit

Permalink
feat: add logging of cancelled outputs when transaction is rejected (#…
Browse files Browse the repository at this point in the history
…3863)

Description
---
This PR just adds some logging of which outputs were specifically cancelled when a transaction is reject by the base node. In addition when an output is marked as Unspent we also clear the Mined In Block field which will result in that output being revalidated the next time a validation is done.
  • Loading branch information
philipr-za authored Feb 22, 2022
1 parent fd32bc9 commit d28703d
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,13 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase {

for output in outputs.iter() {
if output.received_in_tx_id == Some(i64::from(tx_id)) {
info!(
target: LOG_TARGET,
"Cancelling pending inbound output with Commitment: {} - MMR Position: {:?} from TxId: {}",
output.commitment.as_ref().unwrap_or(&vec![]).to_hex(),
output.mined_mmr_position,
tx_id
);
output.update(
UpdateOutput {
status: Some(OutputStatus::CancelledInbound),
Expand All @@ -881,10 +888,18 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase {
&conn,
)?;
} else if output.spent_in_tx_id == Some(i64::from(tx_id)) {
info!(
target: LOG_TARGET,
"Cancelling pending outbound output with Commitment: {} - MMR Position: {:?} from TxId: {}",
output.commitment.as_ref().unwrap_or(&vec![]).to_hex(),
output.mined_mmr_position,
tx_id
);
output.update(
UpdateOutput {
status: Some(OutputStatus::Unspent),
spent_in_tx_id: Some(None),
mined_in_block: Some(None),
..Default::default()
},
&conn,
Expand Down Expand Up @@ -1289,6 +1304,7 @@ pub struct UpdateOutput {
script_private_key: Option<Vec<u8>>,
metadata_signature_nonce: Option<Vec<u8>>,
metadata_signature_u_key: Option<Vec<u8>>,
mined_in_block: Option<Option<Vec<u8>>>,
}

#[derive(AsChangeset)]
Expand All @@ -1301,6 +1317,7 @@ pub struct UpdateOutputSql {
script_private_key: Option<Vec<u8>>,
metadata_signature_nonce: Option<Vec<u8>>,
metadata_signature_u_key: Option<Vec<u8>>,
mined_in_block: Option<Option<Vec<u8>>>,
}

#[derive(AsChangeset)]
Expand All @@ -1323,6 +1340,7 @@ impl From<UpdateOutput> for UpdateOutputSql {
metadata_signature_u_key: u.metadata_signature_u_key,
received_in_tx_id: u.received_in_tx_id.map(|o| o.map(i64::from)),
spent_in_tx_id: u.spent_in_tx_id.map(|o| o.map(i64::from)),
mined_in_block: u.mined_in_block,
}
}
}
Expand Down

0 comments on commit d28703d

Please sign in to comment.