Skip to content

wallet/sql: preserve transaction store semantics#1290

Open
Roasbeef wants to merge 1 commit into
sql-port-stage1-wallet-schemafrom
sql-port-stage1-transactions
Open

wallet/sql: preserve transaction store semantics#1290
Roasbeef wants to merge 1 commit into
sql-port-stage1-wallet-schemafrom
sql-port-stage1-transactions

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

In this PR, we add the port-first transaction, input, credit, and output lease schema for SQLite and PostgreSQL.

This PR is stacked on #1289, which preserves the legacy wallet, scope, account, and address schema.

The long-running branch had moved to a replacement-history state machine that current wtxmgr does not expose. This PR keeps the current model instead: active mined and unmined incidences, physical conflict removal, duplicate mined incidences across blocks, and multiple unmined spenders for one outpoint. The rewrite-only replacement table is deferred.

Credits retain the observable change bit and actual transaction output script. A canonical credit-incidence relation keeps duplicate mined incidences from duplicating one UTXO, while an exact mined debit relation preserves incidence-specific spent state. Labels remain keyed by transaction hash and survive incidence deletion. Leases remain keyed by outpoint, use Unix-second expiry, and can exist independently of a credit row. Atomic lease acquisition preserves same-ID renewal, expired takeover, and rejection of a different live lock ID.

This completes the Stage 1 schema foundation. It does not add a store adapter or change wallet control flow.

Verification:

  • SQLite and PostgreSQL empty-to-head-to-empty-to-head migration tests
  • duplicate incidence, multiple spender, label, credit, output script, and lease parity tests
  • sqlc vet -f sqlc.yaml
  • make fmt-check tidy-module-check rpc-check sqlc-check
  • unmodified lnd tests for ./lnwallet/btcwallet, ./keychain, and ./lnrpc/walletrpc
  • no changes to the existing wallet, waddrmgr, or wtxmgr public surfaces

@Roasbeef
Roasbeef force-pushed the sql-port-stage1-wallet-schema branch from a5a60ca to 97c962d Compare July 11, 2026 00:47
@Roasbeef
Roasbeef force-pushed the sql-port-stage1-transactions branch from 335fb7f to 0c4c46d Compare July 11, 2026 00:48
@Roasbeef
Roasbeef force-pushed the sql-port-stage1-wallet-schema branch from 97c962d to 6ca4b5f Compare July 11, 2026 01:16
In this commit, we add the transaction, input, credit, and output lease schema shared by the SQLite and PostgreSQL backends.

The schema models active mined and unmined incidences instead of retaining rewrite-only status or replacement history. It preserves duplicate mined incidences, multiple unmined spenders, hash-scoped labels, the credit change bit, actual output scripts, and outpoint-scoped leases from the current wtxmgr contract.

Extracted-from: 2fed11b
Extracted-from: 7e9b31e
Extracted-from: a9d660f
Extracted-from: 91802d2
Extracted-from: 34a3539
Extracted-from: 5495079
Extracted-from: ca2f716
Extracted-from: 7f4149f
Extracted-from: 0087d38
Extracted-from: 50acc9c
Extracted-from: aa826c6
Extracted-from: 66e09f2
Extracted-from: c421300
Extracted-from: ff2577a
Extracted-from: 5b1e64a
Extracted-from: 95a09f5

Co-authored-by: Josh Rickmar <jrick@conformal.com>
Co-authored-by: Wilmer Paulino <wilmer.paulino@gmail.com>
Co-authored-by: Joost Jager <joost.jager@gmail.com>
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.

2 participants