db+waddrmgr: add scan-horizon scaffolding and rollback eviction#1269
db+waddrmgr: add scan-horizon scaffolding and rollback eviction#1269yyforyongyu wants to merge 13 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds the recovery scan-horizon “derivation surface” across the SQL store and waddrmgr, including SQL helpers to advance account next-index counters, shared horizon-extension logic (bounded by MaxAddressIndex and skipping hdkeychain.ErrInvalidChild), and rollback primitives to undo in-memory state when a walletdb batch transaction is rolled back.
Changes:
- Add
AdvanceNext{External,Internal}IndexSQL queries (SQLite/Postgres) and wire them into prepared sqlc query sets. - Introduce shared
dbscan-horizon extension scaffolding (ScanHorizon,ScanBatchParams,ExtendScanHorizon+ tests). - Add
waddrmgrrollback helpers (RestoreSyncedTo,EvictDerivedAddresses) plus cache-eviction tests and interface/mocks updates.
Reviewed changes
Copilot reviewed 11 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| wallet/internal/sql/sqlite/sqlc/querier.go | Expose new prepared query methods for monotonic next-index advancement (SQLite). |
| wallet/internal/sql/sqlite/sqlc/db.go | Prepare/close/carry new statements through Queries and WithTx (SQLite). |
| wallet/internal/sql/sqlite/sqlc/accounts.sql.go | Generated bindings for new next-index advancement updates (SQLite). |
| wallet/internal/sql/sqlite/queries/accounts.sql | Source SQL for monotonic next-index advancement (SQLite). |
| wallet/internal/sql/pg/sqlc/querier.go | Expose new prepared query methods for monotonic next-index advancement (Postgres). |
| wallet/internal/sql/pg/sqlc/db.go | Prepare/close/carry new statements through Queries and WithTx (Postgres). |
| wallet/internal/sql/pg/sqlc/accounts.sql.go | Generated bindings for new next-index advancement updates (Postgres). |
| wallet/internal/sql/pg/queries/accounts.sql | Source SQL for monotonic next-index advancement (Postgres). |
| wallet/internal/db/scan_batch_common.go | New shared horizon-extension logic (ExtendScanHorizon) + backend ops abstraction. |
| wallet/internal/db/scan_batch_common_test.go | Unit tests for horizon extension semantics (no-op, bounds, invalid-child skipping, imported-vs-derived account number). |
| wallet/internal/db/data_types.go | Add recovery scan types (ScanHorizon, ScanBatchParams) and MaxAddressIndex; clarify derivation-path semantics on AddressInfo. |
| waddrmgr/sync.go | Add Manager.RestoreSyncedTo to undo in-memory sync-tip on rollback. |
| waddrmgr/scoped_manager.go | Add ScopedKeyManager.EvictDerivedAddresses to undo in-memory derived-address/cache effects on rollback. |
| waddrmgr/scoped_manager_test.go | Add tests ensuring eviction removes only the intended cached/queued entries and invalidates account cache. |
| waddrmgr/interface.go | Extend exported interfaces to include rollback primitives. |
| bwtest/mock/addr_store.go | Update mocks for AddrStore interface expansion. |
| bwtest/mock/account_store.go | Update mocks for AccountStore interface expansion. |
Files not reviewed (6)
- wallet/internal/sql/pg/sqlc/accounts.sql.go: Generated file
- wallet/internal/sql/pg/sqlc/db.go: Generated file
- wallet/internal/sql/pg/sqlc/querier.go: Generated file
- wallet/internal/sql/sqlite/sqlc/accounts.sql.go: Generated file
- wallet/internal/sql/sqlite/sqlc/db.go: Generated file
- wallet/internal/sql/sqlite/sqlc/querier.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage Report for CI Build 28395390432Warning No base build found for commit Coverage: 55.397%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
7aee35e to
3f7db6e
Compare
c11f2ba to
68bac61
Compare
|
No issues found by |
|
No issues found by |
68bac61 to
e4840d1
Compare
c6def60 to
c0de5c2
Compare
e4840d1 to
0019b73
Compare
c0de5c2 to
ed5d9ae
Compare
fa9bf6c to
da711fd
Compare
ed5d9ae to
06be21c
Compare
da711fd to
b458889
Compare
06be21c to
1424387
Compare
b458889 to
b30f2f9
Compare
1424387 to
2f9eda8
Compare
b30f2f9 to
d1d05aa
Compare
|
No issues found by |
|
No issues found by gpt-5.5 🪁 |
d1d05aa to
1a3cac9
Compare
8e24141 to
ae98442
Compare
|
No issues found by |
|
No issues found by |
f731b01 to
73f7574
Compare
7eaff4e to
3c3e52c
Compare
|
No issues found by gpt-5.5 🧭 |
|
No issues found by |
3c3e52c to
2509351
Compare
73f7574 to
0e793a2
Compare
2509351 to
90f6def
Compare
0e793a2 to
27c7852
Compare
|
No issues found by gpt-5.5 🧪 |
|
No issues found by |
27c7852 to
3804fef
Compare
90f6def to
735dd98
Compare
3804fef to
fd82802
Compare
Add EvictDerivedAddresses to the AccountStore interface and ScopedKeyManager. It drops recent-address cache entries and pending unlock derivations for a derived account branch range after a horizon rollback.
Add unit tests covering EvictDerivedAddresses on an unlocked manager, dropping pending unlock-derivation entries when locked, and keeping other accounts' pending entries intact.
Add the recovery scan-batch request shapes before the backend implementations: ScanHorizon and ScanBatchParams, the MaxAddressIndex horizon bound matching waddrmgr.MaxAddressesPerAccount, and the AddressInfo.HasDerivationPath flag distinguishing HD-derived addresses (normal and imported-xpub) from raw single imports.
Add the pg and sqlite SQL and generated sqlc for advancing derived account branch indexes during recovery horizon extension. The scan-batch implementation that calls these queries lands in a following commit.
Add the backend-independent scan-batch horizon types: the HorizonAccount account-state snapshot with its branch-state accessor, the branch number constants, and the ScanHorizonOps interface abstracting the per-backend SQL the horizon extension drives.
Adds the scan-horizon derivation surface: scan-batch request types, SQL
scan-batch account queries, scan-horizon account types, and the horizon
extension helpers (bounded by
MaxAddressIndex, skippingErrInvalidChild).Also adds the
waddrmgrrollback primitivesRestoreSyncedTo(restore arolled-back sync tip) and
EvictDerivedAddresses(evict rolled-back derivedhorizons), with cache-eviction tests.
Split out of the runtime Store PR for reviewability; content-preserving, no
commit changes. Stacked on the scan-batch scaffolding PR (
prep-runtime-2,#1263).