@@ -86,6 +86,8 @@ static void migrate_initialize_alias_local(struct lightningd *ld,
86
86
struct db * db );
87
87
static void insert_addrtype_to_addresses (struct lightningd * ld ,
88
88
struct db * db );
89
+ static void migrate_convert_old_channel_keyidx (struct lightningd * ld ,
90
+ struct db * db );
89
91
90
92
/* Do not reorder or remove elements from this array, it is used to
91
93
* migrate existing databases from a previous state, based on the
@@ -1030,6 +1032,7 @@ static struct migration dbmigrations[] = {
1030
1032
{SQL ("ALTER TABLE channel_funding_inflights ADD remote_funding BLOB DEFAULT NULL;" ), NULL },
1031
1033
{SQL ("ALTER TABLE peers ADD last_known_address BLOB DEFAULT NULL;" ), NULL },
1032
1034
{SQL ("ALTER TABLE channels ADD close_attempt_height INTEGER DEFAULT 0;" ), NULL },
1035
+ {NULL , migrate_convert_old_channel_keyidx },
1033
1036
};
1034
1037
1035
1038
/**
@@ -2025,3 +2028,28 @@ static void insert_addrtype_to_addresses(struct lightningd *ld,
2025
2028
tal_free (stmt );
2026
2029
}
2027
2030
}
2031
+
2032
+ /* If we said a channel final key was taproot-only, but actually the peer
2033
+ * didn't support `option_shutdown_anysegwit`, we used the p2wpkh instead. We
2034
+ * don't have access to the peers' features in the db, so instead convert all
2035
+ * the keys to ADDR_ALL. Users with closed channels may still need to
2036
+ * rescan! */
2037
+ static void migrate_convert_old_channel_keyidx (struct lightningd * ld ,
2038
+ struct db * db )
2039
+ {
2040
+ struct db_stmt * stmt ;
2041
+
2042
+ stmt = db_prepare_v2 (db , SQL ("UPDATE addresses"
2043
+ " SET addrtype = ?"
2044
+ " FROM channels "
2045
+ " WHERE addresses.keyidx = channels.shutdown_keyidx_local"
2046
+ " AND channels.state != ?"
2047
+ " AND channels.state != ?"
2048
+ " AND channels.state != ?" ));
2049
+ db_bind_int (stmt , wallet_addrtype_in_db (ADDR_ALL ));
2050
+ /* If we might have already seen onchain funds, we need to rescan */
2051
+ db_bind_int (stmt , channel_state_in_db (FUNDING_SPEND_SEEN ));
2052
+ db_bind_int (stmt , channel_state_in_db (ONCHAIN ));
2053
+ db_bind_int (stmt , channel_state_in_db (CLOSED ));
2054
+ db_exec_prepared_v2 (take (stmt ));
2055
+ }
0 commit comments