Skip to content

Commit b113b56

Browse files
committed
feat: Set pending hodl invoice to canceled on startup.
At the coordinator startup we stopped all tasks watching invoices. Thus we can safely set all `Open` or `Accepted` (pending) invoices to `Canceled`.
1 parent f72e1f0 commit b113b56

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

coordinator/src/bin/coordinator.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use anyhow::Result;
33
use bitcoin::key::XOnlyPublicKey;
44
use coordinator::backup::SledBackup;
55
use coordinator::cli::Opts;
6+
use coordinator::db;
67
use coordinator::dlc_handler;
78
use coordinator::dlc_handler::DlcHandler;
89
use coordinator::logger;
@@ -356,6 +357,20 @@ async fn main() -> Result<()> {
356357
}
357358
});
358359

360+
if let Err(e) = spawn_blocking({
361+
let pool = pool.clone();
362+
move || {
363+
let mut conn = pool.get()?;
364+
db::hodl_invoice::cancel_pending_hodl_invoices(&mut conn)?;
365+
anyhow::Ok(())
366+
}
367+
})
368+
.await
369+
.expect("task to finish")
370+
{
371+
tracing::error!("Failed to set expired hodl invoices to canceled. Error: {e:#}");
372+
}
373+
359374
tracing::debug!("Listening on http://{}", http_address);
360375

361376
match axum::Server::bind(&http_address)

coordinator/src/db/hodl_invoice.rs

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ impl QueryId for InvoiceStateType {
3535
}
3636
}
3737

38+
pub fn cancel_pending_hodl_invoices(conn: &mut PgConnection) -> QueryResult<usize> {
39+
diesel::update(hodl_invoices::table)
40+
.filter(hodl_invoices::invoice_state.eq_any([InvoiceState::Open, InvoiceState::Accepted]))
41+
.set(hodl_invoices::invoice_state.eq(InvoiceState::Canceled))
42+
.execute(conn)
43+
}
44+
3845
pub fn create_hodl_invoice(
3946
conn: &mut PgConnection,
4047
r_hash: &str,

0 commit comments

Comments
 (0)