DualStore: upload VSS writes in order, monitors before the manager - #11
Merged
Merged
Conversation
Author
|
VSS integration tests, run locally because CI's
Other red checks:
|
kaloudis
force-pushed
the
rl-0.2.7-security-bump
branch
from
October 3, 2026 00:20
5f4194f to
6e0f337
Compare
DualStore spawned one thread per VSS write and remove. VssStore's per-key version check orders same-key writes, but the version is assigned on the spawned thread, so two writes of one key could still swap; the bulk sync read SQLite before taking its version, so it could overwrite a newer live write; and nothing kept the manager behind its monitors. A VSS copy holding a manager ahead of a monitor it treats as persisted cannot be restored: LDK returns DecodeError::DangerousValue. One worker thread now drains a set of dirty keys, reading the current SQLite value at upload time. It reads the manager before taking each batch, uploads monitor keys (full monitors, MonitorUpdatingPersister updates, archived monitors) first, then removes keys deleted locally, and uploads that manager last, only if every monitor key in the batch went through. Monitor-key removes wait for the batch's monitor writes, so an update key is deleted from VSS only once the full monitor that supersedes it is there. Failed keys stay dirty and retry with backoff (1 s to 60 s). The push safety gate moves into the worker: Disabled drops the batch, Undetermined keeps the keys dirty. The startup bulk sync marks every local key dirty on the same worker (still skipped in restore mode). Dropping the store waits up to 5 s for pending uploads. Fixes #10.
kaloudis
force-pushed
the
dual-store-ordered-writes
branch
from
October 3, 2026 00:24
df016e1 to
0787125
Compare
…t read The worker read the manager, then took the dirty set and dropped the manager's mark with it, so a manager write between the two was never uploaded (found in review of ZeusLN/zeus-vls#273, which this ports). The worker now clears the manager's mark before reading it and leaves any later mark in place. If the push verdict is undetermined, the consumed mark is put back. Two regression tests: a manager write paused between the snapshot read and the batch reaches VSS by shutdown (fails before this change with v1 on VSS), and the manager mark survives an undetermined verdict.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #10. This is the mobile counterpart of ZeusLN/zeus-vls#273 (lnrod).
The base is
rl-0.2.7-security-bump(#8), the next branch ZEUS mobile will ship. That branch only changesCargo.toml,Cargo.lockandPackage.swift, so this PR does not conflict with it.zeushas the sameDualStorewith small differences; I can open a separate PR for it.Problem
DualStorespawned one thread per VSS write and remove.VssStore's per-key version check orders writes to the same key, but three gaps remained:VssStoreassigns its version, so a live write landing in between loses to the older blob.LDK refuses to restore that last state (
DecodeError::DangerousValue). This affects every ZEUS mobile user with VSS backup.Change (
src/io/dual_store.rs)One worker thread drains a set of dirty keys. It reads the current SQLite value when it uploads, so the newest value wins and superseded writes are never sent.
Order within each round:
MonitorUpdatingPersisterupdates and archived monitors.Removes of monitor keys wait until the round's monitor writes have succeeded. This matters because
MonitorUpdatingPersisterconsolidation writes a full monitor and then deletes the update keys it replaces, so VSS must never lose an update key before it holds the new full monitor.Retries: failed keys stay dirty and are retried with backoff from 1 s to 60 s.
Push safety gate: it now runs in the worker before each round.
Disableddrops the batch;Undeterminedkeeps the keys dirty and retries.Startup bulk sync: it marks every local key dirty on the same worker. It is still skipped in restore mode, and the
Background bulk sync complete — n/n keyslog line is kept.Shutdown: dropping the store waits up to 5 s for pending uploads. This is shorter than lnrod's 10 s because the drop can happen on an app thread. Anything left over goes out with the next startup sync.
The read, list and restore paths are unchanged.
Tests
11 new unit tests drive the worker over in-memory stores, wired the same way
DualStorewires it:newer_write_wins_when_an_older_upload_is_slowwrites_queued_behind_an_upload_collapse_to_the_newestmanager_waits_for_failed_monitor_uploadmanager_is_uploaded_after_monitor_keys_in_a_roundupdate_keys_are_removed_only_after_the_full_monitor_is_on_vssremove_reaches_vssstartup_sync_uploads_existing_keys_in_orderpoisoned_local_store_uploads_nothingDisabledstill blocks every upload.undetermined_gate_keeps_keys_until_vss_answersshutdown_flushes_dirty_keysshutdown_does_not_wait_forever_on_a_failing_vssdual_store.rs.DualStore(ZeusLN/zeus-vls#273).vss-integration.ymlrunsintegration_tests_vss.rsagainst a real VSS server on this PR. Those tests build nodes throughDualStore.