Skip to content

chore: handle legacy duplicate opaque handles - #24743

Merged
mverzilli merged 8 commits into
merge-train/fairies-v5from
martin/sqlite-opfs-duplicate-detection
Jul 17, 2026
Merged

chore: handle legacy duplicate opaque handles#24743
mverzilli merged 8 commits into
merge-train/fairies-v5from
martin/sqlite-opfs-duplicate-detection

Conversation

@mverzilli

Copy link
Copy Markdown
Contributor

This is a defensive measure in case more than one SQLite page file is found pointing to the same logical name, which could cause undefined behavior. This could happen with old, pre-weblock controlled versions of wallet/pxe (see #24740), so it's unlikely to be found in the wild, but it gives us graceful coverage if that happens.

We detect if a pool contains two valid .opaque files mapped to the same logical SQLite path, then:

  1. Acquire the pool Web Lock.
  2. Copy the entire pool byte-for-byte into: .aztec-sqlite-quarantine//
  3. Verify the copied directory and file contents.
  4. Write a quarantine.json describing the duplicate mappings.
  5. Delete the original active pool.
  6. Open a new, empty database under the original pool name.
  7. Emit a warning log containing the quarantine location.

The caller receives a successfully opened but empty store, so wallet/PXE state would need to be recreated or resynchronized. The quarantined bytes remain available for forensic or manual recovery, although there is currently no public API or UI for that.

If copying or verification fails, opening fails and the original pool is not intentionally removed. If the pool merely comes from an old version but has no duplicate logical mappings, nothing special happens, it opens normally.

@mverzilli
mverzilli requested a review from Thunkar July 16, 2026 07:43
Comment thread yarn-project/kv-store/src/sqlite-opfs/pool_integrity.ts
Base automatically changed from martin/sqlite-web-lock to merge-train/fairies-v5 July 17, 2026 14:48
…te-detection

# Conflicts:
#	yarn-project/kv-store/src/sqlite-opfs/errors.ts
#	yarn-project/kv-store/src/sqlite-opfs/index.ts
#	yarn-project/wallets/src/embedded/store_encryption.ts
…tin/sqlite-opfs-duplicate-detection

# Conflicts:
#	yarn-project/kv-store/src/sqlite-opfs/store.ts
#	yarn-project/kv-store/src/sqlite-opfs/store_management.test.ts
@mverzilli
mverzilli requested a review from Thunkar July 17, 2026 16:22
@mverzilli mverzilli changed the title handle legacy duplicate opaque handles chore: handle legacy duplicate opaque handles Jul 17, 2026
@mverzilli
mverzilli merged commit cfbd62a into merge-train/fairies-v5 Jul 17, 2026
14 of 15 checks passed
@mverzilli
mverzilli deleted the martin/sqlite-opfs-duplicate-detection branch July 17, 2026 16:39
@PhilWindle PhilWindle added port-to-next Forward-port this merged PR into next and removed port-to-next Forward-port this merged PR into next labels Jul 21, 2026
mverzilli added a commit that referenced this pull request Jul 23, 2026
Forward port the following PRs from v5-next to next:

- #24631
- #24647
- #24739
- #24740
 - #24743

---------

Co-authored-by: Gregorio Juliana <gregojquiros@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.

3 participants