You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Require closed channels migration before starting (#3198)
We require closed channels to be migrated to the closed channels table
introduced in #3170 before starting `eclair`. This ensures that we
will not lose channel data when removing support for non-anchor channels
in the next release.
Node operators will have to:
- run the v0.13.0 release to migrate their channel data to v5
- run the v0.13.1 release to migrate their closed channels
Afterwards, they'll be able to update to the (future) v0.14.x release
once all of their pre-anchor channels have been closed.
caseSome(v) if v < minimum =>thrownewIllegalArgumentException("You are updating from a version of eclair older than v0.13.0: please update to the v0.13.0 release first to migrate your channel data, and afterwards you'll be able to update to the latest version.")
107
+
caseSome(v) if v < eclair130 =>thrownewIllegalArgumentException("You are updating from a version of eclair older than v0.13.0: please update to the v0.13.0 release first to migrate your channel data, then to the v0.13.1 release to migrate your closed channels, and afterwards you'll be able to update to the latest version.")
108
+
caseSome(v) if v < eclair131 =>thrownewIllegalArgumentException("You are updating from a version of eclair older than v0.13.1: please update to the v0.13.1 release first to migrate your closed channels, and afterwards you'll be able to update to the latest version.")
* Before version 12, closed channels were directly kept in the local_channels table with an is_closed flag set to true.
54
-
* We move them to a dedicated table, where we keep minimal channel information.
55
-
*/
56
-
defmigration1112(statement: Statement):Unit= {
57
-
// We start by dropping for foreign key constraint on htlc_infos, otherwise we won't be able to move recently
58
-
// closed channels to a different table.
59
-
statement.executeQuery("SELECT conname FROM pg_catalog.pg_constraint WHERE contype = 'f'").map(rs => rs.getString("conname")).headOption match {
60
-
caseSome(foreignKeyConstraint) => statement.executeUpdate(s"ALTER TABLE local.htlc_infos DROP CONSTRAINT $foreignKeyConstraint")
61
-
caseNone=> logger.warn("couldn't find foreign key constraint for htlc_infos table: DB migration may fail")
62
-
}
63
-
// We can now move closed channels to a dedicated table.
64
-
statement.executeUpdate("CREATE TABLE local.channels_closed (channel_id TEXT NOT NULL PRIMARY KEY, remote_node_id TEXT NOT NULL, funding_txid TEXT NOT NULL, funding_output_index BIGINT NOT NULL, funding_tx_index BIGINT NOT NULL, funding_key_path TEXT NOT NULL, channel_features TEXT NOT NULL, is_channel_opener BOOLEAN NOT NULL, commitment_format TEXT NOT NULL, announced BOOLEAN NOT NULL, capacity_satoshis BIGINT NOT NULL, closing_txid TEXT NOT NULL, closing_type TEXT NOT NULL, closing_script TEXT NOT NULL, local_balance_msat BIGINT NOT NULL, remote_balance_msat BIGINT NOT NULL, closing_amount_satoshis BIGINT NOT NULL, created_at TIMESTAMP WITH TIME ZONE NOT NULL, closed_at TIMESTAMP WITH TIME ZONE NOT NULL)")
65
-
statement.executeUpdate("CREATE INDEX channels_closed_remote_node_id_idx ON local.channels_closed(remote_node_id)")
66
-
// We migrate closed channels from the local_channels table to the new channels_closed table, whenever possible.
statement.executeUpdate("CREATE INDEX htlc_infos_channel_id_idx ON local.htlc_infos(channel_id)")
148
66
statement.executeUpdate("CREATE INDEX htlc_infos_commitment_number_idx ON local.htlc_infos(commitment_number)")
149
67
statement.executeUpdate("CREATE INDEX channels_closed_remote_node_id_idx ON local.channels_closed(remote_node_id)")
150
-
caseSome(v) if v <11=>thrownewRuntimeException("You are updating from a version of eclair older than v0.13.0: please update to the v0.13.0 release first to migrate your channel data, and afterwards you'll be able to update to the latest version.")
151
-
caseSome(v@11) =>
152
-
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
153
-
if (v <12) migration1112(statement)
154
68
caseSome(CURRENT_VERSION) => () // table is up-to-date, nothing to do
155
69
caseSome(unknownVersion) =>thrownewRuntimeException(s"Unknown version of DB $DB_NAME found, version=$unknownVersion")
@@ -50,90 +49,6 @@ class SqliteChannelsDb(val sqlite: Connection) extends ChannelsDb with Logging {
50
49
statement.execute("PRAGMA foreign_keys = ON")
51
50
}
52
51
53
-
/**
54
-
* Before version 8, closed channels were directly kept in the local_channels table with an is_closed flag set to true.
55
-
* We move them to a dedicated table, where we keep minimal channel information.
56
-
*/
57
-
defmigration78(statement: Statement):Unit= {
58
-
// We start by dropping for foreign key constraint on htlc_infos, otherwise we won't be able to move recently
59
-
// closed channels to a different table. The only option for that in sqlite is to re-create the table.
60
-
statement.executeUpdate("ALTER TABLE htlc_infos RENAME TO htlc_infos_old")
61
-
statement.executeUpdate("CREATE TABLE htlc_infos (channel_id BLOB NOT NULL, commitment_number INTEGER NOT NULL, payment_hash BLOB NOT NULL, cltv_expiry INTEGER NOT NULL)")
62
-
statement.executeUpdate("INSERT INTO htlc_infos(channel_id, commitment_number, payment_hash, cltv_expiry) SELECT channel_id, commitment_number, payment_hash, cltv_expiry FROM htlc_infos_old")
statement.executeUpdate("CREATE INDEX htlc_infos_channel_id_idx ON htlc_infos(channel_id)")
65
-
statement.executeUpdate("CREATE INDEX htlc_infos_commitment_number_idx ON htlc_infos(commitment_number)")
66
-
// We can now move closed channels to a dedicated table.
67
-
statement.executeUpdate("CREATE TABLE local_channels_closed (channel_id TEXT NOT NULL PRIMARY KEY, remote_node_id TEXT NOT NULL, funding_txid TEXT NOT NULL, funding_output_index INTEGER NOT NULL, funding_tx_index INTEGER NOT NULL, funding_key_path TEXT NOT NULL, channel_features TEXT NOT NULL, is_channel_opener BOOLEAN NOT NULL, commitment_format TEXT NOT NULL, announced BOOLEAN NOT NULL, capacity_satoshis INTEGER NOT NULL, closing_txid TEXT NOT NULL, closing_type TEXT NOT NULL, closing_script TEXT NOT NULL, local_balance_msat INTEGER NOT NULL, remote_balance_msat INTEGER NOT NULL, closing_amount_satoshis INTEGER NOT NULL, created_at INTEGER NOT NULL, closed_at INTEGER NOT NULL)")
68
-
statement.executeUpdate("CREATE INDEX local_channels_closed_remote_node_id_idx ON local_channels_closed(remote_node_id)")
69
-
// We migrate closed channels from the local_channels table to the new local_channels_closed table, whenever possible.
@@ -146,10 +61,6 @@ class SqliteChannelsDb(val sqlite: Connection) extends ChannelsDb with Logging {
146
61
statement.executeUpdate("CREATE INDEX htlc_infos_channel_id_idx ON htlc_infos(channel_id)")
147
62
statement.executeUpdate("CREATE INDEX htlc_infos_commitment_number_idx ON htlc_infos(commitment_number)")
148
63
statement.executeUpdate("CREATE INDEX local_channels_closed_remote_node_id_idx ON local_channels_closed(remote_node_id)")
149
-
caseSome(v) if v <7=>thrownewRuntimeException("You are updating from a version of eclair older than v0.13.0: please update to the v0.13.0 release first to migrate your channel data, and afterwards you'll be able to update to the latest version.")
150
-
caseSome(v@7) =>
151
-
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
152
-
if (v <8) migration78(statement)
153
64
caseSome(CURRENT_VERSION) => () // table is up-to-date, nothing to do
154
65
caseSome(unknownVersion) =>thrownewRuntimeException(s"Unknown version of DB $DB_NAME found, version=$unknownVersion")
0 commit comments