db: initialize variable to hold max payments id.
We generalize the invoice routine, though it's (known) buggy, so we have to copy it. We rename the invoice routine to a more specific name though. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ccb8d4b687
commit
896cb61c8c
48
wallet/db.c
48
wallet/db.c
|
@ -67,12 +67,15 @@ static void migrate_fill_in_channel_type(struct lightningd *ld,
|
||||||
static void migrate_normalize_invstr(struct lightningd *ld,
|
static void migrate_normalize_invstr(struct lightningd *ld,
|
||||||
struct db *db);
|
struct db *db);
|
||||||
|
|
||||||
static void migrate_initialize_wait_indexes(struct lightningd *ld,
|
static void migrate_initialize_invoice_wait_indexes(struct lightningd *ld,
|
||||||
struct db *db);
|
struct db *db);
|
||||||
|
|
||||||
static void migrate_invoice_created_index_var(struct lightningd *ld,
|
static void migrate_invoice_created_index_var(struct lightningd *ld,
|
||||||
struct db *db);
|
struct db *db);
|
||||||
|
|
||||||
|
static void migrate_initialize_payment_wait_indexes(struct lightningd *ld,
|
||||||
|
struct db *db);
|
||||||
|
|
||||||
/* Do not reorder or remove elements from this array, it is used to
|
/* Do not reorder or remove elements from this array, it is used to
|
||||||
* migrate existing databases from a previous state, based on the
|
* migrate existing databases from a previous state, based on the
|
||||||
* string indices */
|
* string indices */
|
||||||
|
@ -965,7 +968,7 @@ static struct migration dbmigrations[] = {
|
||||||
{SQL("CREATE TABLE runes (id BIGSERIAL, rune TEXT, PRIMARY KEY (id));"), NULL},
|
{SQL("CREATE TABLE runes (id BIGSERIAL, rune TEXT, PRIMARY KEY (id));"), NULL},
|
||||||
{SQL("CREATE TABLE runes_blacklist (start_index BIGINT, end_index BIGINT);"), NULL},
|
{SQL("CREATE TABLE runes_blacklist (start_index BIGINT, end_index BIGINT);"), NULL},
|
||||||
{SQL("ALTER TABLE channels ADD ignore_fee_limits INTEGER DEFAULT 0;"), NULL},
|
{SQL("ALTER TABLE channels ADD ignore_fee_limits INTEGER DEFAULT 0;"), NULL},
|
||||||
{NULL, migrate_initialize_wait_indexes},
|
{NULL, migrate_initialize_invoice_wait_indexes},
|
||||||
{SQL("ALTER TABLE invoices ADD updated_index BIGINT DEFAULT 0"), NULL},
|
{SQL("ALTER TABLE invoices ADD updated_index BIGINT DEFAULT 0"), NULL},
|
||||||
{SQL("CREATE INDEX invoice_update_idx ON invoices (updated_index)"), NULL},
|
{SQL("CREATE INDEX invoice_update_idx ON invoices (updated_index)"), NULL},
|
||||||
{NULL, migrate_datastore_commando_runes},
|
{NULL, migrate_datastore_commando_runes},
|
||||||
|
@ -996,6 +999,7 @@ static struct migration dbmigrations[] = {
|
||||||
{SQL("CREATE INDEX local_anchors_idx ON local_anchors (channel_id)"), NULL},
|
{SQL("CREATE INDEX local_anchors_idx ON local_anchors (channel_id)"), NULL},
|
||||||
{SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL},
|
{SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL},
|
||||||
{SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL},
|
{SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL},
|
||||||
|
{NULL, migrate_initialize_payment_wait_indexes},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1685,8 +1689,8 @@ static void migrate_fill_in_channel_type(struct lightningd *ld,
|
||||||
tal_free(stmt);
|
tal_free(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void migrate_initialize_wait_indexes(struct lightningd *ld,
|
static void migrate_initialize_invoice_wait_indexes(struct lightningd *ld,
|
||||||
struct db *db)
|
struct db *db)
|
||||||
{
|
{
|
||||||
struct db_stmt *stmt;
|
struct db_stmt *stmt;
|
||||||
bool res;
|
bool res;
|
||||||
|
@ -1740,6 +1744,40 @@ static void migrate_invoice_created_index_var(struct lightningd *ld, struct db *
|
||||||
tal_free(stmt);
|
tal_free(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We expect to have a few of these... */
|
||||||
|
static void migrate_initialize_wait_indexes(struct db *db,
|
||||||
|
enum wait_subsystem subsystem,
|
||||||
|
enum wait_index index,
|
||||||
|
const char *query,
|
||||||
|
const char *colname)
|
||||||
|
{
|
||||||
|
struct db_stmt *stmt;
|
||||||
|
bool res;
|
||||||
|
|
||||||
|
stmt = db_prepare_v2(db, query);
|
||||||
|
db_query_prepared(stmt);
|
||||||
|
res = db_step(stmt);
|
||||||
|
assert(res);
|
||||||
|
|
||||||
|
if (!db_col_is_null(stmt, colname))
|
||||||
|
db_set_intvar(db,
|
||||||
|
tal_fmt(tmpctx, "last_%s_%s_index",
|
||||||
|
wait_subsystem_name(subsystem),
|
||||||
|
wait_index_name(index)),
|
||||||
|
db_col_u64(stmt, colname));
|
||||||
|
tal_free(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void migrate_initialize_payment_wait_indexes(struct lightningd *ld,
|
||||||
|
struct db *db)
|
||||||
|
{
|
||||||
|
migrate_initialize_wait_indexes(db,
|
||||||
|
WAIT_SUBSYSTEM_SENDPAY,
|
||||||
|
WAIT_INDEX_CREATED,
|
||||||
|
SQL("SELECT MAX(id) FROM payments;"),
|
||||||
|
"MAX(id)");
|
||||||
|
}
|
||||||
|
|
||||||
static void complain_unfixed(struct lightningd *ld,
|
static void complain_unfixed(struct lightningd *ld,
|
||||||
enum channel_state state,
|
enum channel_state state,
|
||||||
u64 id,
|
u64 id,
|
||||||
|
|
Loading…
Reference in New Issue