Skip to content

fix: fence a replaced vss store's writes - #140

Merged
ovitrif merged 9 commits into
mainfrom
fix/vss-write-fence
Nov 23, 2026
Merged

ovitrif merged 9 commits into
mainfrom
fix/vss-write-fence

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs:

Description

  • Fences the writes of a VssStore once another one is built for the same VSS store in the process: the same URL (as parsed, so default ports and host case match), store id and wallet (a hash of the store's obfuscation key), as the server separates stores by authenticated user too.
    • VSS writes are unconditional puts (version: -1). A stopped node's write that is still retrying (up to 100 attempts within 180 s of backoff), or one its detached work starts later, could land after a node rebuilt on the same store wrote the same key, e.g. an older channel monitor over a newer one. The next start then fails with the monitor behind the ChannelManager, and the newer revocation data is gone.
    • fix: shut down the leaked runtime once stuck work ends #138 keeps such work alive until it ends, and Bitkit rebuilds the node after a stop while it may still run (Android in the foreground, iOS always), so this overlap is reachable.
  • A node marks its store live from start() until the end of stop(). Each write or removal counts as in flight from its call until it returns, also while it waits behind an earlier write of the same key, retries and their backoff included. Building a VssStore waits until the store is not live and none of its calls is in flight, then starts a new generation. If that takes over 60 s, the build fails with KVStoreSetupFailed and replaces nothing.
  • A node whose store has been replaced, e.g. by a rebuild that failed later, refuses to start with PersistenceFailed, checked before it waits on detached work. A start that fails or panics clears the live mark again, unless its failed background processor still needs stop().
  • Writes and removes now retry in fenced_retry, through clients that do not retry themselves. A call on a replaced store is dropped before its first attempt; each attempt ends after 30 s (the LNURL-auth JWT fetch has no timeout of its own).
  • A replaced store's dropped write or removal returns an error, so e.g. a retained handle of the old node does not hand out a receive address it could not save. Channel monitor and monitor update writes are the exception: they are logged as a warning and return Ok, since a failed monitor write makes LDK panic and abort the process.
  • The VSS build methods and Node::start document the wait and the PersistenceFailed refusal.

Out of Scope

  • A call that ends on the client, by its last request's timeout or its task being cancelled (e.g. by the store's runtime shutting down), stops counting at once, though the server may still apply that request shortly after. Ruling that out needs conditional writes on the server.
  • A failed start() leaves the tasks it spawned running (also on main): bug: a failed start leaves its background tasks running #141.
  • Stores in other processes, e.g. an iOS notification extension building its own node, are not fenced.
  • Reads are not fenced.

Testing

  • store_fences_tests in vss_store.rs:
    • Generations, refusing a replaced store's writes, waiting for a write in flight, a write queued behind another of its key keeping the store current, a build that times out on a write or on a stopped node's write replacing nothing, a dropped write future ending its write, stores fencing only their own writes, spellings of one URL sharing a fence, and which dropped writes fail.
    • Stores of another wallet on the same URL and store id are not fenced; a running node's store is not replaced and the build times out; a build waits for the running node to stop; a replaced store cannot be marked live, and a stale clear leaves the current one live.
    • start_marked_live: a started node keeps its store live, a failed or panicking start clears the mark, a failed start that still needs a stop keeps it, and a node on a replaced store does not start.
    • fenced_retry: retrying until a write succeeds, returning permanent errors without retrying, dropping a replaced store's write before its first attempt, keeping the store current while a write waits to retry, and ending an attempt that does not finish.
  • vss_test:
    • vss_writes_of_a_replaced_store_are_dropped: two stores on one store id; the replaced one's write and remove fail and leave the current one's value in place, and its monitor write succeeds without being applied.
    • vss_replaced_node_refuses_to_start (integration_tests_vss.rs): of two nodes built on one store, the first fails to start with PersistenceFailed and the second starts.
  • vss_test on 3c715fc against a VSS server built without auth, on GitHub's Linux runner: io::vss_store and all four integration_tests_vss passed (run). The repository's VSS integration workflow fails as is: it builds the server from vss-server/rust, which no longer exists upstream; the run used it with that step fixed.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium), Claude Sonnet 5.5 (reasoning: low)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: gemini-4-neon-high (reasoning: Not exposed)
  • Review rounds: 3

