Skip to content

db+waddrmgr: add scan-horizon scaffolding and rollback eviction#1269

Open
yyforyongyu wants to merge 13 commits into
prep-runtime-2from
prep-runtime-3
Open

db+waddrmgr: add scan-horizon scaffolding and rollback eviction#1269
yyforyongyu wants to merge 13 commits into
prep-runtime-2from
prep-runtime-3

Conversation

@yyforyongyu

Copy link
Copy Markdown
Collaborator

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, skipping ErrInvalidChild).
Also adds the waddrmgr rollback primitives RestoreSyncedTo (restore a
rolled-back sync tip) and EvictDerivedAddresses (evict rolled-back derived
horizons), 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).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}Index SQL queries (SQLite/Postgres) and wire them into prepared sqlc query sets.
  • Introduce shared db scan-horizon extension scaffolding (ScanHorizon, ScanBatchParams, ExtendScanHorizon + tests).
  • Add waddrmgr rollback 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.

Comment thread wallet/internal/sql/sqlite/queries/accounts.sql
Comment thread wallet/internal/sql/sqlite/queries/accounts.sql
Comment thread waddrmgr/interface.go
Comment thread waddrmgr/interface.go
Comment thread waddrmgr/sync.go Outdated
@coveralls

coveralls commented Jun 17, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28395390432

Warning

No base build found for commit 23b1d1e on prep-runtime-2.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 55.397%

Details

  • Patch coverage: 357 uncovered changes across 9 files (221 of 578 lines covered, 38.24%).

Uncovered Changes

File Changed Covered %
wallet/internal/db/pg/txstore_applyscanbatch.go 113 0 0.0%
wallet/internal/db/sqlite/txstore_applyscanbatch.go 110 0 0.0%
wallet/internal/sql/pg/sqlc/accounts.sql.go 28 0 0.0%
wallet/internal/sql/sqlite/sqlc/accounts.sql.go 28 0 0.0%
wallet/internal/sql/pg/sqlc/db.go 24 0 0.0%
wallet/internal/sql/sqlite/sqlc/db.go 24 3 12.5%
wallet/internal/db/scan_batch_common.go 102 84 82.35%
waddrmgr/scoped_manager.go 68 60 88.24%
wallet/db_ops.go 77 70 90.91%
Total (10 files) 578 221 38.24%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 57613
Covered Lines: 31916
Line Coverage: 55.4%
Coverage Strength: 12967.62 hits per line

💛 - Coveralls

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 xhigh 🦦

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by claude-opus-4-8[1m] 🧭

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by claude-opus-4-8[1m] 🛰️

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 🪁

Comment thread wallet/internal/db/data_types.go Outdated
@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by claude-opus-4-8[1m] 🧩

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 xhigh

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 🧭

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by claude-opus-4-8[1m] 🪶

Comment thread wallet/internal/db/data_types.go
@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 🧪

@yyforyongyu

Copy link
Copy Markdown
Collaborator Author

No issues found by gpt-5.5 xhigh

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.
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.

4 participants