Repository navigation
fix: reuse the read connection for vss writes - #147
Conversation
Since 0.7.0-rc.82 writes went through their own VssClients, each with a new reqwest client, so the first write after a node build opened a new connection instead of reusing the one the reads had just opened. On a phone that put a DNS lookup, TCP connect and TLS handshake, and any retries of a failing connect, into the first channel monitor write while the node builds. Each side's read and write clients now share one reqwest client, built with the timeouts VssClient::new_with_headers uses. Write retries stay in fenced_retry. Verified: cargo test --lib vss_store (the new connection test fails on main with 2 connections); staging VSS through a local proxy adding 2 s per new connection: the first sync monitor write takes 0.38 s, against 2.33-2.41 s on rc.84 and 0.21-0.37 s on rc.80
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Each side's VSS read and write clients now share one reqwest client, so the first monitor write reuses the connection the reads opened instead of paying DNS, TCP and TLS again. Reviewed e36d347, full tier, static.
What I checked, and 5 candidates I ruled out
Read in full: the diff, VssStore::new, fenced_retry, the KVStore / KVStoreSync read and write paths in src/io/vss_store.rs, and vss-client-ng 0.4.1 src/client.rs as locked.
Not built or run here: my sandboxed runner refused to build this PR, so this review is from the code. CI ran only mobile-builds-unwind (green). rust.yml and vss-integration.yml are workflow_dispatch only, so connection_tests::first_write_reuses_the_read_connection has not run in CI.
Ruled out
- Timeout drift:
build_http_clientmatchesbuild_client()in vss-client-ng 0.4.1 (10 s total, connect and read). Writes keep the per-attempt bound fromfenced_retry, as before. - Reads queued behind a slow write: reqwest 0.12 here is HTTP/1 only (no
h2in the lockfile's reqwest 0.12.28 entry). The pool hands out only idle connections, so a hung write makes a read open a new connection rather than wait for it. - Fencing: sharing a client changes only the transport.
begin_write, the generation check before each attempt and the no-retry policy on the write clients are untouched. - Cross-runtime pooling: both sides' requests already run on
internal_runtime(block_onon its handle, orruntime.spawn), so a pooled connection is never driven from a runtime that did not open it. - Test determinism: the stub counts each accept before it serves that connection, so a second connection would show up in the count before the write returns. One narrow window remains: hyper-util 0.1.20 can hand the read's connection back to the pool from a spawned idle task (
client.rs:358-362). If the write checks out a connection before that task runs, it opens a second one. Only the async read then write pair in the test has little work between the two, so if this test ever flakes on2 != 3, that is where to look. It does not affect the fix.
Merge confidence: 4/5, no findings, but the test covering the change has not run in CI and I could not run it here.
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at e36d347.
No new actionable code findings.
No new actionable code findings. Sharing one reqwest::Client between blocking_client and blocking_write_client (and a separate shared client between async_client and async_write_client) via VssClient::from_client_and_headers preserves vss-client-ng 0.4.1's 10 s total/connect/read timeouts while returning io::Error instead of panicking on client build failure, and keeps StoreFence, fenced_retry / no_retry_policy, and sync-vs-async pool isolation intact. External reviews on PR #147 (talosmachina, Codex) also reported no open findings.
Validation:
- Executed locally at e36d347 (Rust 1.100.1):
cargo test --lib vss_store --lockedwithRUSTFLAGS="-D warnings"passed (25/25, includingconnection_tests::first_write_reuses_the_read_connection, which also passed 100/100 consecutive runs);cargo test --lib --lockedpassed (164/164);cargo check --features uniffi --locked,cargo doc --no-deps --locked, andrustfmt --edition 2021 --check src/io/vss_store.rspassed;cargo clippy --lib --lockedreported no warnings on changed lines. - CI: mobile-builds-unwind passed; build (ubuntu-latest, stable) failed on pre-existing
cargo fmt --all -- --checkdiffs in untouched files (tests/common/mod.rs,src/builder.rs,src/lib.rs,src/payment/asynchronous/static_invoice_store.rs,src/payment/onchain.rs,tests/integration_tests_rust.rs,tests/multi_address_types_tests.rs), cancelling the remaining jobs in that matrix run before tests ran. - Remaining checks: the
vss_testintegration suite against a live VSS server was not run here (no VSS/Postgres service in this environment), and the mobile-network startup latency check referenced by synonymdev/bitkit-android#2219 remains to be verified on Android/iOS once shipped in a downstream release candidate.
Reviewer model: gemini-4-neon
Reasoning effort: high
coreyphillips
left a comment
There was a problem hiding this comment.
Two independent reviews, nothing blocking a merge.
|
I dispatched the two on-demand workflows on this branch so the new test would run in CI. Neither gets that far, for reasons that are also on
Locally, |
|
Merged: approved by @coreyphillips and @piotr-iohk on e36d347, mobile-builds-unwind green. Next: release 0.7.0-rc.85 for the app bumps. |
Bumps ldk-node to 0.7.0-rc.85: VSS writes reuse the connection the store's reads opened (synonymdev/ldk-node#147), so the first ChannelMonitor write at node start doesn't wait on a new connect and its retries (#2219). Verified: ./gradlew --write-verification-metadata sha256 help resolves ldk-node-android 0.7.0-rc.85 from GitHub Packages and records its checksums
Bumps ldk-node to 0.7.0-rc.85 on master, matching release-3.2.0: VSS writes reuse the connection the store's reads opened (synonymdev/ldk-node#147), so the first ChannelMonitor write at node start doesn't wait on a new connect and its retries (#2219). Verified: none (same pins and checksums as the release-3.2.0 bump, which resolved rc.85 from GitHub Packages and a clean SwiftPM cache)
Refs: synonymdev/bitkit-android#2219
Description
0.7.0-rc.82. Since then VSS writes have had their ownVssClients, each with a new reqwest client, so the first channel monitor write while the node builds opened a new connection instead of reusing the one the reads had just opened. On a phone that adds a DNS lookup, TCP connect and TLS handshake to every start, plus the retries of a connect that fails.blocking_clientwithblocking_write_client,async_clientwithasync_write_client), built with the timeoutsVssClient::new_with_headersuses. Writes still retry throughfenced_retry, and the blocking and async sides keep separate connections.Timings (staging VSS through a local proxy, 150 KB write to
monitors/, 2 rounds each):On a good network with no proxy, rc.84 writes on the first attempt in 0.2–0.45 s on staging,
api.bitkit.toandbitkit.to. A full-node restart on regtest with staging VSS shows the monitor write at 0.12 s. Phone start times on this build haven't been measured yet.Out of Scope
fenced_retry: they stay silent unless the write failsQA Notes
Manual Tests
Got new ChannelMonitor→Persistence … completedback near 0.3–0.4 s, as on 3.1.1 — needs a phone networkAutomated Checks
connection_tests::first_write_reuses_the_read_connectioninvss_store.rs: a local VSS stub counts connections; it fails onmainwith 2 connections where 1 is expectedcargo test --lib vss_storeModels used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)