The pre-PR review runs record only their model id.

VSS puts are unconditional, so a write of a stopped node that is still retrying, or one its detached work starts later, could overwrite what a node rebuilt on the same store wrote since, including a channel monitor. Building a VssStore now starts a new generation for its VSS store and waits for the write requests of earlier generations still on the wire, failing after 60 s. Writes retry in fenced_retry, which checks the generation before each attempt and drops the write once the store has been replaced.

Verified: cargo test --lib (139 passed), cargo clippy --all-targets (no new findings), vss_test cfg compiles (not run: no auth-free VSS server here)
@ovitrif ovitrif self-assigned this Nov 23, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T13:03:08.999116Z 9ab24d5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ab24d55f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/io/vss_store.rs Resolved

@piotr-iohk piotr-iohk 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.

QA review

Scope: full PR diff against its merge base, at 9ab24d5.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

The fencing design matches the stated goal: a stopped node rebuilt on the same store can no longer have older writes land on top of newer ones. Each attempt checks its generation before sending, the in-flight count is released when a future is dropped, a new store does not wait through a backoff sleep, and the schema-version write stays unfenced on purpose. One new finding: the fence key (trimmed URL, store_id) is broader than a VSS store, because the server also separates stores by the authenticated user. So a node built in the same process for a different wallet that uses the same store id silently fences a running node (F1).

Existing review concern, checked against this head: the Codex thread on fenced nodes continuing to run is still open, and its mechanism holds at this head. StoreFences::start_generation increments the generation before it waits, so a rebuild that times out (KVStoreSetupFailed after 60 s) or fails later in build_with_store_internal leaves the original store fenced permanently. Node::start (src/lib.rs:321-343) checks only the running state, background-task state and spawn state, so a stopped node can be started again. After that, fenced_retry (src/io/vss_store.rs:221-223) returns Ok for every write without saving it. This is a source-analysis result; I have not run it. A possible fix: expose the fence state so a fenced store refuses Node::start, or fail loudly before LDK hands out monitor updates.

Validation: Not run by this reviewer: vss-client-ng 0.4.1 could not be fetched (crates.io blocked, no local cargo cache), so I neither compiled nor ran the tests. I worked out the retry semantics of vss_client::util::retry from how they are called and from the PR's unit tests, without reading the crate source. GitHub showed no check runs or statuses for this head. The author says cargo test --lib passed (139 tests) and that the vss_test case compiles but was not run. I read the new store_fences_tests unit tests and the vss_writes_of_a_replaced_store_are_dropped integration test. They cover generations, waiting, the timeout, cancellation and same-store replacement. No test covers two different wallets that share a URL and store id. Out of scope as the PR states: fencing across processes (for example an iOS notification extension) and requests cancelled mid-flight.

Suggested additional test cases

  • Rust unit test (store_fences_tests): build two StoreFences with the same URL and store id but different VSS seeds (or a seed-derived fence key). Expected: the second does not make the first stop being current, and begin_write on the first still returns Some.
  • vss_test integration: build node A, stop it, then make a rebuild on the same store fail after VssStore::new (for example an invalid chain-source config), then call start() on node A again. Expected: start() refuses, or writes fail visibly. They should not return Ok while the value read back from VSS stays unchanged.

Findings

  • [HIGH] Key the write fence by wallet identity, not just URL and store id — inline at src/io/vss_store.rs:257.

Reviewer model: claude-opus-5-5
Reasoning effort: high

Comment thread src/io/vss_store.rs Resolved

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

No findings. Fences a replaced VssStore's writes per (URL, store id): building a store bumps a process-wide generation, waits up to 60 s for earlier generations' requests still on the wire, and drops a replaced store's writes before their next attempt. Reviewed 9ab24d5, full tier, static only: talos-pr-run refused the build (it could not read the author's permission through this token), and no CI ran on this head (every workflow here is workflow_dispatch).

What I checked, and 6 candidates I ruled out

Read in full: src/io/vss_store.rs; VssStore::new's only caller Builder::build_with_vss_store_and_header_provider (src/builder.rs); vss-client-ng 0.4.1 client.rs, util/retry.rs, headers/lnurl_auth_jwt.rs.
Traced: every write and remove path (sync, async, lazy remove) now goes through fenced_retry on a no-retry client; reads stay on the retrying clients.

