Skip to content

wallet/sql: preserve legacy wallet schema#1285

Closed
Roasbeef wants to merge 4 commits into
masterfrom
codex/sql-port-stage1-wallet-schema
Closed

wallet/sql: preserve legacy wallet schema#1285
Roasbeef wants to merge 4 commits into
masterfrom
codex/sql-port-stage1-wallet-schema

Conversation

@Roasbeef

@Roasbeef Roasbeef commented Jul 11, 2026

Copy link
Copy Markdown
Member

In this PR, we add the port-first wallet, scope, account, and address schema for SQLite and PostgreSQL.

This PR is stacked on #1284, which adds the database connection and migration foundation.

The schema preserves the current dual-passphrase encryption hierarchy and encrypted public material instead of taking the single-passphrase key-vault redesign. It also preserves watch-only nullability, the explicit per-scope last-account counter, the manager creation time, uint32 account identity, SHA256 address identifiers, and all five legacy address row shapes.

Address usage remains a sticky persisted bit. We do not derive it from surviving UTXOs, since the KV wallet can mark an address used after the relevant transaction history is no longer available. This keeps LastUnusedAddress and gap-limit behavior stable across a later migration.

No wallet API, signer interface, PSBT flow, or runtime control path changes here.

Verification:

  • SQLite and PostgreSQL migration round trips
  • legacy watch-only, scope, account, address, and ciphertext shape tests
  • generated sqlc code reproduced cleanly
  • full package tests, excluding the environment-dependent local bitcoind startup failure

GustavoStingelin and others added 4 commits July 10, 2026 16:47
In this commit, we add sqlc to the repository tool image and wire deterministic generation into the Makefile and CI. This gives each schema PR a mechanical check that the generated Go query surface matches the SQL checked into the tree.

Extracted-from: e0666e0
Extracted-from: b6fbbb6
Extracted-from: 66cc4be
Extracted-from: bd468f6
In this commit, we add the first SQLite + PostgreSQL schema slice for the port-first wallet. The block table uses the chain height as its natural key, keeps the backend-specific byte types explicit, and generates the same query surface for both backends.

This lands only SQL assets and generated accessors. It does not route the wallet through a new store or change any public wallet API.

Extracted-from: f6e0258
Extracted-from: 3d67ecd
Extracted-from: e773de5
Extracted-from: 69e459b
Extracted-from: 594bb0d

Co-authored-by: Gustavo Stingelin <gustavo.stingelin@outlook.com>
Co-authored-by: yyforyongyu <yong2452@gmail.com>
In this commit, we add bounded SQLite and PostgreSQL connection pools and an embedded migration runner that can move the schema from empty to head, back to empty, then forward again.

We use the released lnd/sqldb v1.0.13 module for shared SQLite defaults and make its transaction, error, and query utilities available to the later store adapter. The wallet schema and rollback-capable migration runner stay local because the concrete lnd stores own lnd-specific schema and migration ordering.

Extracted-from: de762f0
Extracted-from: 2477f80
Extracted-from: 12bedf6
Extracted-from: 9bf5e56
Extracted-from: aa1725a8755db62a8746e46ee8894ab5df3d828a
Extracted-from: d7a5127cc08edb68455f1e7ece45564df3fee487
Extracted-from: 7074419bfe3f7dcd393e302d6201177d3e35df49
Extracted-from: 2be43f4108cc143abb83dd8e35f8e5d4d0667fa3

Co-authored-by: Viktor Torstensson <viktor.t.git@gmail.com>
Co-authored-by: yyforyongyu <yong2452@gmail.com>
In this commit, we add the wallet, scope, account, and address schema shared by the SQLite and PostgreSQL backends.

The schema keeps the current dual-passphrase encryption hierarchy, watch-only nullability, encrypted public material, scope account counters, and SHA256 address identifiers. It also persists the sticky used bit directly, so the SQL port does not change gap-limit behavior or require the key-vault rewrite.

Extracted-from: bbfe24b
Extracted-from: b6b6a7e
Extracted-from: 9a313ea
Extracted-from: bb5a67b
Extracted-from: c5d82b2
Extracted-from: 5a639d4
Extracted-from: 99e40ab
Extracted-from: 132ba5b
Extracted-from: 47b750b
Extracted-from: 69e459b

Co-authored-by: yyforyongyu <yong2452@gmail.com>
@Roasbeef
Roasbeef marked this pull request as ready for review July 11, 2026 00:28
@Roasbeef Roasbeef closed this Jul 11, 2026
@Roasbeef Roasbeef reopened this Jul 11, 2026
@Roasbeef
Roasbeef changed the base branch from codex/sql-port-stage1-migrations to master July 11, 2026 00:30
@Roasbeef Roasbeef closed this Jul 11, 2026
@Roasbeef Roasbeef reopened this Jul 11, 2026
@Roasbeef

Copy link
Copy Markdown
Member Author

Replaced by #1289 after renaming the head branch to remove the codex prefix. The head SHA and commit structure are unchanged.

@Roasbeef Roasbeef closed this Jul 11, 2026
@Roasbeef
Roasbeef deleted the codex/sql-port-stage1-wallet-schema branch July 11, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants