Skip to content

Commit 719a10b

Browse files
rustyrussellShahanaFarooqui
authored andcommitted
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 <[email protected]>
1 parent e1e4c1a commit 719a10b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

wallet/account_migration.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ struct chain_event {
8787
bool we_opened;
8888
};
8989

90+
/* Every 10 seconds, give progress indication */
91+
static bool give_progress(struct timemono *prev)
92+
{
93+
struct timemono now = time_mono();
94+
if (time_to_sec(timemono_between(now, *prev)) >= 10) {
95+
*prev = now;
96+
return true;
97+
}
98+
return false;
99+
}
100+
90101
static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *stmt)
91102
{
92103
struct chain_event *e = tal(ctx, struct chain_event);
@@ -354,6 +365,7 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
354365
size_t descriptions_migrated = 0;
355366
struct db_stmt *stmt;
356367
int version;
368+
struct timemono prev;
357369

358370
/* Initialize wait indices: we're going to use it to generate ids. */
359371
load_indexes(db, ld->indexes);
@@ -379,6 +391,7 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
379391
}
380392

381393
/* Load events */
394+
prev = time_mono();
382395
db_begin_transaction(account_db);
383396
version = db_get_version(account_db);
384397
/* -1 means empty database (Postgres usually). */
@@ -396,6 +409,8 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
396409
db_commit_transaction(account_db);
397410
tal_free(account_db);
398411

412+
log_debug(ld->log, "Transferring %zu chain_events",
413+
tal_count(chain_events));
399414
for (size_t i = 0; i < tal_count(chain_events); i++) {
400415
const struct chain_event *ev = chain_events[i];
401416
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)
486501
wallet_datastore_save_utxo_description(db, &ev->outpoint, ev->desc);
487502
descriptions_migrated++;
488503
}
504+
if (give_progress(&prev))
505+
log_info(ld->log, "Inserted %zu/%zu chain_events", i, tal_count(chain_events));
489506
}
490507

508+
log_debug(ld->log, "Transferring %zu channel_events",
509+
tal_count(channel_events));
491510
for (size_t i = 0; i < tal_count(channel_events); i++) {
492511
const struct channel_event *ev = channel_events[i];
493512
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)
546565
wallet_datastore_save_payment_description(db, ev->payment_id, ev->desc);
547566
descriptions_migrated++;
548567
}
568+
if (give_progress(&prev))
569+
log_info(ld->log, "Inserted %zu/%zu channel_events", i, tal_count(channel_events));
549570
}
550571

551572
log_info(ld->log, "bookkeeper migration complete: migrated %zu chainmoves, %zu channelmoves, %zu descriptions",

0 commit comments

Comments
 (0)