Ruled out

  • Fence never releases: an attempt holds its WriteGuard only while its request is out, and the VSS client sets a 10 s request timeout, so the 60 s wait outlasts several attempts. The one call inside an attempt with no timeout is the LNURL-auth JWT fetch in get_headers (its reqwest client sets none), which holds the fence only against a server that accepts the connection and never answers. That needs an unlikely precondition, so I did not file it.
  • Queued or backing-off writes slip through: a write waiting on the per-key lock or in a backoff sleep holds no guard, and its next begin_write returns None once replaced, so it is dropped before any request goes out.
  • Generation bumped by a build that then fails: the store it replaces belongs to a node that was already stopped, which is the premise of the change. A retried build bumps again and waits on the same in-flight count.
  • Tests racing on the global STORE_FENCES: each test that touches the static uses its own store id; the rest build a local StoreFences.
  • block_in_place from a current-thread runtime: new already called it for the schema read before this diff.
  • MSRV: LazyLock (1.80) and Option::is_none_or (1.82) are within rust-version = 1.85.

Merge confidence: 4/5, no findings, but neither CI nor this review ran the tests on this head, and vss_writes_of_a_replaced_store_are_dropped has not run against a VSS server anywhere.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two independent reviews.

needs changing before merge

  • Independent VSS users can disable each other's persistence (src/io/vss_store.rs:257-259)

worth doing, does not block

  • A stuck LNURL JWT fetch keeps the old store in flight with no time limit (src/io/vss_store.rs:201-217)
  • A PUT that times out on the client stops counting but can still land (src/io/vss_store.rs:87-93)

nits

  • REPLACED_WRITES_TIMEOUT comment gives a reason that no longer holds (src/io/vss_store.rs:77-80)

the reviewers disagree, your call

  • A new build silently turns a live store's writes into Ok no-ops, with no log (src/io/vss_store.rs:257-260)
  • Fence key omits the VSS identity, so unrelated wallets fence each other (src/io/vss_store.rs:257)

Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Scope the write fence to one wallet and to stopped nodes:
- The fence key adds a hash of the store's obfuscation key, so stores
  of other wallets on the same URL and store id stay unaffected.
- A node marks its store live from start() until the end of stop().
  Building a store waits up to 60 s for a live store's node to stop
  and fails without replacing it, so a running node's writes are
  never dropped.
- start() refuses a store that has been replaced, e.g. after a failed
  rebuild, with PersistenceFailed.
- A dropped write is logged, each write attempt ends after 30 s (the
  LNURL-auth JWT fetch has no timeout), and the docs state that a
  request ended on the client may still land.

Verified: cargo test --lib (144 passed), cargo clippy --lib (no new
findings), vss_test targets compile; VSS integration tests not run
locally.
Node::start marks its VSS store live through start_marked_live, whose drop guard clears the mark on a failed or panicking start unless the node still needs stop(). The helper is unit tested without a VSS server.

Verified: cargo test --lib (149 passed), cargo clippy --lib (no new findings), nightly rustfmt on vss_store.rs.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked after 2 new commits (3e494b3, a3aa2c4). Nothing blocking remains.

