@@ -208,3 +208,85 @@ CREATE TABLE IF NOT EXISTS channel_extra_types (
208208CREATE UNIQUE INDEX IF NOT EXISTS channel_extra_types_unique ON channel_extra_types (
209209 type, channel_id
210210);
211+
212+ /* ─────────────────────────────────────────────
213+ channel policy data tables
214+ ─────────────────────────────────────────────
215+ */
216+
217+ CREATE TABLE IF NOT EXISTS channel_policies (
218+ -- The db ID of the channel policy.
219+ id INTEGER PRIMARY KEY ,
220+
221+ -- The protocol version that this update was gossiped on.
222+ version SMALLINT NOT NULL ,
223+
224+ -- The DB ID of the channel that this policy is referencing.
225+ channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE ,
226+
227+ -- The DB ID of the node that created the policy update.
228+ node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE ,
229+
230+ -- The number of blocks that the node will subtrace from the expiry
231+ -- of an incoming HTLC.
232+ timelock INTEGER NOT NULL ,
233+
234+ -- The fee rate in parts per million (ppm) that the node will charge
235+ -- HTLCs for each millionth of a satoshi forwarded.
236+ fee_ppm BIGINT NOT NULL ,
237+
238+ -- The base fee in millisatoshis that the node will charge for forwarding
239+ -- any HTLC.
240+ base_fee_msat BIGINT NOT NULL ,
241+
242+ -- The smallest value HTLC this node will forward.
243+ min_htlc_msat BIGINT NOT NULL ,
244+
245+ -- The largest value HTLC this node will forward. NOTE: this is nullable
246+ -- since the field was added later on for the v1 channel update message and
247+ -- so is not necessarily present in all channel updates.
248+ max_htlc_msat BIGINT ,
249+
250+ -- The unix timestamp of the last time the policy was updated.
251+ -- NOTE: this is nullable since in later versions, block-height will likely
252+ -- be used instead.
253+ last_update BIGINT ,
254+
255+ -- A boolean indicating that forwards are disabled for this channel.
256+ -- NOTE: this is nullable since for later protocol versions, this might be
257+ -- split up into more fine-grained flags.
258+ disabled bool,
259+
260+ -- The optional base fee in milli-satoshis that the node will charge
261+ -- for incoming HTLCs.
262+ inbound_base_fee_msat BIGINT ,
263+
264+ -- The optional fee rate in parts per million (ppm) that the node will
265+ -- charge for incoming HTLCs.
266+ inbound_fee_rate_milli_msat BIGINT ,
267+
268+ -- The signature of the channel update announcement.
269+ signature BLOB
270+ );
271+ -- A node can only have a single live policy update for a channel on a
272+ -- given protocol at any given time.
273+ CREATE UNIQUE INDEX IF NOT EXISTS channel_policies_unique ON channel_policies (
274+ channel_id, node_id, version
275+ );
276+
277+ -- channel_policy_extra_types stores any extra TLV fields covered by a channel
278+ -- update that we do not have an explicit column for in the channel_policies
279+ -- table.
280+ CREATE TABLE IF NOT EXISTS channel_policy_extra_types (
281+ -- The channel_policy id this TLV field belongs to.
282+ channel_policy_id BIGINT NOT NULL REFERENCES channel_policies(id) ON DELETE CASCADE ,
283+
284+ -- The Type field.
285+ type BIGINT NOT NULL ,
286+
287+ -- The value field.
288+ value BLOB
289+ );
290+ CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_policy_extra_types (
291+ type, channel_policy_id
292+ );
0 commit comments