MCPcopy Create free account
hub / github.com/ElementsProject/lightning / migrate_invoice_created_index_var

Function migrate_invoice_created_index_var

wallet/db.c:735–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

733}
734
735void migrate_invoice_created_index_var(struct lightningd *ld, struct db *db)
736{
737 struct db_stmt *stmt;
738 s64 badindex, realindex;
739
740 /* Prior migration had a typo! But we might have run since
741 * then and created an invoice, so we have to set the real one
742 * to the max of the two... */
743 badindex = db_get_intvar(db, "last_invoice_created_index", -1);
744 realindex = db_get_intvar(db, "last_invoices_created_index", -1);
745
746 /* Bad index does not exist? Fine */
747 if (badindex < 0)
748 return;
749
750 /* Bad index exists, real index doesn't? Rename */
751 if (badindex >= 0 && realindex < 0) {
752 stmt = db_prepare_v2(db, SQL("UPDATE vars"
753 " SET name = 'last_invoices_created_index'"
754 " WHERE name = 'last_invoice_created_index'"));
755 db_exec_prepared_v2(stmt);
756 tal_free(stmt);
757 return;
758 }
759
760 /* Both exist. Correct value is the higher one. */
761 if (badindex > realindex)
762 realindex = badindex;
763
764 /* Update correct one, remove bad one. */
765 db_set_intvar(db, "last_invoices_created_index", realindex);
766 stmt = db_prepare_v2(db, SQL("DELETE FROM vars"
767 " WHERE name = 'last_invoice_created_index'"));
768 db_exec_prepared_v2(stmt);
769 tal_free(stmt);
770}
771
772/* We expect to have a few of these... */
773static void migrate_initialize_wait_indexes(struct db *db,

Callers

nothing calls this directly

Calls 4

db_exec_prepared_v2Function · 0.85
tal_freeFunction · 0.85
db_set_intvarFunction · 0.85
db_get_intvarFunction · 0.50

Tested by

no test coverage detected