addressed

  • A new build silently turns a live store's writes into Ok no-ops, with no log (src/io/vss_store.rs:257-260). Fixed: A build now waits on the live flag and returns TimedOut before it bumps the generation (src/io/vss_store.rs:124-133). Node::start sets the flag through start_marked_live (src/lib.rs:349-354, vss_store.rs:242-262) and Node::stop clears it (lib.rs:900-903). A node on a replaced store gets PersistenceFailed (vss_store.rs:249-255), and dropped writes and removes are logged at warn (vss_store.rs:899-907, 950-958). A failed build still leaves the generation bumped, but the store it replaces cannot belong to a running node and that node cannot start again, so no running node's writes are acknowledged without being sent. I ran store_fences_tests (21 passed), including a_store_is_not_replaced_while_its_node_runs, a_new_store_waits_for_the_running_node_to_stop and a_node_on_a_replaced_store_does_not_start.
  • Fence key omits the VSS identity, so unrelated wallets fence each other (src/io/vss_store.rs:257). Fixed: StoreKey is now (URL, store id, sha256 of the obfuscation key) (src/io/vss_store.rs:92, 364-367), so wallets with different seeds get separate fences. stores_of_other_wallets_are_not_fenced covers this and passes locally.
  • A stuck LNURL JWT fetch keeps the old store in flight with no time limit (src/io/vss_store.rs:201-217). Fixed: Each attempt is now wrapped in tokio::time::timeout(WRITE_ATTEMPT_TIMEOUT) (30 s, src/io/vss_store.rs:85, 314, 319-321). vss-client-ng 0.4.1 calls get_headers inside post_request (client.rs:189-195), so the bound covers the LNURL JWT fetch, and the guard is dropped when the timeout fires. fenced_retry_ends_an_attempt_that_does_not_finish passes locally.
  • A PUT that times out on the client stops counting but can still land (src/io/vss_store.rs:87-93). Fixed: The StoreFences doc (src/io/vss_store.rs:103-105) and the PR's Out of Scope now say that a request timed out on the client, or cancelled, stops counting but may still be applied, and that only conditional writes rule this out. The CHANGELOG no longer says "still on the wire".
  • REPLACED_WRITES_TIMEOUT comment gives a reason that no longer holds (src/io/vss_store.rs:77-80). Fixed: The comment at src/io/vss_store.rs:78-80 now says the second wait covers at most one attempt, bounded by WRITE_ATTEMPT_TIMEOUT, which matches the code.
  • Independent VSS users can disable each other's persistence (src/io/vss_store.rs:257-259). Fixed: Same change as point 2: the fence key includes a per-wallet hash (src/io/vss_store.rs:364-367). A second wallet on the same URL and store id no longer bumps the first wallet's generation, and the first wallet's begin_write still returns Some (stores_of_other_wallets_are_not_fenced).

new since the last review

worth doing, does not block

  • Public docs of VSS build methods and Node::start omit the new fencing contract (src/lib.rs:316-323). The build_with_vss_store* docs (src/builder.rs:712-800, 1195-1230) and the Node::start doc (src/lib.rs:316-323) do not mention three new behaviours. A build can now block for up to 60 s and fail with KVStoreSetupFailed while another node on the same store and wallet is running. Building also makes any earlier Node on that store unable to start, and drops that node's later writes. Finally, start returns PersistenceFailed in that case. Today this is only in the CHANGELOG and private comments. A binding consumer who sees PersistenceFailed from start() will read it as a storage failure rather than "rebuild this node".

@piotr-iohk piotr-iohk 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.

QA review

Scope: changes since 9ab24d5, including the affected fence, startup, and shutdown paths, at a3aa2c4. Baseline: previous review.

3 actionable findings — resolve or provide an evidence-backed rebuttal.

Those two commits change every surface covered by that baseline (live mark, per-wallet fence key, attempt timeout, and start/stop), so this pass re-read them.

stop clears the live mark while a VSS persist can still be inside fenced_retry. The processor wait aborts that task after 30s and drops the join handle, which leaves the store-runtime retry running. A rebuild then fences the store during backoff, when the attempt is not counted in flight, and the rest of the persist is dropped. stop can still return success.

The 60s build budget is shared with the wait for a live node, so the follow-up wait for an in-flight attempt can be shorter than the 30s attempt limit. That timeout already publishes the new generation, which fences the previous store and fails the build.

A start that fails while resolving or binding listening addresses clears the live mark after chain sync and other tasks are already spawned. stop then returns NotRunning and does not shut those tasks down.

Validation: source inspection at a3aa2c4, including vss-client-ng 0.4.1 retry (Cargo.lock checksum c05f61751537ec3e7cf744e6ed8a56830b8d048f9862871cb4b9c239e3d23b45). The new store_fences_tests and vss_replaced_node_refuses_to_start were read and not executed. They do not cover a persist still retrying at clear_live, a live wait that uses most of the 60s, or a failed start after tasks are spawned. No device run.

Suggested additional test cases:

  • Unit: hold a fenced_retry in backoff with writes_in_flight == 0, call clear_live, then start_generation. The retry must still be allowed to finish, or the new generation must keep waiting until that call returns. The persist must not come back as Ok unless the value was written.
  • Unit: mark a store live, wait 45s, start an attempt that sleeps 20s, then clear_live. start_generation with a 60s budget must wait out that attempt. It must not return TimedOut with the new generation already published.
  • Unit: start_services returns a bind error after spawning a task that writes the store. The live mark stays set until that task is stopped, and Node::stop on that failure actually stops it.

Earlier findings reconciled at this revision: 1 still present, 4 verified fixed, 1 not substantiated.

Findings

  • [HIGH] Finish a shutdown VSS persist before clearing the live mark — inline at src/lib.rs:902.
  • [MEDIUM] Wait out one in-flight VSS attempt after the live node stops — inline at src/io/vss_store.rs:139.
  • [MEDIUM] Keep the store live when start fails after spawning writers — inline at src/io/vss_store.rs:258.

Existing concerns

  • [LOW] Document the VSS fence on the public build and start methods — Raised in the approval body at this head; there is no review thread. Node::start calls start_marked_live, which returns PersistenceFailed when the store generation has been replaced. VssStore::new can time out while a node on that wallet's store is still live, and the builder maps that to KVStoreSetupFailed. The rustdoc on Node::start and on build_with_vss_store, build_with_vss_store_and_fixed_headers, and build_with_vss_store_and_header_provider, including the outer wrappers, still describes startup and the alpha persistence-panic caution. CHANGELOG.md states the new contract. PersistenceFailed still displays as "Failed to persist data.", so a binding caller has no API doc that this result means the store was replaced and the node has to be rebuilt. Issue search repo:synonymdev/ldk-node VssStore OR STORE_FENCES OR "write fence" returned no issues. Source analysis only; not executed.

Reviewer model: grok-4.7
Reasoning effort: xhigh

Comment thread src/lib.rs Resolved
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
A write's retry backoff did not count as in flight, so a store built
while a stopped node's write waited to retry replaced it at once and
dropped the rest of that write. Each write call now counts until it
returns, and building a store waits for the node to stop and its calls
to return before it starts a new generation, so a build that times out
replaces nothing.

Documents on the VSS build methods and Node::start that building waits
for a node on the same store, and that the earlier node then refuses to
start with PersistenceFailed.

Verified: cargo test --lib io::vss_store (store_fences_tests), cargo check with --cfg vss_test, cargo doc, cargo clippy
Comment thread src/io/vss_store.rs Resolved
Comment thread src/io/vss_store.rs Resolved
@ovitrif

ovitrif commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Public docs of VSS build methods and Node::start omit the new fencing contract

@coreyphillips Addressed in 61491b6 and 55735be: the six VSS build methods now say that building waits for a node on the same store and wallet, fails with KVStoreSetupFailed after 60 s, and that past that wait the earlier node's start fails with PersistenceFailed, so it needs a rebuild. Node::start says the same.

A replaced store's dropped write returned Ok, so a retained handle of
the old node, e.g. one handing out a receive address, went on as if
its state were saved. Only channel monitor writes, which LDK treats as
unrecoverable on error, still succeed with a warning; other dropped
writes and removals return an error.

The fence key now uses the parsed VSS URL, so spellings of one URL,
such as with the default port, share a fence.

Verified: cargo test --lib io::vss_store, cargo check with --cfg vss_test, cargo doc
@ovitrif
ovitrif requested a review from ben-kaufman November 23, 2026 15:41
Comment thread src/io/vss_store.rs Resolved
Comment thread src/lib.rs Resolved

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked after 3 new commits (61491b6, 55735be, 3c715fc). Nothing blocking remains.

addressed

  • Public docs of VSS build methods and Node::start omit the new fencing contract (src/lib.rs:316-323). Fixed: All six VSS build methods now carry the contract (src/builder.rs:727-731, 787-791, 812-816, 1228-1232, 1258-1262, 1285-1289), and Node::start documents the PersistenceFailed refusal at src/lib.rs:325-326. I checked each claim against the code: the 60 s wait in start_generation (vss_store.rs:118-136), its mapping to KVStoreSetupFailed (builder.rs:850-855), the refusal in start_marked_live (vss_store.rs:229-235) and the monitor-only quiet drop (vss_store.rs:1007-1014).

new since the last review

nits

  • REPLACED_WRITES_TIMEOUT comment understates how long a write call stays in flight (src/io/vss_store.rs:71-73)

Comment thread src/io/vss_store.rs Resolved
A write counted as in flight only once it held its key's lock, so a
rebuild could replace the store while an event acknowledgement waited
behind an earlier write of the same key, and the rebuilt node replayed
the event. Each write and removal now counts from its call, where it
takes its version.

Node::start refuses a node whose store was replaced before it waits on
detached work, so it returns PersistenceFailed instead of AlreadyRunning.

Verified: cargo test --lib, cargo check with --cfg vss_test

@piotr-iohk piotr-iohk 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.

QA review

Scope: changes since a3aa2c4, including affected code paths, at 3c715fc. Baseline: previous review.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

A build waits until the current store's write calls return, retries and backoff included, and a 60s timeout leaves that store in place. After a successful replacement, dropped writes and removals fail, while channel monitor and monitor-update writes still return success so a monitor persist does not abort the process. Spellings of one VSS URL that parse to the same endpoint share a fence. Inherited coverage still covers the wallet-scoped store key, the retry predicates, and the live mark around start and stop.

Validation: Source review at 3c715fc, including LDK 0.2.8 monitor persist (monitors and monitor_updates map a failed write to UnrecoverableError; channel-manager, scorer, and sweeper failures do not panic) and fence_url checked with the url 2.5.2 parser. cargo test was not run in this review. VSS integration run 45208879488 succeeded on 09c2c23, which adds only a workflow change on top of this revision.

Earlier findings reconciled at this revision: 3 still present, 3 verified fixed.

Findings

  • [MEDIUM] Keep the store live when start fails after spawning writers — inline at src/io/vss_store.rs:238. Still present from the earlier review.

Existing concerns

  • [MEDIUM] Count a VSS write while it waits on the per-key lock — Thread #140 (comment) is unresolved and has no reply. Stop the node while a second write of the same key is blocked on the per-key mutex. When the first fenced_retry returns, its guard drops and writes_in_flight hits zero while that task still holds the mutex. A rebuild can publish a new generation before the waiter reaches begin_write. The queued call then gets WriteOutcome::Dropped. A non-monitor write returns an io::Error, so the newer value is absent from VSS and a rebuilt node can replay the event whose acknowledgement was that write. A channel-monitor write returns Ok without being stored. The direct error is io::Error, not crate::Error::PersistenceFailed. This is source analysis at 3c715fc. No matching issue was found.
  • [MEDIUM] Check the VSS fence before reporting AlreadyRunning — Thread #140 (comment) is unresolved and has no reply. stop waits 30s for the background processor, aborts it, waits another 30s, and on that second timeout stores the task as detached and returns Ok after clearing the live mark. A rebuild can then replace the store once no write call is in flight. start on the old node calls allow_task_spawns, which drains that detached work for 5s. If the task is still running, start returns AlreadyRunning and never reaches the fence check. The old node cannot start again; the documented signal is PersistenceFailed, which tells the caller to build a new node. Retrying start repeats the 5s wait. This is source analysis at 3c715fc. No matching issue was found.

Reviewer model: grok-4.7
Reasoning effort: xhigh

Comment thread src/io/vss_store.rs Resolved
A write queued behind an earlier write of the same key keeps the store
current after the first returns. Comments now place the in-flight count
at the call site instead of fenced_retry.

Verified: cargo test --lib (152 passed); RUSTFLAGS="--cfg vss_test" cargo build --tests

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked after 3 new commits (602f5b2, d334b33, 337be92). Nothing blocking remains.

addressed

  • REPLACED_WRITES_TIMEOUT comment understates how long a write call stays in flight (src/io/vss_store.rs:71-73). Fixed: src/io/vss_store.rs:71-74 now says a call's backoff sleeps add up to 180 s, on top of up to 30 s per attempt. I checked this against vss-client-ng 0.4.1 retry.rs:63-81,202, where only the summed sleeps are capped, and against WRITE_ATTEMPT_TIMEOUT at vss_store.rs:79.

new since the last review

worth doing, does not block

  • Queued-write regression test passes without the fix it was added for (src/io/vss_store.rs:1219-1233)

Comment thread src/io/vss_store.rs Resolved

@piotr-iohk piotr-iohk 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.

QA review

Scope: changes since 3c715fc, including affected code paths, at 337be92. Baseline: previous review. The baseline head is an ancestor of the reviewed head and the merge base is unchanged. Only src/io/vss_store.rs and src/lib.rs changed since the baseline. CHANGELOG.md, src/builder.rs and tests/integration_tests_vss.rs are identical to the baseline, so their coverage is inherited.

No new actionable code findings.

  • Write counting: all four write and remove entry points (KVStoreSync and KVStore) now count a call as in flight at the call, before it waits on the per-key lock. A write queued behind another write of the same key therefore keeps the store current. Every exit releases the count: an invalid key, a stale version, completion, a dropped future and a cancelled task. The schema-version write in determine_and_write_schema_version is still intentionally outside the fence.
  • Dropped writes: a call made after its store was replaced still uses dropped(). Channel monitor writes return Ok with a warning; other writes and all removals return an error. The result is the same as before, except that the check now happens at call time instead of at the first attempt.
  • Early refusal in Node::start: a replaced node now fails with PersistenceFailed before draining detached work. start_marked_live is still the check that prevents the race, so the early check only shortens the failure path.
  • Trade-off, not a defect: queued writes of the same key now add to the builder's 60 s wait. Against a failing VSS, a new build is more likely to time out and replace nothing, which matches the documented behaviour.

Validation: source analysis only. cargo test --lib store_fences could not run: the sandbox denies access to the crates.io index and no dependencies are cached. The new and updated store_fences_tests were read, not executed. Coverage gap: a_write_queued_behind_another_keeps_the_store_current exercises StoreFences directly. No test checks that the VssStore write and remove entry points take the count before waiting on the key's lock; that needs a mock or real VSS client.

Suggested additional test cases

  • Rust, VSS integration (vss_test cfg). Setup: a node on VSS. Action: issue two async writes to the same key, with the first blocked (for example a stalled server), then build a second node on the same store and wallet with a short timeout. Expected: the build fails with KVStoreSetupFailed until both writes have returned, and the original store stays current.
  • Rust, VSS integration. Setup: build node A, then node B on the same store, so A's store is replaced. Action: call A.start() while A still has detached work that has not drained. Expected: it returns PersistenceFailed at once, without waiting for the background-task shutdown timeout.

Earlier findings reconciled at this revision: 2 verified fixed, 1 tracked separately outside this PR.

Tracked separately (outside this PR; unresolved): Keep the store live when start fails after spawning writers. Re-verified at head 337be92 against merge base b89c209. The remaining unresolved behaviour is unchanged. On a failed start, Node::start leaves the chain sync, RGS gossip and pathfinding tasks running, and Node::stop returns NotRunning without signalling them. The same is true at the base: chain sync is spawned at base src/lib.rs:360, before the address resolution and bind errors at base src/lib.rs:448-467; is_running is set only at base src/lib.rs:782; stop returns NotRunning at base src/lib.rs:824. That pre-existing defect is #141, which is open. The part this PR adds, start_marked_live clearing the live mark on Err (src/io/vss_store.rs:242-245), no longer has a harmful consequence at this head. (1) Every write and remove call is now counted from the call itself, including while it waits on the key's lock (src/io/vss_store.rs:444, 478, 545, 578). A rebuild waits for any call the leaked tasks have already made (src/io/vss_store.rs:119-135). The only write that can still land afterwards is one whose request timed out on the client, a limit the StoreFences docs state and that applies to every path. (2) The only error exits that clear the mark come before the listener and peer tasks are spawned. The one later exit, a failed background processor at src/lib.rs:806-809, keeps the mark through stop_required. With no peer connection, an Ok for a dropped monitor write cannot release a commitment update. (3) After a replacement the old node can never start again (src/lib.rs:336 and src/io/vss_store.rs:233-239). Non-monitor writes it drops return an error (src/io/vss_store.rs:867-882). At the base, the same leaked tasks would write to VSS without any check, over a rebuilt node's state. The fence therefore reduces the base failure and does not worsen it. The author's reply in #140 (comment) makes the same argument, and the source above confirms it independently. The QA re-report thread #140 (comment) is still unresolved on GitHub. This disposition does not resolve it, and it is neither a fix nor a runtime pass. Not executed: source analysis only. This is not a runtime verification or merge-readiness declaration.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@ovitrif

ovitrif commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved at 337be92, every thread resolved. Corey's call-site and start() tests follow in the rc.82 release PR.

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.

5 participants