mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-08 23:45:52 +01:00
Add explicit rollback. (#947)
The proof_writer implicit rollback on Drop is too slow for our tests causing race conditions with Postgres. This commit enhances the rollback logic and makes it explicit
This commit is contained in:
@@ -662,6 +662,7 @@ impl Mint {
|
||||
"Lightning payment for quote {} failed.",
|
||||
melt_request.quote()
|
||||
);
|
||||
proof_writer.rollback().await?;
|
||||
return Err(Error::PaymentFailed);
|
||||
}
|
||||
MeltQuoteState::Pending => {
|
||||
|
||||
@@ -143,13 +143,28 @@ impl ProofWriter {
|
||||
}
|
||||
|
||||
/// Rollback all changes in this ProofWriter consuming it.
|
||||
pub async fn rollback(mut self, tx: &mut Tx<'_, '_>) -> Result<(), Error> {
|
||||
pub async fn rollback(mut self) -> Result<(), Error> {
|
||||
let db = if let Some(db) = self.db.take() {
|
||||
db
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
let mut tx = db.begin_transaction().await?;
|
||||
let (ys, original_states) = if let Some(proofs) = self.proof_original_states.take() {
|
||||
proofs.into_iter().unzip::<_, _, Vec<_>, Vec<_>>()
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
reset_proofs_to_original_state(tx, &ys, original_states).await?;
|
||||
|
||||
tracing::info!(
|
||||
"Rollback {} proofs to their original states {:?}",
|
||||
ys.len(),
|
||||
original_states
|
||||
);
|
||||
|
||||
reset_proofs_to_original_state(&mut tx, &ys, original_states).await?;
|
||||
tx.commit().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user