Skip to content

Commit 4e2750e

Browse files
committed
sqldb: channel policy tables
Define the SQL tables for representing channel policies. Namely: - channel_policies - channel_policy_extra_types
1 parent 425b057 commit 4e2750e

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ circuit. The indices are only available for forwarding events saved after v0.20.
5858
cache population.
5959
* Add graph schemas, queries and CRUD:
6060
* [1](https://github.com/lightningnetwork/lnd/pull/9866)
61+
* [2](https://github.com/lightningnetwork/lnd/pull/9869)
62+
* [3](https://github.com/lightningnetwork/lnd/pull/9887)
6163

6264
## RPC Updates
6365

sqldb/sqlc/migrations/000007_graph.down.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ DROP INDEX IF EXISTS channels_unique;
1010
DROP INDEX IF EXISTS channels_version_outpoint_idx;
1111
DROP INDEX IF EXISTS channel_features_unique;
1212
DROP INDEX IF EXISTS channel_extra_types_unique;
13+
DROP INDEX IF EXISTS channel_policies_unique;
14+
DROP INDEX IF EXISTS channel_policy_extra_types_unique;
1315

1416
-- Drop tables in order of reverse dependencies.
17+
DROP TABLE IF EXISTS channel_policy_extra_types;
18+
DROP TABLE IF EXISTS channel_policies;
1519
DROP TABLE IF EXISTS channel_features;
1620
DROP TABLE IF EXISTS channel_extra_types;
1721
DROP TABLE IF EXISTS channels;

sqldb/sqlc/migrations/000007_graph.up.sql

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,85 @@ CREATE TABLE IF NOT EXISTS channel_extra_types (
208208
CREATE 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+
);

sqldb/sqlc/models.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)