-
Notifications
You must be signed in to change notification settings - Fork 135
staticaddr: persist multi-address ownership foundation #1210
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
Open
hieblmi
wants to merge
3
commits into
lightninglabs:master
Choose a base branch
from
hieblmi:codex/multi-address-foundation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
loopdb/sqlc/migrations/000022_deposit_static_address_id.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE deposits DROP COLUMN static_address_id; |
8 changes: 8 additions & 0 deletions
8
loopdb/sqlc/migrations/000022_deposit_static_address_id.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ALTER TABLE deposits ADD static_address_id INT REFERENCES static_addresses(id); | ||
|
|
||
| UPDATE deposits | ||
| SET static_address_id = ( | ||
| SELECT id FROM static_addresses ORDER BY id ASC LIMIT 1 | ||
| ) | ||
| WHERE static_address_id IS NULL | ||
| AND EXISTS (SELECT 1 FROM static_addresses); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠
F1(Major) — Backfill assigns every old deposit to one address ·loopdb/sqlc/migrations/000022_deposit_static_address_id.up.sql:5The migration assigns every pre-existing deposit to the lowest-id row in
static_addresses. If a client ever created more than one static address before this migration runs, deposits belonging to the second address are permanently recorded as owned by the first, and every subsequent read hands spending code the wrong client/server pubkeys and expiry through the newAddressParams.Why this matters
The subselect
SELECT id FROM static_addresses ORDER BY id ASC LIMIT 1has no way to tell which address produced a given deposit —depositsstores onlytimeout_sweep_pk_script, not the address pkScript — and theEXISTSguard only checks that at least one address row exists, not that exactly one does. The mis-assignment is also unrecoverable through the repair path this PR adds:SetAllNullDepositsStaticAddressID(loopdb/sqlc/queries/static_address_deposits.sql) andBatchSetStaticAddressID(staticaddr/deposit/sql_store.go) both filter onstatic_address_id IS NULL, so a row that was wrongly filled is never revisited. Gating the backfill on(SELECT COUNT(*) FROM static_addresses) = 1and leaving the column NULL otherwise keeps the ambiguous case in the hands of application code, which can derive scripts and match them against each deposit. I cannot tell from the loaded context whether the client can currently create more than one static address; if it provably cannot, this reduces to a hardening request.