Skip to content

Commit

Permalink
feat: Set pending hodl invoice to canceled on startup.
Browse files Browse the repository at this point in the history
At the coordinator startup we stopped all tasks watching invoices. Thus we can safely set all `Open` or `Accepted`  (pending) invoices to `Canceled`.
  • Loading branch information
holzeis committed May 31, 2024
1 parent f72e1f0 commit b113b56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Result;
use bitcoin::key::XOnlyPublicKey;
use coordinator::backup::SledBackup;
use coordinator::cli::Opts;
use coordinator::db;
use coordinator::dlc_handler;
use coordinator::dlc_handler::DlcHandler;
use coordinator::logger;
Expand Down Expand Up @@ -356,6 +357,20 @@ async fn main() -> Result<()> {
}
});

if let Err(e) = spawn_blocking({
let pool = pool.clone();
move || {
let mut conn = pool.get()?;
db::hodl_invoice::cancel_pending_hodl_invoices(&mut conn)?;
anyhow::Ok(())
}
})
.await
.expect("task to finish")
{
tracing::error!("Failed to set expired hodl invoices to canceled. Error: {e:#}");
}

tracing::debug!("Listening on http://{}", http_address);

match axum::Server::bind(&http_address)
Expand Down
7 changes: 7 additions & 0 deletions coordinator/src/db/hodl_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ impl QueryId for InvoiceStateType {
}
}

pub fn cancel_pending_hodl_invoices(conn: &mut PgConnection) -> QueryResult<usize> {
diesel::update(hodl_invoices::table)
.filter(hodl_invoices::invoice_state.eq_any([InvoiceState::Open, InvoiceState::Accepted]))
.set(hodl_invoices::invoice_state.eq(InvoiceState::Canceled))
.execute(conn)
}

pub fn create_hodl_invoice(
conn: &mut PgConnection,
r_hash: &str,
Expand Down

0 comments on commit b113b56

Please sign in to comment.