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
A json column has been added to the few tables that contains an
opaque serialized blob:
- `local_channels.data`
- `nodes.data`
- `channels.channel_announcement`, `channels.channel_update_x`
We can now access all the individual data fields from SQL.
For the serialization, we use the same serializers than the one
that were previously used by the API. They have been moved to the
`eclair-core` module and simplified a bit.
There are two json data types in Postgres: `JSON` and `JSONB`. We use
the latter one, which is more recent, and allows indexing.
An alternative to this PR would have been to use columns, but:
- there would have been a *lot* of columns for the channel data
- every modification of our types would have required a db migration
NB: to handle non-backwards compatible changes in the json serializersi,
all the json columns can be recomputed on restart by setting
`eclair.db.reset-json-columns=true`.
Change in in ChannelCodecsSpec:
The goal of this test is to make sure that, in addition to successfully
decoding data that encoded with an older codec, we actually read the
correct data. Just because there is no error doesn't mean that we
interpreted the data properly. For example we could invert a
`payment_hash` and a `payment_preimage`.
We can't compare object to object, because the current version of the
class has probably changed too. That's why we compare using the json
representation of the data, that we amend to ignore new or modified
fields.
After doing a manual comparison, I updated the test to use the current
json serializers, and replaced the test data with the latest json
serialization. This allows us to remove all the tweaks that we added
over time to take into account new and updated fields.
statement.executeUpdate("ALTER TABLE local_channels ALTER COLUMN json SET NOT NULL")
71
+
statement.executeUpdate("CREATE INDEX local_channels_type_idx ON local_channels ((json->>'type'))")
72
+
statement.executeUpdate("CREATE INDEX local_channels_remote_node_id_idx ON local_channels ((json->'commitments'->'remoteParams'->>'nodeId'))")
73
+
}
74
+
65
75
getVersion(statement, DB_NAME) match {
66
76
caseNone=>
67
-
statement.executeUpdate("CREATE TABLE local_channels (channel_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL, is_closed BOOLEAN NOT NULL DEFAULT FALSE, created_timestamp TIMESTAMP WITH TIME ZONE, last_payment_sent_timestamp TIMESTAMP WITH TIME ZONE, last_payment_received_timestamp TIMESTAMP WITH TIME ZONE, last_connected_timestamp TIMESTAMP WITH TIME ZONE, closed_timestamp TIMESTAMP WITH TIME ZONE)")
77
+
statement.executeUpdate("CREATE TABLE local_channels (channel_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL, json JSONB NOT NULL, is_closed BOOLEAN NOT NULL DEFAULT FALSE, created_timestamp TIMESTAMP WITH TIME ZONE, last_payment_sent_timestamp TIMESTAMP WITH TIME ZONE, last_payment_received_timestamp TIMESTAMP WITH TIME ZONE, last_connected_timestamp TIMESTAMP WITH TIME ZONE, closed_timestamp TIMESTAMP WITH TIME ZONE)")
68
78
statement.executeUpdate("CREATE TABLE htlc_infos (channel_id TEXT NOT NULL, commitment_number BIGINT NOT NULL, payment_hash TEXT NOT NULL, cltv_expiry BIGINT NOT NULL, FOREIGN KEY(channel_id) REFERENCES local_channels(channel_id))")
79
+
80
+
statement.executeUpdate("CREATE INDEX local_channels_type_idx ON local_channels ((json->>'type'))")
81
+
statement.executeUpdate("CREATE INDEX local_channels_remote_node_id_idx ON local_channels ((json->'commitments'->'remoteParams'->>'nodeId'))")
69
82
statement.executeUpdate("CREATE INDEX htlc_infos_idx ON htlc_infos(channel_id, commitment_number)")
70
83
caseSome(v@2) =>
71
84
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
72
85
migration23(statement)
73
86
migration34(statement)
87
+
migration45(statement)
74
88
caseSome(v@3) =>
75
89
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
76
90
migration34(statement)
91
+
migration45(statement)
92
+
caseSome(v@4) =>
93
+
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
94
+
migration45(statement)
77
95
caseSome(CURRENT_VERSION) => () // table is up-to-date, nothing to do
78
96
caseSome(unknownVersion) =>thrownewRuntimeException(s"Unknown version of DB $DB_NAME found, version=$unknownVersion")
79
97
}
80
98
setVersion(statement, DB_NAME, CURRENT_VERSION)
81
99
}
82
100
}
83
101
102
+
/** Sometimes we may want to do a full reset when we update the json format */
0 commit comments