Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Part 1|3] Introduce SQL Payment schema into LND #9147

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
## lncli Updates

## Code Health

* [Introduce](https://github.com/lightningnetwork/lnd/pull/XXXX) SQL schema for payments in LND.

## Breaking Changes
## Performance Improvements
Expand Down
125 changes: 125 additions & 0 deletions docs/sql-schemas/payments_sql_schema.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
erDiagram
payments {
BIGINT id PK
INTEGER payment_status FK
INTEGER payment_type FK
BIGINT amount_msat
BLOB payment_request
TIMESTAMP created_at
}
payment_status_types {
INTEGER id PK
TEXT description
}
payment_types {
INTEGER id PK
TEXT description
}
legacy_payments {
INTEGER payment_id PK,FK
BLOB payment_hash
}
mpp_payments {
INTEGER payment_id PK,FK
INTEGER mpp_record_id FK
}
amp_payments {
INTEGER payment_id PK,FK
INTEGER amp_record_id FK
}
payment_state {
INTEGER payment_id PK,FK
INTEGER num_attempts_in_flight
BIGINT remaining_amt
BIGINT fees_paid
BOOLEAN has_settled_htlc
BOOLEAN payment_failed
}
htlc_attempt {
INTEGER id PK
BLOB session_key
TIMESTAMP attempt_time
INTEGER payment_id FK
}
route {
INTEGER htlc_attempt_id PK,FK
INTEGER total_timeLock
BIGINT total_amount
BLOB source_key
BIGINT first_hop_amount
}
hop {
INTEGER id PK
INTEGER route_id FK
BLOB pub_key
TEXT chan_id
INTEGER outgoing_time_lock
BIGINT amt_to_forward
BLOB meta_data
}
mpp_record {
INTEGER hop_id PK,FK
BLOB payment_addr
BIGINT total_msat
}
amp_record {
INTEGER hop_id PK,FK
BLOB root_share
BLOB set_id
INTEGER child_index
}
tlv_records {
INTEGER id PK
BIGINT key
BLOB value
}
custom_records {
INTEGER tlv_record_id PK,FK
INTEGER hop_id FK
}
first_hop_custom_records {
INTEGER tlv_record_id PK,FK
INTEGER payment_id FK
}
blinded_data {
INTEGER hop_id PK,FK
BLOB encrypted_data
BLOB blinding_point
BIGINT total_amt
}
htlc_settle_info {
INTEGER htlc_attempt_id PK,FK
BLOB preimage
TIMESTAMP settle_time
}
htlc_fail_info {
INTEGER htlc_attempt_id PK,FK
INTEGER htlc_fail_reason FK
TEXT failure_msg
}
htlc_fail_reason_types {
INTEGER id PK
TEXT description
}

payments ||--o| legacy_payments : has
payments ||--o| mpp_payments : has
payments ||--o| amp_payments : has
payments ||--o| payment_state : has
payments ||--o{ first_hop_custom_records : has
payments ||--o{ htlc_attempt : has
payments }o--|| payment_status_types : has
payments }o--|| payment_types : has
htlc_attempt ||--o| route : has
route ||--o{ hop : has
hop ||--o| mpp_record : has
hop ||--o| amp_record : has
hop ||--o{ custom_records : has
hop ||--o| blinded_data : has
htlc_attempt ||--o| htlc_settle_info : has
htlc_attempt ||--o| htlc_fail_info : has
htlc_fail_info }o--|| htlc_fail_reason_types : has
mpp_record ||--|| mpp_payments : references
amp_record ||--|| amp_payments : references
tlv_records ||--o{ custom_records : has
tlv_records ||--o{ first_hop_custom_records : has
69 changes: 69 additions & 0 deletions sqldb/sqlc/migrations/000005_payments.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- Drop htlc_settle_info index and table.
DROP INDEX IF EXISTS htlc_settle_info_htlc_attempt_id_idx;
DROP TABLE IF EXISTS htlc_settle_info;

-- Drop htlc_fail_info index and table.
DROP INDEX IF EXISTS htlc_fail_info_htlc_attempt_id_idx;
DROP TABLE IF EXISTS htlc_fail_info;

-- Drop htlc_fail_reason_types index and table.
DROP INDEX IF EXISTS htlc_fail_reason_types_htlc_fail_reason_type_idx;
DROP TABLE IF EXISTS htlc_fail_reason_types;

-- Drop blinded_data index and table.
DROP INDEX IF EXISTS blinded_data_hop_id_idx;
DROP TABLE IF EXISTS blinded_data;

-- Drop mpp_record index and table.
DROP INDEX IF EXISTS mpp_record_payment_addr_idx;
DROP TABLE IF EXISTS mpp_record;

-- Drop amp_record index and table.
DROP INDEX IF EXISTS amp_record_set_id_idx;
DROP TABLE IF EXISTS amp_record;

-- Drop hop index and table.
DROP INDEX IF EXISTS hop_route_id_idx;
DROP TABLE IF EXISTS hop;

-- Drop route index and table.
DROP INDEX IF EXISTS route_htlc_attempt_id_idx;
DROP TABLE IF EXISTS route;

-- Drop htlc_attempt index and table.
DROP INDEX IF EXISTS htlc_attempt_payment_id_idx;
DROP TABLE IF EXISTS htlc_attempt;

-- Drop first_hop_custom_records index and table.
DROP INDEX IF EXISTS first_hop_custom_records_payment_id_idx;
DROP TABLE IF EXISTS first_hop_custom_records;

-- Drop mpp_state index and table.
DROP INDEX IF EXISTS mpp_state_payment_id_idx;
DROP TABLE IF EXISTS mpp_state;

-- Drop mpp_payments index and table.
DROP INDEX IF EXISTS mpp_payments_payment_id_idx;
DROP TABLE IF EXISTS mpp_payments;

-- Drop amp_payments index and table.
DROP INDEX IF EXISTS amp_payments_payment_id_idx;
DROP TABLE IF EXISTS amp_payments;

-- Drop legacy_payments index and table.
DROP INDEX IF EXISTS legacy_payments_payment_hash_idx;
DROP TABLE IF EXISTS legacy_payments;

-- Drop payment_types index and table.
DROP INDEX IF EXISTS payment_types_name_idx;
DROP TABLE IF EXISTS payment_types;

-- Drop payment_status_types index and table.
DROP INDEX IF EXISTS payment_status_types_name_idx;
DROP TABLE IF EXISTS payment_status_types;

-- Drop payments index and table.
DROP INDEX IF EXISTS payments_payment_status_idx;
DROP INDEX IF EXISTS payments_payment_type_idx;
DROP INDEX IF EXISTS payments_created_at_idx;
DROP TABLE IF EXISTS payments;
Loading
Loading