1414#include <lightningd/log.h>
1515#include <lightningd/plugin_hook.h>
1616#include <wallet/db_common.h>
17+ #include <wally_bip32.h>
1718
1819#define NSEC_IN_SEC 1000000000
1920
2021struct migration {
2122 const char * sql ;
22- void (* func )(struct lightningd * ld , struct db * db );
23+ void (* func )(struct lightningd * ld , struct db * db ,
24+ const struct ext_key * bip32_base );
2325};
2426
25- static void migrate_pr2342_feerate_per_channel (struct lightningd * ld , struct db * db );
27+ static void migrate_pr2342_feerate_per_channel (struct lightningd * ld , struct db * db ,
28+ const struct ext_key * bip32_base );
29+
30+ static void migrate_our_funding (struct lightningd * ld , struct db * db ,
31+ const struct ext_key * bip32_base );
32+
33+ static void migrate_last_tx_to_psbt (struct lightningd * ld , struct db * db ,
34+ const struct ext_key * bip32_base );
2635
27- static void migrate_our_funding (struct lightningd * ld , struct db * db );
2836
2937/* Do not reorder or remove elements from this array, it is used to
3038 * migrate existing databases from a previous state, based on the
@@ -970,7 +978,8 @@ static int db_get_version(struct db *db)
970978/**
971979 * db_migrate - Apply all remaining migrations from the current version
972980 */
973- static void db_migrate (struct lightningd * ld , struct db * db )
981+ static void db_migrate (struct lightningd * ld , struct db * db ,
982+ const struct ext_key * bip32_base )
974983{
975984 /* Attempt to read the version from the database */
976985 int current , orig , available ;
@@ -997,7 +1006,7 @@ static void db_migrate(struct lightningd *ld, struct db *db)
9971006 tal_free (stmt );
9981007 }
9991008 if (dbmigrations [current ].func )
1000- dbmigrations [current ].func (ld , db );
1009+ dbmigrations [current ].func (ld , db , bip32_base );
10011010 }
10021011
10031012 /* Finally update the version number in the version table */
@@ -1029,14 +1038,15 @@ u32 db_data_version_get(struct db *db)
10291038 return version ;
10301039}
10311040
1032- struct db * db_setup (const tal_t * ctx , struct lightningd * ld )
1041+ struct db * db_setup (const tal_t * ctx , struct lightningd * ld ,
1042+ const struct ext_key * bip32_base )
10331043{
10341044 struct db * db = db_open (ctx , ld -> wallet_dsn );
10351045 db -> log = new_log (db , ld -> log_book , NULL , "database" );
10361046
10371047 db_begin_transaction (db );
10381048
1039- db_migrate (ld , db );
1049+ db_migrate (ld , db , bip32_base );
10401050
10411051 db -> data_version = db_data_version_get (db );
10421052 db_commit_transaction (db );
@@ -1082,7 +1092,8 @@ void db_set_intvar(struct db *db, char *varname, s64 val)
10821092}
10831093
10841094/* Will apply the current config fee settings to all channels */
1085- static void migrate_pr2342_feerate_per_channel (struct lightningd * ld , struct db * db )
1095+ static void migrate_pr2342_feerate_per_channel (struct lightningd * ld , struct db * db ,
1096+ const struct ext_key * bip32_base )
10861097{
10871098 struct db_stmt * stmt = db_prepare_v2 (
10881099 db , SQL ("UPDATE channels SET feerate_base = ?, feerate_ppm = ?;" ));
@@ -1100,7 +1111,8 @@ static void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db
11001111 * is the same as the funding_satoshi for every channel where we are
11011112 * the `funder`
11021113 */
1103- static void migrate_our_funding (struct lightningd * ld , struct db * db )
1114+ static void migrate_our_funding (struct lightningd * ld , struct db * db ,
1115+ const struct ext_key * bip32_base )
11041116{
11051117 struct db_stmt * stmt ;
11061118
@@ -1121,7 +1133,8 @@ static void migrate_our_funding(struct lightningd *ld, struct db *db)
11211133 * This migration loads all of the last_tx's and 're-formats' them into psbts,
11221134 * adds the required input witness utxo information, and then saves it back to disk
11231135 * */
1124- void migrate_last_tx_to_psbt (struct lightningd * ld , struct db * db )
1136+ void migrate_last_tx_to_psbt (struct lightningd * ld , struct db * db ,
1137+ const struct ext_key * bip32_base )
11251138{
11261139 struct db_stmt * stmt , * update_stmt ;
11271140
0 commit comments