wallet: print progress reports for large account migration.
Show the work we're doing (at debug level) and every 10 seconds print progress (at INFO level):x ``` lightningd-1 2025-10-08T05:13:07.973Z INFO lightningd: Creating database lightningd-1 2025-10-08T05:13:10.987Z DEBUG lightningd: Transferring 6166 chain_events lightningd-1 2025-10-08T05:13:11.780Z DEBUG lightningd: Transferring 1660043 channel_events ``` It's the inserting channel_events which takes a long time, slowing down exponentially: ``` lightningd-1 2025-10-08T05:13:18.034Z INFO lightningd: Inserted 26690/1660043 channel_events lightningd-1 2025-10-08T05:13:28.034Z INFO lightningd: Inserted 47086/1660043 channel_events lightningd-1 2025-10-08T05:13:38.035Z INFO lightningd: Inserted 61699/1660043 channel_events lightningd-1 2025-10-08T05:13:48.035Z INFO lightningd: Inserted 73743/1660043 channel_events lightningd-1 2025-10-08T05:13:58.035Z INFO lightningd: Inserted 83244/1660043 channel_events ... lightningd-1 2025-10-08T05:35:18.286Z INFO lightningd: Inserted 466720/1660043 channel_events lightningd-1 2025-10-08T05:35:29.074Z INFO lightningd: Inserted 468437/1660043 channel_events lightningd-1 2025-10-08T05:35:39.079Z INFO lightningd: Inserted 470130/1660043 channel_events lightningd-1 2025-10-08T05:35:49.081Z INFO lightningd: Inserted 471871/1660043 channel_events ``` Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -87,6 +87,17 @@ struct chain_event {
|
||||
bool we_opened;
|
||||
};
|
||||
|
||||
/* Every 10 seconds, give progress indication */
|
||||
static bool give_progress(struct timemono *prev)
|
||||
{
|
||||
struct timemono now = time_mono();
|
||||
if (time_to_sec(timemono_between(now, *prev)) >= 10) {
|
||||
*prev = now;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *stmt)
|
||||
{
|
||||
struct chain_event *e = tal(ctx, struct chain_event);
|
||||
@@ -354,6 +365,7 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
|
||||
size_t descriptions_migrated = 0;
|
||||
struct db_stmt *stmt;
|
||||
int version;
|
||||
struct timemono prev;
|
||||
|
||||
/* Initialize wait indices: we're going to use it to generate ids. */
|
||||
load_indexes(db, ld->indexes);
|
||||
@@ -379,6 +391,7 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
|
||||
}
|
||||
|
||||
/* Load events */
|
||||
prev = time_mono();
|
||||
db_begin_transaction(account_db);
|
||||
version = db_get_version(account_db);
|
||||
/* -1 means empty database (Postgres usually). */
|
||||
@@ -396,6 +409,8 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
|
||||
db_commit_transaction(account_db);
|
||||
tal_free(account_db);
|
||||
|
||||
log_debug(ld->log, "Transferring %zu chain_events",
|
||||
tal_count(chain_events));
|
||||
for (size_t i = 0; i < tal_count(chain_events); i++) {
|
||||
const struct chain_event *ev = chain_events[i];
|
||||
struct mvt_account_id *account = tal(ev, struct mvt_account_id);
|
||||
@@ -486,8 +501,12 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
|
||||
wallet_datastore_save_utxo_description(db, &ev->outpoint, ev->desc);
|
||||
descriptions_migrated++;
|
||||
}
|
||||
if (give_progress(&prev))
|
||||
log_info(ld->log, "Inserted %zu/%zu chain_events", i, tal_count(chain_events));
|
||||
}
|
||||
|
||||
log_debug(ld->log, "Transferring %zu channel_events",
|
||||
tal_count(channel_events));
|
||||
for (size_t i = 0; i < tal_count(channel_events); i++) {
|
||||
const struct channel_event *ev = channel_events[i];
|
||||
struct mvt_account_id *account = tal(ev, struct mvt_account_id);
|
||||
@@ -546,6 +565,8 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
|
||||
wallet_datastore_save_payment_description(db, ev->payment_id, ev->desc);
|
||||
descriptions_migrated++;
|
||||
}
|
||||
if (give_progress(&prev))
|
||||
log_info(ld->log, "Inserted %zu/%zu channel_events", i, tal_count(channel_events));
|
||||
}
|
||||
|
||||
log_info(ld->log, "bookkeeper migration complete: migrated %zu chainmoves, %zu channelmoves, %zu descriptions",
|
||||
|
||||
Reference in New Issue
Block a user