-
Notifications
You must be signed in to change notification settings - Fork 651
wallet+db+waddrmgr: prep for address-manager Store routing #1237
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
yyforyongyu
wants to merge
11
commits into
btcsuite:impl-account-manager-store
Choose a base branch
from
yyforyongyu:prep-address-manager-store
base: impl-account-manager-store
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
Show all changes
11 commits
Select commit
Hold shift + click to select a range
893f132
docs: add ADR 0011 (no addresses.used column)
yyforyongyu 886907b
waddrmgr: export taproot script codec
yyforyongyu 83d3b26
waddrmgr: export `ManagedPubKeyAddressHasPrivateKey`
yyforyongyu 89ba430
db: add HasScript field + IsWatchOnly helper to imported address params
yyforyongyu c49dac1
db: thread PubKey + per-account addrSchema through address derivation
yyforyongyu 3925db5
db: add account-metadata fields + helpers on AddressInfo
yyforyongyu fdbcaae
db: select account metadata columns in address read queries
yyforyongyu 0d06eb6
db: wire pg/sqlite address adapters through ApplyAddressAccountMetadata
yyforyongyu b86cd8f
db: extract derived-address adapter helpers in addresses_common
yyforyongyu e98cf25
db: add IsUsed to AddressInfo + AddressInfoRow
yyforyongyu f077eb0
db: derive IsUsed from utxos via EXISTS on SQL
yyforyongyu 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # ADR 0011: No `used` Column on the Addresses Table | ||
|
|
||
| ## 1. Context | ||
|
|
||
| The wallet needs to answer whether an address has appeared in any transaction | ||
| the wallet has seen. This is a monotonic property used by unused-address scans | ||
| to avoid re-offering a previously published address. | ||
|
|
||
| The SQL transaction schema keeps observed wallet history as the source of | ||
| truth. A transaction that is disconnected from the best chain remains in the | ||
| `transactions` table with updated status and block metadata, and `utxos` rows | ||
| reference their creating transaction with restrictive foreign keys. The wallet | ||
| does not physically remove these rows during normal reorg, replace, or orphan | ||
| handling. | ||
|
|
||
| Because observed credits remain represented in SQL history, address used-ness | ||
| can be derived from transaction state: | ||
|
|
||
| ```sql | ||
| SELECT EXISTS(SELECT 1 FROM utxos WHERE address_id = ?) | ||
| ``` | ||
|
|
||
| Storing a second `addresses.used` flag would duplicate the same fact and create | ||
| drift risk between address metadata and wallet history. | ||
|
|
||
| ### Scope | ||
|
|
||
| The SQL `is_used` projection is monotonic for non-abandoned wallet history. | ||
| Explicit abandon/delete flows intentionally remove the abandoned transaction | ||
| state, matching the rest of the wallet's abandon semantics: balances revert and | ||
| the corresponding change indices may become reusable. | ||
|
|
||
| ## 2. Decision | ||
|
|
||
| The SQL backends (`pg` and `sqlite`) do not persist a `used` column on the | ||
| `addresses` table. | ||
|
|
||
| - SQL address-read queries project `db.AddressInfo.IsUsed` from `EXISTS` over | ||
| `utxos`. | ||
| - The Store interface intentionally has no SQL `MarkAddressUsed` method: | ||
| recording an observed wallet transaction inserts the `utxos` row that future | ||
| address reads consult via the `EXISTS` projection. | ||
| - The kvdb backend continues to populate `IsUsed` from waddrmgr's sticky used | ||
| bit, because legacy rollback handling does not provide the same durable SQL | ||
| history table. | ||
|
|
||
| The `db.AddressInfo.IsUsed` contract remains backend-neutral. Callers see the | ||
| same logical wallet property even though SQL derives it from wallet history and | ||
| kvdb reads it from legacy address metadata. | ||
|
|
||
| ## 3. Consequences | ||
|
|
||
| ### Pros | ||
|
|
||
| - SQL has one source of truth for observed address usage. | ||
| - Address metadata avoids an extra column, migration, trigger, and write path. | ||
| - Wallet code can continue to call the Store contract without knowing how each | ||
| backend materializes `IsUsed`. | ||
|
|
||
| ### Cons | ||
|
|
||
| - SQL address reads pay an `EXISTS` lookup against `utxos`. The | ||
| `idx_utxos_by_address` index bounds that cost for single-address reads and | ||
| address-list scans. | ||
| - The SQL and kvdb adapters implement the same contract differently. Store | ||
| method comments and schema comments should point to this ADR so the asymmetry | ||
| remains intentional and discoverable. | ||
|
|
||
| ### Orthogonal: the unbroadcast-tx gap | ||
|
|
||
| Neither a derived SQL projection nor a stored flag covers a transaction the | ||
| user constructs but never records or broadcasts. If no wallet transaction state | ||
| exists, the wallet has no durable fact proving the address was published. That | ||
| privacy gap is independent of where used-ness is materialized. | ||
|
|
||
| ## 4. Implementation Notes | ||
|
|
||
| - SQL migrations do not add an `addresses.used` column. | ||
| - SQL address-read queries project `is_used` with `EXISTS` over `utxos` instead | ||
| of reading address metadata. | ||
| - The Store interface has no `MarkAddressUsed` method on SQL backends; SQL | ||
| derives used-ness from wallet transaction state recorded in the `utxos` | ||
| table. | ||
| - The kvdb adapter keeps using waddrmgr's used bit. |
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
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.
Uh oh!
There was an error while loading. Please reload this page.