Skip to content
Open
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
6 changes: 2 additions & 4 deletions internal/lspapi/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ func (s *SQLStore) pingAndMigrate(ctx context.Context) error {
CREATE TABLE IF NOT EXISTS async_hash_pool (
id INTEGER PRIMARY KEY AUTOINCREMENT,
order_id INTEGER NOT NULL REFERENCES async_orders(order_id) ON DELETE CASCADE,
hash_index INTEGER NOT NULL,
payment_hash TEXT NOT NULL,
hash_index INTEGER NOT NULL UNIQUE,
payment_hash TEXT NOT NULL UNIQUE,
status TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(order_id, hash_index),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bogdanserdinov,

Double-checking this: hash_index is only unique within an order, so enforcing UNIQUE(hash_index) is too strong. It makes values like 1 usable only once across the whole system, which will break the next peer/order that starts its pool at 1.

payment_hash can be globally unique as the intended invariant. Please make sure it's enforced where it's looked up and acted on, not only in async_hash_pool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

UNIQUE(order_id, payment_hash)
);
CREATE TABLE IF NOT EXISTS async_rotating_invoices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down
Loading